-
Notifications
You must be signed in to change notification settings - Fork 71
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
checkStampを非Vue化した #8194
Open
mousu-a
wants to merge
8
commits into
main
Choose a base branch
from
chore/check-stamp-non-vue-conversion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
checkStampを非Vue化した #8194
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d94b76c
check-stamp.vueをRailsで実装(非Vue化)した
mousu-a 9a0fd7a
不要なファイル、記述を削除
mousu-a 8cef7c8
不要な記述だったため削除
mousu-a fcbd33f
冗長なコードだったため変更
mousu-a 3416639
"未チェック"状態を変数を導入してわかりやすくした
mousu-a 8a6ffbd
生成されるHTMLが変わってしまっていたため修正
mousu-a beb140e
関数名を実態に即した形に
mousu-a 9a5cc64
comments.rbのテストが落ちやすくなっていたためコードを移動
mousu-a File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,48 @@ | ||
import Vue from 'vue' | ||
import CheckStamp from 'check-stamp.vue' | ||
import store from 'check-store.js' | ||
import CSRF from 'csrf' | ||
import 'whatwg-fetch' | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const checkStamp = document.getElementById('js-check-stamp') | ||
if (checkStamp) { | ||
const checkableId = checkStamp.getAttribute('data-checkable-id') | ||
const checkableType = checkStamp.getAttribute('data-checkable-type') | ||
new Vue({ | ||
store, | ||
render: (h) => | ||
h(CheckStamp, { | ||
props: { | ||
checkableId: checkableId, | ||
checkableType: checkableType | ||
} | ||
}) | ||
}).$mount('#js-check-stamp') | ||
} | ||
setCheckStamp() | ||
}) | ||
|
||
export const setCheckStamp = () => { | ||
const checkStamp = document.getElementById('js-check-stamp') | ||
if (!checkStamp) return | ||
|
||
const checkableType = checkStamp.getAttribute('data-checkable-type') | ||
const checkableId = checkStamp.getAttribute('data-checkable-id') | ||
store.dispatch('setCheckable', { | ||
checkableId: checkableId, | ||
checkableType: checkableType | ||
}) | ||
fetch( | ||
`/api/checks.json/?checkable_type=${checkableType}&checkable_id=${checkableId}`, | ||
{ | ||
method: 'GET', | ||
headers: { | ||
'X-Requested-With': 'XMLHttpRequest', | ||
'X-CSRF-Token': CSRF.getToken() | ||
}, | ||
credentials: 'same-origin' | ||
} | ||
) | ||
.then((response) => { | ||
return response.json() | ||
}) | ||
.then((json) => { | ||
const notChecked = !json[0] | ||
const checkStampElement = document.querySelector('.stamp-approve') | ||
|
||
checkStampElement.classList.toggle('is-hidden', notChecked) | ||
if (notChecked) return | ||
|
||
const checkedUserName = document.querySelector('.stamp__content-inner') | ||
const checkedCreatedAt = document.querySelector('.is-created-at') | ||
checkedUserName.textContent = json[0].user.login_name | ||
checkedCreatedAt.textContent = json[0].created_at | ||
}) | ||
.catch((error) => { | ||
console.warn(error) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.stamp.stamp-approve.is-hidden | ||
h2.stamp__content.is-title | ||
| 確認済 | ||
time.stamp__content.is-created-at | ||
.stamp__content.is-user-name | ||
.stamp__content-inner | ||
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. 現状のコードから生成されるHTMLは、 <div class="stamp stamp-approve show">
<h2 class="stamp__content is-title">確認済</h2>
<time class="stamp__content is-created-at">2024/11/20</time>
<div class="stamp__content is-user-name">komagata</div>
</div> となりますが変更前のファイルを見る限り、下記のHTMLを生成するコードが正しいのではないかと思いました。 <div class="stamp stamp-approve show">
<h2 class="stamp__content is-title">確認済</h2>
<time class="stamp__content is-created-at">2024/11/20</time>
<div class="stamp__content is-user-name">
<div class="stamp__content-inner">komagata</div>
</div>
</div> 現状だとユーザー名が下よりになっています。 変更すると中央に揃います。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
この処理(store.jsのcheckIdのセット)が遅いと、commentsテスト(日報にコメントをする処理のあるテスト)でコメントをする時に、日報をチェック済みかどうか?の確認(store.jsのcheckIdのセット)がコメントをするタイミングに間に合わず、日報がチェック済みであるにも関わらずアラートが出てしまうことがあります。それによりテストが落ちやすくなっていたため、コードを上に移動させました。
9a5cc64