-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Friends #184
Friends #184
Changes from all commits
019da2a
7b6d06a
1de322f
5f022f6
041238e
251ac1b
3189a19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
class FriendsController < ApplicationController | ||
include QRcode | ||
|
||
before_action :make_sure_user_logged_in | ||
|
||
def new | ||
@trigger = Trigger.find_by(description: trigger_description) | ||
|
||
if @trigger | ||
@trigger.key = SecureRandom.uuid | ||
@trigger.expires_at = Time.zone.now + 30.seconds | ||
@trigger.amount = 1 | ||
else | ||
@trigger = new_trigger | ||
end | ||
|
||
raise unless @trigger.save | ||
|
||
@qrcode = url_to_svg_qrcode(url: trigger_url(@trigger, key: @trigger.key)) | ||
end | ||
|
||
private | ||
|
||
def trigger_description | ||
"friends:#{@user.profile.uid}" | ||
end | ||
|
||
def new_trigger | ||
Trigger.build( | ||
description: trigger_description, | ||
key: SecureRandom.uuid, | ||
action: [ | ||
{ | ||
model: 'Friend', | ||
target: 'Profile', | ||
props: { | ||
from: @user.profile.id, | ||
to: :target | ||
}, | ||
action: :craete | ||
}, | ||
{ | ||
model: 'Friend', | ||
target: 'Profile', | ||
props: { | ||
from: :target, | ||
to: @user.profile.id | ||
}, | ||
action: :craete | ||
} | ||
], | ||
expires_at: Time.zone.now + 30.seconds, | ||
amount: 1 | ||
) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
module FriendsHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
// Connects to data-controller="friend-code" | ||
export default class extends Controller { | ||
static targets = ['counter'] | ||
static values = { expiresAt: String } | ||
|
||
connect() { | ||
this.calc(); | ||
this.timer = setInterval(() => { | ||
this.calc(); | ||
}, 1000); | ||
} | ||
|
||
disconnect() { | ||
clearInterval(this.timer); | ||
} | ||
|
||
calc () { | ||
const expiresAt = Date.parse(this.expiresAtValue); | ||
const now = Date.now(); | ||
|
||
if (now < expiresAt) { | ||
this.counterTarget.innerHTML = Math.trunc((expiresAt - now) / 1000); | ||
} else { | ||
this.counterTarget.innerHTML = 0; | ||
|
||
fetch('/profile/friends/new', { headers: { Accept: "text/vnd.turbo-stream.html" } }) | ||
.then(r => r.text()) | ||
.then(html => Turbo.renderStreamMessage(html)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class Friend < ApplicationRecord | ||
belongs_to :from_profile, class_name: 'Profile', foreign_key: :from | ||
belongs_to :to_profile, class_name: 'Profile', foreign_key: :to | ||
|
||
validates :from, presence: true | ||
validates :to, presence: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div class="w-full"> | ||
<%= @qrcode.html_safe %> | ||
<div class="flex flex-col w-full mt-4" data-controller="friend-code" data-friend-code-expires-at-value="<%= @trigger.expires_at %>"> | ||
<p>expires in <span data-friend-code-target="counter"></span> seconds</p> | ||
<a href="<%= new_profile_friend_path %>" class="normal-button mr-2"><%= I18n.t('button.reload') %></a> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= turbo_frame_tag 'friend-qr' do %> | ||
<div id="friend-qr-code"> | ||
<%= render 'qrcode' %> | ||
</div> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= turbo_stream.update 'friend-qr-code' do %> | ||
<%= render 'qrcode' %> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,15 @@ | |
<td> | ||
<% if row.tracks[track] %> | ||
<div class="p-2"><%= render("schedules/card", schedule: row.tracks[track], mode: :schedule, inactive: @selected) %></div> | ||
<% if @user&.profile %> | ||
<div class="flex flex-wrap ml-6 mb-4"> | ||
<% @user.profile.friend_profiles.each do |profile| %> | ||
<% if @friends_schedules_map[profile.id].include?(row.tracks[track].id) %> | ||
<img src="<%= profile.avatar_url %>" class="h-8 w-8 rounded-full border-2 border-black mt-[-4px] ml-[-16px] mt-1" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. モバイルだとスケジュールに友達のアイコンが表示されませんでした。これから対応予定でしたらすみません🙏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. モバイルの存在忘れてました There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. モバイル対応はこのPRでやります? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 別PRでやります |
||
<% end %> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
<% else %> | ||
<div class="sm:p-2"></div> | ||
<% end %> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
すみません仕様をよく分かっていないのですが、adminじゃないとQRコードを表示できない仕様でしょうか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
すみません、説明不足でした!!!
これはリリースをRubyKaigiDay0に合わせたいなと思って塞いでいます、Day0の日にこのコミットをRevertして全員に使えるようにしようと思います