Skip to content
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

プラクティス完了ツイート機能の実装 #3385

Merged
merged 30 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e3784c8
プラクティス完了ツイート機能の実装
konaga-k Sep 12, 2021
10c6e4b
ツイートに記載されるプラクティス完了ページのURLを修正
konaga-k Oct 24, 2021
829e992
完了ページのデザインのベース作成
machida Nov 30, 2021
73a4609
重複分のviewの整理
machida Dec 3, 2021
c17c3e1
完了ツイートで表示するページのデザインの大枠を作成
machida Dec 9, 2021
b864793
不要なclassを削除
machida Dec 9, 2021
c5c56cb
デザイン修正
machida Dec 9, 2021
96bfa02
おめでとう用のモーダルのスタイルを用意、モーダルのpartialに渡す引数の名前を変更
machida Dec 16, 2021
0e8ef77
不要な変数の定義を削除
machida Dec 16, 2021
2e3b57b
完了モーダルのデザイン変更
machida Dec 17, 2021
5d8e040
文言変更、デザイン変更に伴うテスト修正
machida Dec 17, 2021
9cfe3e6
文言変更、デザイン変更に伴うテスト修正
machida Dec 17, 2021
84e239a
テストの修正
machida Dec 21, 2021
58e3d6a
テストの修正
machida Dec 21, 2021
293d57e
テストの修正
machida Dec 21, 2021
d84b135
テストの修正
machida Dec 21, 2021
1a35971
プラクティス編集画面の「完了おめでとう画像」に関するテストを修正
R-Tsukada Dec 21, 2021
b6443d5
completionのテストを修正
R-Tsukada Dec 22, 2021
64bd09c
プラクティス終了時に表示されるモーダルを閉じるテストを修正
R-Tsukada Dec 22, 2021
aac43fd
【完了Tweetする】ボタンをクリックする処理を追加
R-Tsukada Dec 25, 2021
226ed7e
クリックの処理を削除
R-Tsukada Dec 27, 2021
a5ce05b
learning-completion-message.jsの読み込みを追加
R-Tsukada Dec 28, 2021
f4fb7a8
プラクティス完了モーダルの「閉じる」をクリックする処理を追加し、2回目以降はモーダルを表示しないことをテストできるようにした。
R-Tsukada Dec 28, 2021
cad0d2a
リファクタリングを実施
R-Tsukada Jan 6, 2022
bfcdf78
findメソッドにセレクターを追加
R-Tsukada Jan 7, 2022
0cda629
メソッド名と引数を変更
R-Tsukada Jan 7, 2022
678e225
tweet_urlメソッドをPractice#tweet_urlで呼べるように修正
R-Tsukada Jan 19, 2022
122c058
テストを修正
R-Tsukada Jan 19, 2022
731e8ac
完了Tweet機能をコメントアウトした
machida Feb 9, 2022
4e34beb
コメントアウトの記法を変更
machida Feb 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,522 changes: 1,522 additions & 0 deletions app/assets/images/completion/completion_background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions app/assets/stylesheets/atoms/_a-completion-message.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.a-completion-message
background-color: $info
+padding(vertical, .75rem)
&:not(:last-child)
margin-bottom: 1.25rem

.a-completion-message__inner
+media-breakpoint-up(md)
display: flex
justify-content: center
align-items: center

.a-completion-message__title
+text-block(1em 1.45, center $reversal-text 600)
+media-breakpoint-up(md)
font-size: 1rem
+media-breakpoint-down(sm)
font-size: .8125rem

.a-completion-message__actions-item
+media-breakpoint-up(md)
width: 10rem
+media-breakpoint-down(sm)

.a-completion-message__inner-end
+media-breakpoint-up(md)
margin-left: 1rem
+media-breakpoint-down(sm)
margin-top: .75rem
22 changes: 22 additions & 0 deletions app/assets/stylesheets/blocks/card/_congrats-card-body.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.congrats-card-body__title
+text-block(1.5rem 1.5, 700)
+media-breakpoint-up(md)
font-size: 1.5rem
+media-breakpoint-down(sm)
font-size: 1rem

.congrats-card-body__image-container
margin-top: 1.25rem

.congrats-card-body__image-container
width: 100%
max-width: 28rem
+margin(horizontal, auto)

.congrats-card-body__image
border-radius: .75rem
border: solid .5rem $background

.congrats-card-body
.card-main-actions
margin-top: 1.25rem
8 changes: 5 additions & 3 deletions app/assets/stylesheets/blocks/page/_page-body.sass
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
+padding(vertical, 1.5rem)
+media-breakpoint-down(sm)
+padding(vertical, 1.125rem)
.page-header + &
border-top: solid 1px $border-shade

.page-body__inner
position: relative

.page-optional-header
+padding(vertical, .875rem)
border-bottom: solid 1px $border-shade
border-bottom: solid 1px $border-more-shade

.page-optional-header__title
+text-block(1em 1.4, center flex)
+text-block(1em 1.4, center 600 flex)
align-items: center
+media-breakpoint-up(md)
font-size: 1.25rem
font-size: 1.125rem
+media-breakpoint-down(sm)
font-size: 1rem

Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/blocks/page/_page-tabs.sass
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
+media-breakpoint-down(sm)
>.container
+padding(horizontal, 0)
.page-header + &
border-top: solid 1px $border-more-shade
.page-tools &:last-child
border-bottom: none


.page-tabs__items
display: flex
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/blocks/page/_page-tools.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.page-tools
.page-header + &
border-top: solid 1px $border-more-shade
& + .page-body
border-top: solid 1px $border-more-shade
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@machida
通知一覧ページの表示が、意図されている内容なのか気になったので、一応コメントさせていただきました😅
意図通り or 他の箇所で修正であれば、スルーしていただければ🙏


ここのborder-topについて、おそらく下図のような部分での区切り線を意図されていると思います。

CleanShot 2021-12-26 at 09 39 10

通知一覧ページも同じような構造なのですが、未読・既読のトグルがあるので、余計な線が入っている or マージンが足りないように見えました。

CleanShot 2021-12-26 at 09 40 50

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おおーすいません、こちら見逃してました🙇‍♂️

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.completion-massage
background-color: $success
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
width: 100%
+position(sticky, left 0, bottom 0, 1)
+padding(vertical, .5rem)
+text-block(1rem 1.4, center $reversal-text)
+text-block(.875rem 1.4, center $reversal-text)
a
+hover-link-reversal
color: $reversal-text
Expand Down
29 changes: 22 additions & 7 deletions app/assets/stylesheets/blocks/shared/_modal.sass
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@
font-size: .875rem

.modal-header
padding: .25rem 1rem
display: flex
align-items: center
justify-content: space-between
border-bottom: solid 1px $background
+media-breakpoint-up(md)
padding: .25rem 1.5rem
+media-breakpoint-down(sm)
padding: .25rem 1rem

.modal-header__close
display: flex
align-items: center
justify-content: center
+size(2.75rem)
cursor: pointer
margin-right: -.75rem
opacity: .7
opacity: .4
transition: all .2s ease-out
position: relative
+media-breakpoint-up(md)
margin-right: -1.5rem
+media-breakpoint-down(sm)
margin-right: -1rem
&::before,
&::after
content: ""
display: block
+size(50% 2px)
+size(40% 2px)
background-color: $default-text
+position(absolute, left 50%, top 50%)
border-radius: 2px
Expand All @@ -60,12 +66,21 @@
.modal-body
max-height: calc(100vh - 11.5rem)
overflow: auto
padding: 1rem
border-bottom: solid 1px $background
+media-breakpoint-up(md)
padding: 1rem 1.5rem
+media-breakpoint-down(sm)
padding: 1rem

.modal-title
font-size: 1.25rem
font-weight: 600
+media-breakpoint-up(md)
font-size: 1.25rem
+media-breakpoint-down(sm)
font-size: 1rem

.modal-footer
padding: .25rem 1rem
+media-breakpoint-up(md)
padding: .25rem 1.5rem
+media-breakpoint-down(sm)
padding: .25rem 1rem
2 changes: 1 addition & 1 deletion app/assets/stylesheets/blocks/shared/_sort-nav.sass
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
flex-direction: column

.sort-nav__label
+text-block(.8125rem 1.45)
+text-block(.75rem 1.4)
margin-right: .5rem
white-space: nowrap
+media-breakpoint-down(sm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.a-user-name,
.a-meta
font-size: .75rem
.thread-list-item-title + &
margin-top: .25em

.thread-list-item-meta__items
+text-block(.75rem 1.4)
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/completion.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import common-imports
@import blocks/shared/flash
@import blocks/shared/modal
@import completion/**/*
80 changes: 80 additions & 0 deletions app/assets/stylesheets/completion/_completion-base.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
$completion: #00a0dd

body.is-completion
background-color: $completion

.completion-wrapper
min-height: 100vh
display: flex
flex-direction: column
&::before
content: ''
background-image: image_url('completion/completion_background.svg')
background-repeat: repeat
+position(fixed, left 0, top 0, right 0, bottom 0, 1)
+size(100%)
opacity: .075
+media-breakpoint-up(md)
background-size: 16rem auto

.completion-wrapper__start
flex: 1
+position(relative, 2)

.completion-wrapper__end
+position(relative, 2)

.complestion
+padding(vertical, 4rem 2rem)

.complestion__title
+text-block(2rem 1.5, 800 center $reversal-text)
font-family: YakuHanJP_Narrow,Hiragino Sans,Hiragino Kaku Gothic ProN,BIZ UDPGothic,Meiryo,sans-serif

.complestion__body
margin-top: 3rem

.complestion__image
border-radius: 1rem
border: solid .75rem shade($completion, 30%)

.welcome-footer
+media-breakpoint-up(md)
+padding(vertical, 3rem)
+media-breakpoint-down(sm)
padding-bottom: 1.5rem
body.welcome & .container
+padding(horizontal, 0)

.welcome-footer__nav
margin-bottom: 1.5rem

.welcome-footer__nav-items
+media-breakpoint-up(md)
display: flex
justify-content: center

.welcome-footer__nav-item
+media-breakpoint-up(md)
+padding(horizontal, .5rem)

.welcome-footer__nav-item-link
+text-block(.875rem 1, $reversal-text)
+media-breakpoint-up(md)
+hover-link
+media-breakpoint-down(sm)
text-decoration: none
display: flex
align-items: center
+padding(horizontal, 1rem)
border-bottom: solid 1px $border
+size(100% 2.75rem)

.welcome-footer-copyright
justify-content: center
align-items: center
+text-block(.875rem 1.45, flex $reversal-text)

.welcome-footer-copyright__author
display: block
+margin(horizontal, .1em .5em)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class API::Practices::Learning::CompletionMessageController < API::BaseController
def update
learning = current_user.learnings.find_by(practice_id: params[:practice_id])
if learning.update(completion_message_displayed: true)
head :ok
else
head :bad_request
end
end
end
9 changes: 9 additions & 0 deletions app/controllers/practices/completion_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class Practices::CompletionController < ApplicationController
layout 'completion'

def show
@practice = Practice.find(params[:practice_id])
end
end
2 changes: 2 additions & 0 deletions app/controllers/practices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class PracticesController < ApplicationController

def show
@categories = @practice.categories
@tweet_url = @practice.tweet_url(practice_completion_url(@practice.id))
end

def new
Expand Down Expand Up @@ -47,6 +48,7 @@ def practice_params
:submission,
:open_product,
:include_progress,
:ogp_image,
:memo,
category_ids: [],
reference_books_attributes: %i[id title price page_url must_read cover description _destroy]
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def show
@product = find_product
@reports = @product.user.reports.limit(10).order(reported_on: :DESC)
@practice = find_practice
@learning = @product.learning # decoratorメソッド用にcontrollerでインスタンス変数化
@footprints = find_footprints
@tweet_url = @practice.tweet_url(practice_completion_url(@practice.id))
footprint!
respond_to do |format|
format.html
Expand Down
7 changes: 7 additions & 0 deletions app/decorators/learning_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module LearningDecorator
def should_display_message_automatically?(current_user:)
user == current_user && complete? && !completion_message_displayed?
end
end
Comment on lines +3 to +7
Copy link
Contributor Author

@konaga-k konaga-k Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

モーダルの初回表示判定はviewでしか使わないのでメソッドはdecoratorにしましたが、
今見ると権限系に近い処理なので、モデルに直接生やした方がよかったのか迷ってます

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

うーん、正直どこにメソッド定義をしたらいいか自分には判断できませんね😥
これはぜひ駒形さんに聞きたいです!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

現在viewでしか使わず、今後も他で使われなさそうであればこれで良いと思います〜

35 changes: 35 additions & 0 deletions app/javascript/learning-completion-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
document.addEventListener('DOMContentLoaded', () => {
const modal = document.querySelector('#modal-learning_completion')
if (!modal) {
return null
}

const datasetNode = document.querySelector('#modal-learning_completion-data')

if (datasetNode.dataset.shouldDisplayMessageAutomatically === 'true') {
modal.checked = true
}

modal.addEventListener('change', () => {
if (!modal.checked) {
const practiceId = datasetNode.dataset.practiceId
fetch(`/api/practices/${practiceId}/learning/completion_message`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-Token': token()
},
credentials: 'same-origin',
redirect: 'manual'
}).catch((error) => {
console.warn('Failed to parsing', error)
})
}
})

function token() {
const meta = document.querySelector('meta[name="csrf-token"]')
return meta ? meta.getAttribute('content') : ''
}
})
5 changes: 3 additions & 2 deletions app/javascript/learning.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
i.fas.fa-check
| 完了しています
li.card-main-actions__item(v-else)
button#js-complete.a-button.is-md.is-warning.is-block(
@click='pushComplete'
label#js-complete.a-button.is-md.is-warning.is-block(
@click='pushComplete',
for='modal-learning_completion'
Comment on lines +13 to +15
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
プラクティス詳細ページの完了ボタンですが、button要素からlabel要素に変更し、for属性を追加しました
理由としては、完了ボタンを押したときにモーダル表示されるようにするためです
label要素がクリックされると for属性の値 modal-learning_completion をidとする要素がcheckedになります
モーダルがcheckedになると、sassの設定により画面上に表示されます

input:checked + &
display: block

)
i.fas.fa-check
| 完了
Expand Down
1 change: 1 addition & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ import '../talks.js'
import '../admin_companies.js'
import '../company-users.js'
import '../generation-users.js'
import '../learning-completion-message.js'
Loading