fix: preserve comment IDs and enter edit mode only on request
Deploy EG-BIM QA Gateway / deploy (push) Failing after 21s
Deploy EG-BIM QA Gateway / deploy (push) Failing after 21s
This commit is contained in:
1 parent
922d24cac7
commit
03f2cd3b65
2 files changed
+157
-8
No files matched your search
+14
-8
@@ -757,10 +757,10 @@
|
||||
comment = comment || {};
|
||||
const rawAttachments = comment.attachments || comment.images || comment.comment_attachments || comment.commentAttachments || [];
|
||||
return {
|
||||
id: comment.id || '',
|
||||
id: String(comment.id || comment.comment_id || comment.commentId || '').trim(),
|
||||
authorId: comment.author_id || comment.authorId || comment.requester_id || comment.requesterId || '',
|
||||
author: comment.author_name || comment.authorName || comment.author?.name || comment.author || '작성자',
|
||||
date: formatKoreanDateTime(comment.created_at || comment.createdAt || comment.updated_at || '', true),
|
||||
date: comment.date || formatKoreanDateTime(comment.created_at || comment.createdAt || comment.updated_at || '', true),
|
||||
content: comment.content || comment.body || '',
|
||||
attachments: (Array.isArray(rawAttachments) ? rawAttachments : [rawAttachments]).map(normalizeAttachment)
|
||||
};
|
||||
@@ -775,7 +775,7 @@
|
||||
}).join('');
|
||||
}
|
||||
|
||||
let editingCommentId = '';
|
||||
let editingCommentId = null;
|
||||
function isCommentOwner(comment, user) {
|
||||
const authorId = String(comment.authorId || '').trim().toLowerCase();
|
||||
const userIds = [user && user.requesterId, user && user.ssoSubject, user && user.userUuid].map(function (id) { return String(id || '').trim().toLowerCase(); }).filter(Boolean);
|
||||
@@ -787,8 +787,8 @@
|
||||
qs('#commentCount').textContent = comments.length;
|
||||
const user = detailUser || getAuthUser();
|
||||
qs('#comments').innerHTML = comments.length ? comments.map(function (comment) {
|
||||
const owner = isCommentOwner(comment, user);
|
||||
const editing = editingCommentId === comment.id && owner;
|
||||
const owner = Boolean(comment.id) && isCommentOwner(comment, user);
|
||||
const editing = Boolean(editingCommentId) && editingCommentId === comment.id && owner;
|
||||
const actions = owner ? '<div class="comment-actions"><button class="button button-outline" type="button" data-comment-edit="' + escapeHtml(comment.id) + '">수정</button><button class="button button-danger" type="button" data-comment-delete="' + escapeHtml(comment.id) + '">삭제</button></div>' : '';
|
||||
const content = editing ? '<textarea class="textarea comment-edit-input" data-comment-edit-input maxlength="5000">' + escapeHtml(comment.content) + '</textarea><div class="comment-actions"><button class="button button-outline" type="button" data-comment-cancel>취소</button><button class="button button-primary" type="button" data-comment-save="' + escapeHtml(comment.id) + '">저장</button></div>' : '<div class="comment-content">' + escapeHtml(comment.content) + '</div>';
|
||||
return '<div class="comment" data-comment-id="' + escapeHtml(comment.id) + '"><div class="comment-meta"><strong>' + escapeHtml(comment.author) + '</strong><span>' + escapeHtml(comment.date) + '</span></div>' + content + (comment.attachments.length ? '<div class="comment-attachments-list">' + renderCommentAttachments(comment.attachments) + '</div>' : '') + (editing ? '' : actions) + '</div>';
|
||||
@@ -817,7 +817,7 @@
|
||||
if (input) { input.focus(); input.setSelectionRange(input.value.length, input.value.length); }
|
||||
return;
|
||||
}
|
||||
if (cancelButton) { editingCommentId = ''; comments = renderComments(comments); return; }
|
||||
if (cancelButton) { editingCommentId = null; comments = renderComments(comments); return; }
|
||||
if (saveButton) {
|
||||
const commentId = saveButton.getAttribute('data-comment-save');
|
||||
const comment = comments.find(function (item) { return item.id === commentId; });
|
||||
@@ -829,7 +829,7 @@
|
||||
const result = await requestJson(commentsPath + '/' + encodeURIComponent(commentId), { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ content: content }) });
|
||||
const updatedComment = normalizeComment(Object.assign({}, comment, result.comment || result, { content: content }));
|
||||
comments = comments.map(function (item) { return item.id === commentId ? updatedComment : item; });
|
||||
editingCommentId = '';
|
||||
editingCommentId = null;
|
||||
renderComments(comments);
|
||||
showToast('댓글이 수정되었습니다.');
|
||||
} catch (error) { showToast(error.message || '댓글 수정에 실패했습니다.'); saveButton.disabled = false; }
|
||||
@@ -871,7 +871,13 @@
|
||||
}
|
||||
const result = await postToApi(commentsPath, payload);
|
||||
const localAttachments = files.map(function (file) { const url = URL.createObjectURL(file); return { name: file.name, url: url, thumbnailUrl: url }; });
|
||||
const savedComment = normalizeComment(result.comment || { id: result.id, content: content, author: (getAuthUser() || {}).name || '작성자', createdAt: new Date().toISOString(), attachments: localAttachments });
|
||||
const savedComment = normalizeComment(Object.assign({
|
||||
content: content,
|
||||
author: (getAuthUser() || {}).name || '작성자',
|
||||
createdAt: new Date().toISOString(),
|
||||
attachments: localAttachments
|
||||
}, result.comment || result.data || result));
|
||||
if (!savedComment.id) savedComment.id = normalizeComment(result).id;
|
||||
if (!savedComment.authorId) savedComment.authorId = (getAuthUser() || {}).requesterId || '';
|
||||
if (!savedComment.attachments.length) savedComment.attachments = localAttachments;
|
||||
comments.push(savedComment);
|
||||
|
||||
Reference in new issue
Block a user