* 'main' of https://framagit.org/isUnknown/design-to-pack:
  #88 - fix edit comment system
  delete reply working
This commit is contained in:
Timothée Goguely 2025-01-07 16:07:56 +01:00
commit bc1722495f
5 changed files with 16 additions and 17 deletions

View file

@ -10,13 +10,13 @@ return [
$page = page($data->location->page->uri); $page = page($data->location->page->uri);
$project = page($data->location->project->uri); $project = page($data->location->project->uri);
$file = $page->file($data->location->file->uuid); $file = $page->file($data->location->file->uuid);
$isReply = $data->location->parentId ?? false; $isReply = $data->location->parent->id ?? false;
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
foreach ($comments as $key => &$comment) { foreach ($comments as $key => &$comment) {
if ($isReply) { if ($isReply) {
if ($comment['id'] === $data->location->parentId) { if ($comment['id'] === $data->location->parent->id) {
foreach ($comment['replies'] as $replyKey => $reply) { foreach ($comment['replies'] as $replyKey => $reply) {
if ($reply['id'] === $data->id) { if ($reply['id'] === $data->id) {
unset($comment['replies'][$replyKey]); unset($comment['replies'][$replyKey]);

View file

@ -10,13 +10,13 @@ return [
$page = page($data->location->page->uri); $page = page($data->location->page->uri);
$project = page($data->location->project->uri); $project = page($data->location->project->uri);
$file = $page->file($data->location->file->uuid); $file = $page->file($data->location->file->uuid);
$isReply = $data->location->parentId ?? false; $isReply = $data->location->parent->id ?? false;
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
foreach ($comments as $key => &$comment) { foreach ($comments as $key => &$comment) {
if ($isReply) { if ($isReply) {
if ($comment['id'] === $data->location->parentId) { if ($comment['id'] === $data->location->parent->id) {
foreach ($comment['replies'] as $replyKey => $reply) { foreach ($comment['replies'] as $replyKey => $reply) {
if ($reply['id'] === $data->id) { if ($reply['id'] === $data->id) {
$comment['replies'][$replyKey]["text"] = $data->text; $comment['replies'][$replyKey]["text"] = $data->text;

View file

@ -21,13 +21,13 @@
</p> </p>
</header> </header>
<p v-if="!isEditCommentMode" class="comment__body"> <p v-if="!comment.isEditMode" class="comment__body">
{{ comment.text }} {{ comment.text }}
</p> </p>
<textarea v-else class="comment__body" v-model="draftText" :rows="Math.ceil(draftText.length / 32)"></textarea> <textarea v-else class="comment__body" v-model="draftText" :rows="Math.ceil(draftText.length / 32)"></textarea>
<footer v-if="!isEditCommentMode" class="comment__replies"> <footer v-if="!comment.isEditMode" class="comment__replies">
<p v-if="comment.replies?.length > 0"> <p v-if="comment.replies?.length > 0">
{{ comment.replies.length }} réponse{{ {{ comment.replies.length }} réponse{{
comment.replies.length > 1 ? "s" : "" comment.replies.length > 1 ? "s" : ""
@ -40,7 +40,7 @@
<button <button
class="btn btn--transparent btn--icon btn--sm" class="btn btn--transparent btn--icon btn--sm"
data-icon="edit" data-icon="edit"
@click="isEditCommentMode = true" @click="comment.isEditMode = true"
> >
<span class="sr-only">Éditer</span> <span class="sr-only">Éditer</span>
</button> </button>
@ -89,7 +89,7 @@ const emits = defineEmits(["update:file", "close:comment"]);
const userStore = useUserStore(); const userStore = useUserStore();
const api = useApiStore(); const api = useApiStore();
const dialog = useDialogStore(); const dialog = useDialogStore();
const { activeTracks, isEditCommentMode } = storeToRefs(useDialogStore()); const { activeTracks } = storeToRefs(useDialogStore());
const draftText = ref(comment.text); const draftText = ref(comment.text);
// Functions // Functions
@ -141,7 +141,7 @@ async function deleteComment(event) {
// If there is an active track, // If there is an active track,
// it's not the opened file that should be updated // it's not the opened file that should be updated
// but the corresponding file in the active track // but the corresponding file in the active track
if (activeTracks.value.length > 0) { if (activeTracks.value?.length > 0) {
activeTracks.value[0].files = activeTracks.value[0].files.map((file) => { activeTracks.value[0].files = activeTracks.value[0].files.map((file) => {
if (file.uuid !== newFile.uuid) return file; if (file.uuid !== newFile.uuid) return file;
return newFile; return newFile;
@ -159,12 +159,12 @@ function saveEditedComment(event) {
comment.text = draftText.value; comment.text = draftText.value;
comment.date = dayjs().format(); comment.date = dayjs().format();
api.updateComment(comment); api.updateComment(comment);
isEditCommentMode.value = false; comment.isEditMode = false;
} }
function cancelEditComment(event) { function cancelEditComment(event) {
event.stopImmediatePropagation(); event.stopImmediatePropagation();
isEditCommentMode.value = false; comment.isEditMode = false;
draftText.value = comment.text; draftText.value = comment.text;
} }
</script> </script>

View file

@ -121,8 +121,9 @@ dayjs.locale("fr");
const { user } = useUserStore(); const { user } = useUserStore();
const { page } = usePageStore(); const { page } = usePageStore();
const dialog = useDialogStore(); const dialog = useDialogStore();
const { comments, openedFile, draftComment, activeTracks, isEditCommentMode } = const { comments, openedFile, draftComment, activeTracks } = storeToRefs(
storeToRefs(useDialogStore()); useDialogStore()
);
const api = useApiStore(); const api = useApiStore();
const openedComment = ref(null); const openedComment = ref(null);
@ -304,11 +305,11 @@ function prepareDraftCommentInImage(event) {
} }
function openComment(comment) { function openComment(comment) {
if (isEditCommentMode.value) return; if (comment.isEditMode) return;
openedComment.value = comment; openedComment.value = comment;
if (activeTracks?.value.length === 1) { if (activeTracks.value?.length === 1) {
openedFile.value = activeTracks.value[0].files.find( openedFile.value = activeTracks.value[0].files.find(
(file) => file.uuid === openedComment.value.location.file.uuid (file) => file.uuid === openedComment.value.location.file.uuid
); );

View file

@ -6,7 +6,6 @@ export const useDialogStore = defineStore("dialog", () => {
const content = ref(null); const content = ref(null);
const openedFile = ref(null); const openedFile = ref(null);
const activeTracks = ref(null); const activeTracks = ref(null);
const isEditCommentMode = ref(false);
const comments = computed(() => { const comments = computed(() => {
if (activeTracks.value?.length > 0) { if (activeTracks.value?.length > 0) {
@ -144,6 +143,5 @@ export const useDialogStore = defineStore("dialog", () => {
isCommentsOpen, isCommentsOpen,
isCommentPanelEnabled, isCommentPanelEnabled,
updateFile, updateFile,
isEditCommentMode,
}; };
}); });