-
Notifications
You must be signed in to change notification settings - Fork 79
メンターメモに作成者と作成時間を追加し、1対多の関係に変更 #10121
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
Open
matuaya
wants to merge
29
commits into
main
Choose a base branch
from
feature/add-author-and-timestamp-to-mentor-memos
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.
+607
−256
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0e893c9
MentorMemoモデルを作成しUserモデルと関連付け
matuaya f32a3ea
メンターメモの初期表示をJSからRailsに変更
matuaya a67f0aa
メンターメモにメモの追加機能を実装
matuaya a876e8d
メンターメモの初期化処理をinitializeMentorMemo.jsに分離
matuaya 48c3943
メンターメモにメモの編集機能を実装
matuaya 712fdd1
メンターメモにメモの削除機能を実装
matuaya 9a38e03
重複しているTextareaInitializerを削除
matuaya 0d94bad
プレビューの表示をタブクリック時に実行するように変更
matuaya 54d3a08
mentorMemoのチェックを早期リターンに変更
matuaya 7c165df
リクエストを@rails/request.jsで処理するように変更
matuaya 3dead7a
エディター再表示時のタブの状態を修正
matuaya b3d14fa
doorkeepr authorizationにcreateアクションを追加
matuaya fefc37d
ファイル名をuser_mentor_memo.jsからmentor-memos.jsに変更
matuaya ccb612b
パーシャルの呼び出しと渡すデータを修正
matuaya c8d9d16
不要なdivを削除
matuaya d3c9b46
メモの編集・削除に所有者チェックを追加
matuaya 2cb8f1d
メモが存在しない時のメッセージを常時DOMに置き、表示の制御をJSで行うよう変更
matuaya 1e8c81b
resetEditorTabsをDOMContentLoaded内に移動
matuaya 11e194e
saveボタンのdisabled状態が正しくなるよう修正
matuaya a1c26d4
ユーザーフィクスチャからmentor_memo属性を削除
matuaya 4ec5c32
メンターメモのテストをUser::MemoTestに集約し、重複テストを削除
matuaya 08dbe04
クエリのスコープをmentor-memoに変更
matuaya 235b0f4
メンター向けユーザーメモのデザインを整えた
machida 6c3ea45
メンター向けユーザーメモのhtmlの構造を変更
machida e367840
プレビュータブが正しく切り替わるように修正
matuaya 04f57ee
既存のメンターメモをMentorMemoにコピー
matuaya e1ce7c1
関数名をinitializeNewMemoからaddNewMemoに変更
matuaya 6a42459
メモ追加処理をInitializeNewMentorMemoに分離
matuaya fd93424
空白のみの入力時にsaveボタンが無効になるよう修正
matuaya 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 hidden or 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
82 changes: 82 additions & 0 deletions
82
app/assets/stylesheets/application/blocks/user/_mentor-memos.css
This file contains hidden or 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,82 @@ | ||
| .mentor-memo-list { | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| .mentor-memo { | ||
| font-size: 0.875rem; | ||
| line-height: 1.6; | ||
| } | ||
|
|
||
| .mentor-memo__inner { | ||
| padding: 1rem; | ||
| } | ||
|
|
||
| @media (width <= 47.9375em) { | ||
| .mentor-memo__inner { | ||
| padding: 0.75rem; | ||
| } | ||
| } | ||
|
|
||
| .mentor-memo:not(:last-child) { | ||
| border-bottom: solid 1px var(--border-tint); | ||
| } | ||
|
|
||
| .mentor-memo__meta { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.375rem; | ||
| margin-bottom: 0.5rem; | ||
| } | ||
|
|
||
| .mentor-memo__writer-link { | ||
| display: inline-flex; | ||
| flex: 0 0 auto; | ||
| line-height: 1; | ||
| } | ||
|
|
||
| .mentor-memo__writer { | ||
| font-size: 0.875rem; | ||
| line-height: 1.4; | ||
| font-weight: 600; | ||
| } | ||
|
|
||
| .mentor-memo__created-at { | ||
| margin-left: auto; | ||
| font-size: 0.75rem; | ||
| line-height: 1.4; | ||
| white-space: nowrap; | ||
| color: var(--muted-text); | ||
| } | ||
|
|
||
| .mentor-memo__body { | ||
| margin-bottom: 0.5rem; | ||
| } | ||
|
|
||
| .mentor-memo__actions { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.75rem; | ||
| } | ||
|
|
||
| .mentor-memo__action { | ||
| font-size: 0.75rem; | ||
| line-height: 1; | ||
| display: inline-flex; | ||
| align-items: center; | ||
| gap: 0.25rem; | ||
| cursor: pointer; | ||
| background-color: transparent; | ||
| border: none; | ||
| padding: 0; | ||
| color: var(--muted-text); | ||
| transition: color 0.2s ease-in; | ||
| } | ||
|
|
||
| .mentor-memo__action:hover { | ||
| color: var(--link-text); | ||
| } | ||
|
|
||
| .mentor-memo__action.is-danger:hover { | ||
| color: var(--danger); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,134 @@ | ||
| import TextareaInitializer from 'textarea-initializer' | ||
| import MarkdownInitializer from 'markdown-initializer' | ||
| import { put, destroy } from '@rails/request.js' | ||
|
|
||
| export default function initializeMemo(memo, userId) { | ||
| const memoId = memo.dataset.memo_id | ||
| const memoBody = memo.dataset.memo_body | ||
| let savedMemo = memoBody || '' | ||
|
|
||
| TextareaInitializer.initialize(`#js-memo-${memoId}`) | ||
| const markdownInitializer = new MarkdownInitializer() | ||
|
|
||
| const memoDisplay = memo.querySelector('.memo-display') | ||
| const memoDisplayContent = memo.querySelector('.memo-text') | ||
|
|
||
| const memoEditor = memo.querySelector('.memo-editor') | ||
| const editorTextarea = memo.querySelector('.a-markdown-input__textarea') | ||
| const editorPreview = memo.querySelector('.a-markdown-input__preview') | ||
|
|
||
| if (memoBody) { | ||
| memoDisplayContent.innerHTML = markdownInitializer.render(savedMemo) | ||
| editorPreview.innerHTML = markdownInitializer.render(savedMemo) | ||
| } | ||
|
|
||
| const editButton = memo.querySelector('.js-edit-memo') | ||
| if (editButton) { | ||
| editButton.addEventListener('click', () => { | ||
| toggleEditor() | ||
| resetEditorTabs() | ||
| }) | ||
| } | ||
|
|
||
| const saveButton = memo.querySelector('.js-save-memo') | ||
| editorTextarea.addEventListener('input', () => { | ||
| saveButton.disabled = editorTextarea.value.trim().length === 0 | ||
| }) | ||
|
|
||
| saveButton.addEventListener('click', async () => { | ||
| try { | ||
| const editedMemo = editorTextarea.value | ||
| await updateMemo(memoId, editedMemo, userId) | ||
| savedMemo = editedMemo | ||
| toggleEditor() | ||
| memoDisplayContent.innerHTML = markdownInitializer.render(savedMemo) | ||
| } catch (error) { | ||
| console.warn(error) | ||
| } | ||
| }) | ||
|
|
||
| const cancelButton = memo.querySelector('.js-cancel-memo') | ||
| cancelButton.addEventListener('click', () => { | ||
| toggleEditor() | ||
| editorTextarea.value = savedMemo | ||
| editorPreview.innerHTML = markdownInitializer.render(savedMemo) | ||
| saveButton.disabled = editorTextarea.value.trim().length === 0 | ||
| }) | ||
|
|
||
| const deleteButton = memo.querySelector('.js-delete-memo') | ||
| if (deleteButton) { | ||
| deleteButton.addEventListener('click', async () => { | ||
| if (window.confirm('本当によろしいですか?')) { | ||
| try { | ||
| await deleteMemo(memoId, userId) | ||
| memo.remove() | ||
|
|
||
| const mentorMemos = document.querySelector('.mentor-memos') | ||
| const emptyMessage = mentorMemos.querySelector('.o-empty-message') | ||
| const memoList = mentorMemos.querySelectorAll('.mentor-memo') | ||
|
|
||
| if (!memoList.length) emptyMessage.classList.remove('is-hidden') | ||
| } catch (error) { | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| console.warn(error) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| const editorTab = memoEditor.querySelector('.editor-tab') | ||
| const editorTabContent = memoEditor.querySelector('.is-editor') | ||
| const previewTab = memoEditor.querySelector('.preview-tab') | ||
| const previewTabContent = memoEditor.querySelector('.is-preview') | ||
|
|
||
| const tabElements = [ | ||
| editorTab, | ||
| editorTabContent, | ||
| previewTab, | ||
| previewTabContent | ||
| ] | ||
| editorTab.addEventListener('click', () => | ||
| toggleClass(tabElements, 'is-active') | ||
| ) | ||
| previewTab.addEventListener('click', () => { | ||
| editorPreview.innerHTML = markdownInitializer.render(editorTextarea.value) | ||
| toggleClass(tabElements, 'is-active') | ||
| }) | ||
|
|
||
| async function updateMemo(memoId, memoContent, userId) { | ||
| const params = { | ||
| mentor_memo: { | ||
| body: memoContent | ||
| } | ||
| } | ||
| const response = await put(`/api/users/${userId}/mentor_memos/${memoId}`, { | ||
| body: params | ||
| }) | ||
|
|
||
| if (!response.ok) throw new Error('Failed to update') | ||
| } | ||
|
|
||
| async function deleteMemo(memoId, userId) { | ||
| const response = await destroy( | ||
| `/api/users/${userId}/mentor_memos/${memoId}` | ||
| ) | ||
|
|
||
| if (!response.ok) throw new Error('Failed to delete') | ||
| } | ||
|
|
||
| function toggleEditor() { | ||
| toggleClass([memoDisplay, memoEditor], 'is-hidden') | ||
| } | ||
|
|
||
| function toggleClass(elements, className) { | ||
| elements.forEach((element) => { | ||
| element.classList.toggle(className) | ||
| }) | ||
| } | ||
|
|
||
| function resetEditorTabs() { | ||
| editorTab.classList.add('is-active') | ||
| editorTabContent.classList.add('is-active') | ||
| previewTab.classList.remove('is-active') | ||
| previewTabContent.classList.remove('is-active') | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
狭い画面でメタ情報が横にはみ出します。
.mentor-memo__metaが1行固定の flex で、__writer-linkも__created-atもほぼ縮まないため、ユーザー名が長いケースだと日時と衝突してカード幅を超えます。折り返しを許可するか、少なくともモバイルでは日時を次行へ落とせるようにしておいた方が安全です。💡 修正例
.mentor-memo__meta { display: flex; align-items: center; + flex-wrap: wrap; gap: 0.375rem; margin-bottom: 0.5rem; } .mentor-memo__writer-link { display: inline-flex; - flex: 0 0 auto; + flex: 0 1 auto; + min-width: 0; line-height: 1; } +@media (width <= 47.9375em) { + .mentor-memo__created-at { + margin-left: 0; + } +}📝 Committable suggestion
🤖 Prompt for AI Agents