From da594a4b4c88b56bf50bc5974fb256cd6a3e45ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Thu, 5 Dec 2024 10:35:00 +0100 Subject: [PATCH] Implement assignee editing --- src/components/AssigneeInput.svelte | 183 ++++++++++++++++++++++++++++ src/lib/utils.ts | 24 ++++ src/views/repo/Issue.svelte | 45 +++++-- 3 files changed, 239 insertions(+), 13 deletions(-) create mode 100644 src/components/AssigneeInput.svelte diff --git a/src/components/AssigneeInput.svelte b/src/components/AssigneeInput.svelte new file mode 100644 index 0000000..0876b39 --- /dev/null +++ b/src/components/AssigneeInput.svelte @@ -0,0 +1,183 @@ + + + + +
+
+
Assignees
+ + {#if allowedToEdit} +
+ {#if showInput} + + { + inputValue = ""; + showInput = false; + }} + name="cross" + styleCursor="pointer" /> + {:else} + (showInput = true)} + styleCursor="pointer"> + {/if} +
+ {/if} +
+ +
+ {#if allowedToEdit} + {#each updatedAssignees as assignee} + + {:else} +
Not assigned to anyone.
+ {/each} + {:else} + {#each updatedAssignees as assignee} + + {:else} +
Not assigned to anyone.
+ {/each} + {/if} +
+ + {#if showInput} +
+ + {#if !valid && validationMessage} +
+ {validationMessage} +
+ {/if} +
+ {/if} +
diff --git a/src/lib/utils.ts b/src/lib/utils.ts index e5b8a88..677c810 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -179,3 +179,27 @@ export function isMac() { export function modifierKey() { return isMac() ? "⌘" : "ctrl"; } + +export function parseNodeId( + nid: string, +): { prefix: string; pubkey: string } | undefined { + const match = /^(did:key:)?(z[a-zA-Z0-9]+)$/.exec(nid); + if (match) { + let hex: Uint8Array | undefined = undefined; + try { + hex = bs58.decode(match[2].substring(1)); + } catch (error) { + console.error("utils.parseNodId: Not able to decode received NID", error); + return undefined; + } + // This checks also that the first 2 bytes are equal + // to the ed25519 public key type used. + if (hex && !(hex.byteLength === 34 && hex[0] === 0xed && hex[1] === 1)) { + return undefined; + } + + return { prefix: match[1] || "did:key:", pubkey: match[2] }; + } + + return undefined; +} diff --git a/src/views/repo/Issue.svelte b/src/views/repo/Issue.svelte index 25a3688..80c7248 100644 --- a/src/views/repo/Issue.svelte +++ b/src/views/repo/Issue.svelte @@ -12,11 +12,7 @@ import * as roles from "@app/lib/roles"; import { invoke } from "@app/lib/invoke"; - import { - publicKeyFromDid, - scrollIntoView, - authorForNodeId, - } from "@app/lib/utils"; + import { publicKeyFromDid, scrollIntoView } from "@app/lib/utils"; import { announce } from "@app/components/AnnounceSwitch.svelte"; @@ -38,6 +34,7 @@ import Layout from "./Layout.svelte"; import Sidebar from "@app/components/Sidebar.svelte"; + import AssigneeInput from "@app/components/AssigneeInput.svelte"; interface Props { repo: RepoInfo; @@ -65,6 +62,7 @@ let editingTitle = $state(false); let updatedTitle = $state(""); let labelSaveInProgress: boolean = $state(false); + let assigneesSaveInProgress: boolean = $state(false); $effect(() => { // The component doesn't get destroyed when we switch between different @@ -102,6 +100,26 @@ } } + async function saveAssignees(assignees: string[]) { + try { + assigneesSaveInProgress = true; + await invoke("edit_issue", { + rid: repo.rid, + cobId: issue.id, + action: { + type: "assign", + assignees, + }, + opts: { announce: $announce }, + }); + } catch (error) { + console.error("Editing assignees failed", error); + } finally { + assigneesSaveInProgress = false; + await reload(); + } + } + async function toggleReply() { topLevelReplyOpen = !topLevelReplyOpen; if (!topLevelReplyOpen) { @@ -457,14 +475,15 @@
- -
- {#each issue.assignees as assignee} - - {:else} - Not assigned to anyone. - {/each} -
+ delegate.did), + issue.body.author.did, + )} + assignees={issue.assignees} + submitInProgress={assigneesSaveInProgress} + save={saveAssignees} />