diff --git a/src/components/Chip.svelte b/src/components/Chip.svelte index e13450370..51c2dd365 100644 --- a/src/components/Chip.svelte +++ b/src/components/Chip.svelte @@ -1,19 +1,25 @@
- + + + {#if removeable} diff --git a/src/components/Comment.svelte b/src/components/Comment.svelte index f66528138..27390ec0a 100644 --- a/src/components/Comment.svelte +++ b/src/components/Comment.svelte @@ -1,13 +1,15 @@ @@ -99,16 +94,9 @@ {:else} {/if} - {#if groupedReactions.size > 0} + {#if id && (reactions.length > 0 || $httpdStore.state === "authenticated")}
- {#each groupedReactions as [reaction, nids], key} - -
- {reaction} - {nids.length} -
-
- {/each} +
{/if}
diff --git a/src/components/Reactions.svelte b/src/components/Reactions.svelte new file mode 100644 index 000000000..fdaebaade --- /dev/null +++ b/src/components/Reactions.svelte @@ -0,0 +1,112 @@ + + + + +
+ {#if $httpdStore.state === "authenticated"} + +
+ {#each config.reactions as reaction} + + {/each} +
+ +
+ {/if} + {#if groupedReactions.size > 0} + {#each groupedReactions as [reaction, nids], key} + { + if ($httpdStore.state === "authenticated") { + dispatch("react", { nids, id, reaction }); + } + }}> +
+ {reaction} + {nids.length} +
+
+ {/each} + {/if} +
diff --git a/src/components/Thread.svelte b/src/components/Thread.svelte index 449853683..72645ad45 100644 --- a/src/components/Thread.svelte +++ b/src/components/Thread.svelte @@ -42,6 +42,7 @@ const dispatch = createEventDispatcher<{ reply: { id: string; body: string }; + react: { nids: string[]; commentId: string | undefined; reaction: string }; cancel: never; }>(); @@ -81,7 +82,8 @@ timestamp={root.timestamp} body={root.body} showReplyIcon={Boolean($httpdStore.state === "authenticated")} - on:toggleReply={toggleReply} /> + on:toggleReply={toggleReply} + on:react /> {#each replies as reply}
@@ -93,7 +95,8 @@ caption="replied" reactions={reply.reactions} timestamp={reply.timestamp} - body={reply.body} /> + body={reply.body} + on:react />
{/each} {#if showReplyTextarea} diff --git a/src/config.json b/src/config.json index a3208cb7a..cfa35b2e3 100644 --- a/src/config.json +++ b/src/config.json @@ -14,6 +14,7 @@ } ] }, + "reactions": ["👍", "👎", "😄", "🎉", "🙁", "🚀", "👀"], "projects": { "pinned": [ { diff --git a/src/views/projects/Cob/Revision.svelte b/src/views/projects/Cob/Revision.svelte index 2eb181310..40d8cffdd 100644 --- a/src/views/projects/Cob/Revision.svelte +++ b/src/views/projects/Cob/Revision.svelte @@ -339,6 +339,7 @@ {:else if element.type === "merge"}
+ body={review.summary} + on:react />
{:else}
acc.set(emoji, [...(acc.get(emoji) ?? []), nid]), - new Map(), - ); - let action: "edit" | "view"; $: action = $httpdStore.state === "authenticated" && utils.isLocal(baseUrl.hostname) @@ -85,6 +80,32 @@ } } + async function handleReaction({ + detail: { nids, id, reaction }, + }: CustomEvent<{ nids: string[]; id: string; reaction: string }>) { + if ($httpdStore.state === "authenticated") { + try { + const status = await updateIssue( + project.id, + issue.id, + { + type: "comment.react", + id, + reaction, + active: nids.includes($httpdStore.session.publicKey) ? false : true, + }, + $httpdStore.session, + api, + ); + if (status === "success") { + issue = await refreshIssue(project.id, issue, api); + } + } catch (e) { + console.error(e); + } + } + } + async function editTitle({ detail: title }: CustomEvent) { if ( $httpdStore.state === "authenticated" && @@ -262,17 +283,6 @@ padding-left: 1rem; margin-left: 1rem; } - .reactions { - display: inline-flex; - gap: 0.5rem; - margin-top: 1rem; - user-select: none; - } - .reaction { - display: inline-flex; - flex-direction: row; - gap: 0.5rem; - } .actions { display: flex; @@ -287,6 +297,9 @@ flex-wrap: nowrap; gap: 0.5rem; } + .reactions { + margin-top: 1rem; + } .thread { margin: 1rem 0; } @@ -341,16 +354,12 @@ - {#if issue.discussion[0].reactions} -
- {#each groupedReactions as [reaction, nids], key} - -
- {reaction} - {nids.length} -
-
- {/each} + {#if issue.discussion[0].reactions.length > 0 || $httpdStore.state === "authenticated"} +
+
{/if}
@@ -363,7 +372,11 @@ {#each threads as thread (thread.root.id)}
- +
{/each} {#if $httpdStore.state === "authenticated"} diff --git a/src/views/projects/Patch.svelte b/src/views/projects/Patch.svelte index 579ed191d..cb5d8f26b 100644 --- a/src/views/projects/Patch.svelte +++ b/src/views/projects/Patch.svelte @@ -80,6 +80,25 @@ patch = await api.project.getPatchById(project.id, patch.id); } } + async function handleReaction({ + detail: { nids, id, reaction }, + }: CustomEvent<{ nids: string[]; id: string; reaction: string }>) { + if ($httpdStore.state === "authenticated") { + await api.project.updatePatch( + project.id, + patch.id, + { + type: "revision.comment.react", + revision: revisionId, + comment: id, + reaction, + active: nids.includes($httpdStore.session.publicKey) ? false : true, + }, + $httpdStore.session.id, + ); + patch = await api.project.getPatchById(project.id, patch.id); + } + } function badgeColor(status: string): Variant { if (status === "draft") { return "foreground"; @@ -435,6 +454,7 @@ projectHead={project.head} {...revision} first={index === 0} + on:react={handleReaction} on:reply={createReply} patchId={patch.id} expanded={index === patch.revisions.length - 1} diff --git a/tests/e2e/project/issues.spec.ts b/tests/e2e/project/issues.spec.ts index c34c6083e..3ed815a77 100644 --- a/tests/e2e/project/issues.spec.ts +++ b/tests/e2e/project/issues.spec.ts @@ -19,6 +19,48 @@ test("navigate single issue", async ({ page }) => { ); }); +test("adding and removing reactions", async ({ page, authenticatedPeer }) => { + await page.goto(authenticatedPeer.uiUrl()); + const { rid, projectFolder } = await createProject( + authenticatedPeer, + "handle-reactions", + ); + await authenticatedPeer.rad( + [ + "issue", + "open", + "--title", + "This is an issue to test reactions", + "--description", + "We'll write some comments and add and remove reactions to them", + ], + { cwd: projectFolder }, + ); + await page.goto( + `${authenticatedPeer.uiUrl()}/${rid}/issues/48af7d329e5b44ee8d348eeb7e341370243db9ad`, + ); + const commentReactionToggle = page.locator(".card-body .toggle").first(); + await page.getByPlaceholder("Leave your comment").fill("This is a comment"); + await page.getByRole("button", { name: "Comment" }).click(); + await commentReactionToggle.click(); + await page.getByRole("button", { name: "👍" }).click(); + await expect(page.locator("span").filter({ hasText: "👍 1" })).toBeVisible(); + + await commentReactionToggle.click(); + await page.getByRole("button", { name: "🎉" }).click(); + await expect(page.locator("span").filter({ hasText: "🎉 1" })).toBeVisible(); + await expect(page.locator(".reaction")).toHaveCount(2); + + await page.locator("span").filter({ hasText: "👍 1" }).click(); + await expect(page.locator("span").filter({ hasText: "👍 1" })).toBeHidden(); + await expect(page.locator(".reaction")).toHaveCount(1); + + await commentReactionToggle.click(); + await page.getByRole("button", { name: "🎉" }).click(); + await expect(page.locator("span").filter({ hasText: "🎉 1" })).toBeHidden(); + await expect(page.locator(".reaction")).toHaveCount(0); +}); + test("test issue counters", async ({ page, authenticatedPeer }) => { const { rid, projectFolder } = await createProject( authenticatedPeer, diff --git a/tests/e2e/project/patches.spec.ts b/tests/e2e/project/patches.spec.ts index a0df9ea3e..71347babd 100644 --- a/tests/e2e/project/patches.spec.ts +++ b/tests/e2e/project/patches.spec.ts @@ -38,6 +38,56 @@ test("navigate patch details", async ({ page }) => { } }); +test("adding and removing reactions", async ({ page, authenticatedPeer }) => { + await page.goto(authenticatedPeer.uiUrl()); + const { rid, projectFolder } = await createProject( + authenticatedPeer, + "handle-reactions", + ); + await authenticatedPeer.git(["switch", "-c", "feature-1"], { + cwd: projectFolder, + }); + await authenticatedPeer.git( + ["commit", "--allow-empty", "-m", "Reaction patch"], + { + cwd: projectFolder, + }, + ); + await authenticatedPeer.git(["push", "rad", "HEAD:refs/patches"], { + cwd: projectFolder, + }); + await authenticatedPeer.rad( + [ + "comment", + "bfc3bc2c6af29920283f83e7ada9d52b2d4d3a57", + "--message", + "This is a comment for reactions", + ], + { cwd: projectFolder }, + ); + await page.goto( + `${authenticatedPeer.uiUrl()}/${rid}/patches/bfc3bc2c6af29920283f83e7ada9d52b2d4d3a57`, + ); + const commentReactionToggle = page.locator(".card-body .toggle").first(); + await commentReactionToggle.click(); + await page.getByRole("button", { name: "👍" }).click(); + await expect(page.locator("span").filter({ hasText: "👍 1" })).toBeVisible(); + + await commentReactionToggle.click(); + await page.getByRole("button", { name: "🎉" }).click(); + await expect(page.locator("span").filter({ hasText: "🎉 1" })).toBeVisible(); + await expect(page.locator(".reaction")).toHaveCount(2); + + await page.locator("span").filter({ hasText: "👍 1" }).click(); + await expect(page.locator("span").filter({ hasText: "👍 1" })).toBeHidden(); + await expect(page.locator(".reaction")).toHaveCount(1); + + await commentReactionToggle.click(); + await page.getByRole("button", { name: "🎉" }).click(); + await expect(page.locator("span").filter({ hasText: "🎉 1" })).toBeHidden(); + await expect(page.locator(".reaction")).toHaveCount(0); +}); + test("test patches counters", async ({ page, authenticatedPeer }) => { const { rid, projectFolder, defaultBranch } = await createProject( authenticatedPeer, diff --git a/tests/support/heartwood-version b/tests/support/heartwood-version index f367d9b1d..f3b36dac2 100644 --- a/tests/support/heartwood-version +++ b/tests/support/heartwood-version @@ -1 +1 @@ -95a314688589b8b974015fef57f1e0b0751692ad +f6bd7a3dc6176adbd8b55f3a0801b6ecb26b1649