From dbb2fd0614cac7d77f15db8999732336d904ea90 Mon Sep 17 00:00:00 2001 From: reckyy Date: Tue, 14 Jan 2025 17:32:12 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=E5=9B=9E=E7=AD=94=E3=81=AE=E3=83=97?= =?UTF-8?q?=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC=E3=82=92=E5=88=9D=E6=9C=9F?= =?UTF-8?q?=E5=8C=96=E3=81=97=E3=81=A6=E3=81=84=E3=81=AA=E3=81=8B=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/initializeAnswer.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/javascript/initializeAnswer.js b/app/javascript/initializeAnswer.js index 464120ef292..23b30ffd676 100644 --- a/app/javascript/initializeAnswer.js +++ b/app/javascript/initializeAnswer.js @@ -14,9 +14,19 @@ export default function initializeAnswer(answer) { const answerEditor = answer.querySelector('.answer-editor') const answerDisplayContent = answerDisplay.querySelector('.a-long-text') const answerDescription = answerDisplayContent.innerHTML + + const answerEditorPreview = answerEditor.querySelector( + '.a-markdown-input__preview' + ) + const editorTextarea = answerEditor.querySelector( + '.a-markdown-input__textarea' + ) + if (answerDescription) { answerDisplayContent.innerHTML = markdownInitializer.render(answerDescription) + answerEditorPreview.innerHTML = + markdownInitializer.render(answerDescription) } const editButton = answerDisplay.querySelector('.card-main-actions__action') @@ -40,13 +50,6 @@ export default function initializeAnswer(answer) { }) } - const answerEditorPreview = answerEditor.querySelector( - '.a-markdown-input__preview' - ) - const editorTextarea = answerEditor.querySelector( - '.a-markdown-input__textarea' - ) - const cancelButton = answerEditor.querySelector('.is-secondary') cancelButton.addEventListener('click', () => { toggleVisibility(modalElements, 'is-hidden') From 5ed1f256d116bf4ab7c824092b596412f8536666 Mon Sep 17 00:00:00 2001 From: reckyy Date: Tue, 14 Jan 2025 22:59:26 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=E7=94=BB=E5=83=8F=E3=81=8C=E3=82=A2?= =?UTF-8?q?=E3=83=83=E3=83=97=E3=83=AD=E3=83=BC=E3=83=89=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/initializeAnswer.js | 2 +- app/javascript/new-answer.js | 2 +- app/views/questions/_answer.html.slim | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/javascript/initializeAnswer.js b/app/javascript/initializeAnswer.js index 23b30ffd676..af2cfd3d72c 100644 --- a/app/javascript/initializeAnswer.js +++ b/app/javascript/initializeAnswer.js @@ -6,6 +6,7 @@ import MarkdownInitializer from 'markdown-initializer' export default function initializeAnswer(answer) { const questionId = answer.dataset.question_id const answerId = answer.dataset.answer_id + const answerDescription = answer.dataset.answer_description let savedAnswer = '' TextareaInitializer.initialize(`#js-comment-${answerId}`) const markdownInitializer = new MarkdownInitializer() @@ -13,7 +14,6 @@ export default function initializeAnswer(answer) { const answerDisplay = answer.querySelector('.answer-display') const answerEditor = answer.querySelector('.answer-editor') const answerDisplayContent = answerDisplay.querySelector('.a-long-text') - const answerDescription = answerDisplayContent.innerHTML const answerEditorPreview = answerEditor.querySelector( '.a-markdown-input__preview' diff --git a/app/javascript/new-answer.js b/app/javascript/new-answer.js index aa4ef3efbca..0f6609afe48 100644 --- a/app/javascript/new-answer.js +++ b/app/javascript/new-answer.js @@ -10,7 +10,7 @@ import store from './check-store.js' document.addEventListener('DOMContentLoaded', () => { const newAnswer = document.querySelector('.new-answer') if (newAnswer) { - TextareaInitializer.initialize('#new-comment') + TextareaInitializer.initialize('#js-new-comment') const markdownInitializer = new MarkdownInitializer() const questionId = newAnswer.dataset.question_id let savedAnswer = '' diff --git a/app/views/questions/_answer.html.slim b/app/views/questions/_answer.html.slim index 3204868b087..9928be7db75 100644 --- a/app/views/questions/_answer.html.slim +++ b/app/views/questions/_answer.html.slim @@ -1,4 +1,4 @@ -.thread-comment.answer id="answer_#{answer.id}" data-question_id="#{question.id}" data-answer_id="#{answer.id}" +.thread-comment.answer id="answer_#{answer.id}" data-question_id="#{question.id}" data-answer_id="#{answer.id}" data-answer_description="#{answer.description}" .thread-comment__start a.thread-comment__user-link href="#{answer.user.url}" span class="a-user-role is-#{answer.user.primary_role}" @@ -64,7 +64,7 @@ .a-markdown-input__inner.is-editor.js-tabs__content.is-active .form-textarea .form-textarea__body - textarea.a-text-input.a-markdown-input__textarea data-id="#js-comment-#{answer.id}" data-preview="#js-comment-preview-#{answer.id}" data-input=".js-comment-file-input-#{answer.id}" name='answer[description]' + textarea.a-text-input.a-markdown-input__textarea id="js-comment-#{answer.id}" data-preview="#js-comment-preview-#{answer.id}" data-input=".js-comment-file-input-#{answer.id}" name='answer[description]' = answer.description .form-textarea__footer .form-textarea__insert From 4264b95651ab6d6604b7133405617597e88c07f0 Mon Sep 17 00:00:00 2001 From: reckyy Date: Wed, 15 Jan 2025 22:59:31 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=E5=9B=9E=E7=AD=94=E6=8A=95=E7=A8=BF?= =?UTF-8?q?=E6=99=82=E3=81=AB=E3=83=97=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E3=83=96=E3=82=92=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=82=BF=E3=83=96=E3=81=AB=E3=83=AA=E3=82=BB=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=81=99=E3=82=8B=E6=A9=9F=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit comments_test.rb L193 の対応 --- app/javascript/new-answer.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/javascript/new-answer.js b/app/javascript/new-answer.js index 0f6609afe48..e746b8a36cc 100644 --- a/app/javascript/new-answer.js +++ b/app/javascript/new-answer.js @@ -33,7 +33,7 @@ document.addEventListener('DOMContentLoaded', () => { saveButton.addEventListener('click', () => { savedAnswer = editorTextarea.value - createAnswer(savedAnswer, questionId) + createAnswer(savedAnswer, questionId, tabElements) editorTextarea.value = '' answerEditorPreview.innerHTML = markdownInitializer.render( editorTextarea.value @@ -62,7 +62,7 @@ document.addEventListener('DOMContentLoaded', () => { } }) -function createAnswer(description, questionId) { +function createAnswer(description, questionId, tabElements) { if (description.length < 1) { return null } @@ -103,6 +103,11 @@ function createAnswer(description, questionId) { initializeReaction(reactionElement) updateAnswerCount(true) updateWatchable(questionId) + const [, , previewTab] = tabElements + if (previewTab.classList.contains('is-active')) { + toggleVisibility(tabElements, 'is-active') + } + toast('回答を投稿しました!') }) .catch((error) => { From c6a6580ce852a95305563553cce88288d9746b52 Mon Sep 17 00:00:00 2001 From: reckyy Date: Thu, 16 Jan 2025 22:48:15 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=E5=9B=9E=E7=AD=94=E6=8A=95=E7=A8=BF?= =?UTF-8?q?=E5=BE=8C=E3=80=81=E6=96=B0=E8=A6=8F=E5=9B=9E=E7=AD=94=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=BC=E3=83=A0=E3=81=AEtextarea=E3=82=92=E3=83=87?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=88=E3=81=AB=E6=88=BB=E3=81=99?= =?UTF-8?q?=E5=87=A6=E7=90=86=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/new-answer.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/javascript/new-answer.js b/app/javascript/new-answer.js index e746b8a36cc..9b61932f950 100644 --- a/app/javascript/new-answer.js +++ b/app/javascript/new-answer.js @@ -11,6 +11,8 @@ document.addEventListener('DOMContentLoaded', () => { const newAnswer = document.querySelector('.new-answer') if (newAnswer) { TextareaInitializer.initialize('#js-new-comment') + const defaultTextareaSize = + document.getElementById('js-new-comment').scrollHeight const markdownInitializer = new MarkdownInitializer() const questionId = newAnswer.dataset.question_id let savedAnswer = '' @@ -39,6 +41,7 @@ document.addEventListener('DOMContentLoaded', () => { editorTextarea.value ) saveButton.disabled = true + resizeTextarea(editorTextarea, defaultTextareaSize) }) const editTab = answerEditor.querySelector('.edit-answer-tab') @@ -127,3 +130,7 @@ function updateWatchable(questionId) { watchableType: 'Question' }) } + +function resizeTextarea(textarea, defaultTextareaSize) { + textarea.style.height = `${defaultTextareaSize}px` +} From 1e31d12023ffb723485330b92276a437eaab7ce6 Mon Sep 17 00:00:00 2001 From: reckyy Date: Fri, 17 Jan 2025 20:56:53 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=E6=96=B0=E8=A6=8F=E5=9B=9E=E7=AD=94?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=A0=E3=81=AE=E5=88=9D=E6=9C=9F?= =?UTF-8?q?=E5=8C=96=E5=87=A6=E7=90=86=E3=82=92=E8=A1=8C=E3=81=86initializ?= =?UTF-8?q?eNewAnswer=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=82=92?= =?UTF-8?q?=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/new-answer.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/javascript/new-answer.js b/app/javascript/new-answer.js index 9b61932f950..20dd9e5895b 100644 --- a/app/javascript/new-answer.js +++ b/app/javascript/new-answer.js @@ -35,12 +35,17 @@ document.addEventListener('DOMContentLoaded', () => { saveButton.addEventListener('click', () => { savedAnswer = editorTextarea.value - createAnswer(savedAnswer, questionId, tabElements) + createAnswer(savedAnswer, questionId) editorTextarea.value = '' answerEditorPreview.innerHTML = markdownInitializer.render( editorTextarea.value ) saveButton.disabled = true + updateAnswerCount(true) + updateWatchable(questionId) + if (previewTab.classList.contains('is-active')) { + toggleVisibility(tabElements, 'is-active') + } resizeTextarea(editorTextarea, defaultTextareaSize) }) @@ -65,7 +70,7 @@ document.addEventListener('DOMContentLoaded', () => { } }) -function createAnswer(description, questionId, tabElements) { +function createAnswer(description, questionId) { if (description.length < 1) { return null } @@ -96,21 +101,7 @@ function createAnswer(description, questionId, tabElements) { } }) .then((html) => { - const answersList = document.querySelector('.answers-list') - const answerDiv = document.createElement('div') - answerDiv.innerHTML = html - const newAnswerElement = answerDiv.firstElementChild - answersList.appendChild(newAnswerElement) - initializeAnswer(newAnswerElement) - const reactionElement = newAnswerElement.querySelector('.js-reactions') - initializeReaction(reactionElement) - updateAnswerCount(true) - updateWatchable(questionId) - const [, , previewTab] = tabElements - if (previewTab.classList.contains('is-active')) { - toggleVisibility(tabElements, 'is-active') - } - + initializeNewAnswer(html) toast('回答を投稿しました!') }) .catch((error) => { @@ -134,3 +125,14 @@ function updateWatchable(questionId) { function resizeTextarea(textarea, defaultTextareaSize) { textarea.style.height = `${defaultTextareaSize}px` } + +function initializeNewAnswer(html) { + const answersList = document.querySelector('.answers-list') + const answerDiv = document.createElement('div') + answerDiv.innerHTML = html + const newAnswerElement = answerDiv.firstElementChild + answersList.appendChild(newAnswerElement) + initializeAnswer(newAnswerElement) + const reactionElement = newAnswerElement.querySelector('.js-reactions') + initializeReaction(reactionElement) +} From dc549d38d6672b295b4af12f63c1afceed50fb7e Mon Sep 17 00:00:00 2001 From: reckyy Date: Fri, 17 Jan 2025 22:14:05 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E5=9B=9E=E7=AD=94=E3=82=92=E5=8F=A4?= =?UTF-8?q?=E3=81=84=E9=A0=86=EF=BC=88=E6=98=87=E9=A0=86=EF=BC=89=E3=81=A7?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/questions_controller.rb | 1 + app/views/questions/show.html.slim | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index 783c520e04d..87969a15b2d 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -33,6 +33,7 @@ def show .includes(:correct_answer) .latest_update_order .limit(MAX_PRACTICE_QUESTIONS_DISPLAYED) + @answers = @question.answers.order(created_at: :asc) respond_to do |format| format.html format.md diff --git a/app/views/questions/show.html.slim b/app/views/questions/show.html.slim index 65ef5b0dcd7..43b1a695813 100644 --- a/app/views/questions/show.html.slim +++ b/app/views/questions/show.html.slim @@ -39,7 +39,7 @@ hr.a-border h2.thread-comments__title | 回答・コメント .answers-list - - @question.answers.each do |answer| + - @answers.each do |answer| = render 'answer', question: @question, user: current_user, answer: answer = render 'new_answer', question: @question, user: current_user nav.a-side-nav