From 6052098c18ff08d6fb42f8cbbdfcf059e354564f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Fri, 25 Oct 2024 16:21:36 +0200 Subject: [PATCH] Allow editing issue titles --- src/components/Border.svelte | 2 +- src/components/TextInput.svelte | 20 ++++++- src/views/repo/Issue.svelte | 93 ++++++++++++++++++++++++++++++--- 3 files changed, 105 insertions(+), 10 deletions(-) diff --git a/src/components/Border.svelte b/src/components/Border.svelte index fc3152909..af34eb009 100644 --- a/src/components/Border.svelte +++ b/src/components/Border.svelte @@ -1,5 +1,5 @@ - + { focussed = true; @@ -69,5 +86,6 @@ bind:value autocomplete="off" spellcheck="false" + on:keydown|stopPropagation={handleKeydown} on:input /> diff --git a/src/views/repo/Issue.svelte b/src/views/repo/Issue.svelte index 51c5ddb55..72814502e 100644 --- a/src/views/repo/Issue.svelte +++ b/src/views/repo/Issue.svelte @@ -32,6 +32,7 @@ import Layout from "./Layout.svelte"; import { tick } from "svelte"; + import TextInput from "@app/components/TextInput.svelte"; export let repo: RepoInfo; export let issue: Issue; @@ -39,12 +40,16 @@ export let config: Config; let topLevelReplyOpen = false; + let editingTitle = false; + let updatedTitle: string = issue.title; - // Close the comment textbox when switching between issues. The view doesn't - // get destroyed when we switch between different issues in the sidebar and - // because of that the top-level state gets retained when the issue changes. + // The view doesn't get destroyed when we switch between different issues in + // the sidebar and because of that the top-level state gets retained when the + // issue changes. $: if (issue) { topLevelReplyOpen = false; + editingTitle = false; + updatedTitle = issue.title; } $: project = repo.payloads["xyz.radicle.project"]!; @@ -137,6 +142,32 @@ } } + async function editTitle(id: string, title: string) { + if (issue.title === updatedTitle) { + editingTitle = false; + return; + } + + try { + await invoke("edit_issue", { + rid: repo.rid, + cobId: issue.id, + action: { + type: "edit", + id, + title, + }, + opts: { announce: $announce }, + }); + editingTitle = false; + issue.title = updatedTitle; + } catch (error) { + if (error instanceof Error) { + console.error("Issue editing failed: ", error); + } + } + } + async function reactOnComment( publicKey: string, commentId: string, @@ -173,8 +204,12 @@ font-weight: var(--font-weight-medium); -webkit-user-select: text; user-select: text; - margin-bottom: 1rem; - margin-top: 0.35rem; + margin-bottom: 20px; + margin-top: 6px; + display: flex; + align-items: center; + justify-content: space-between; + word-break: break-all; } .issue-body { margin-top: 1rem; @@ -212,6 +247,12 @@ margin-left: 1.25rem; background-color: var(--color-background-float); } + + .title-icons { + display: flex; + gap: 0.5rem; + margin-left: 1rem; + } @@ -283,9 +324,45 @@
-
- -
+ {#if editingTitle} +
+ 0} + bind:value={updatedTitle} + autofocus + onSubmit={() => { + if (updatedTitle.trim().length > 0) { + editTitle(issue.id, updatedTitle); + } + }} + onDismiss={() => { + updatedTitle = issue.title; + editingTitle = !editingTitle; + }} /> +
+ { + if (updatedTitle.trim().length > 0) { + editTitle(issue.id, updatedTitle); + } + }} /> + { + updatedTitle = issue.title; + editingTitle = !editingTitle; + }} /> +
+
+ {:else} +
+ +
+ (editingTitle = !editingTitle)} /> +
+
+ {/if}