Cleaning up state flags

This commit is contained in:
Sebastian Martinez
2023-11-15 09:32:12 +01:00
parent 664158e472
commit 1188e84c87
5 changed files with 56 additions and 59 deletions
+8 -11
View File
@@ -29,8 +29,7 @@
// TODO: Remove flag once `radicle-httpd` fixes embed editing
export let disableEdit: boolean = false;
let editInProgress = false;
let submitInProgress = false;
let state: "read" | "edit" | "submit" = "read";
export let editComment:
| ((body: string, embeds: Embed[]) => Promise<void>)
@@ -126,11 +125,9 @@
<NodeId nodeId={authorId} alias={authorAlias} />
{caption}
<div class="header-right">
{#if id && editComment && !editInProgress && !disableEdit}
{#if id && editComment && state === "read" && !disableEdit}
<div class="edit-buttons">
<IconButton
title="edit comment"
on:click={() => (editInProgress = true)}>
<IconButton title="edit comment" on:click={() => (state = "edit")}>
<IconSmall name={"edit"} />
</IconButton>
</div>
@@ -143,26 +140,26 @@
</div>
<div class="card-body">
{#if editComment && editInProgress}
{#if editComment && state !== "read"}
{@const editComment_ = editComment}
<ExtendedTextarea
{body}
{enableAttachments}
{submitInProgress}
submitInProgress={state === "submit"}
submitCaption="Save"
placeholder="Leave your comment"
on:submit={async ({ detail: { comment, embeds } }) => {
submitInProgress = true;
state = "submit";
try {
await editComment_(comment, embeds);
} finally {
submitInProgress = false;
state = "read";
}
}}
on:close={async () => {
body = body;
await tick();
editInProgress = false;
state = "read";
}} />
{:else if body.trim() === ""}
<span class="txt-missing">No description</span>
+7 -9
View File
@@ -11,8 +11,7 @@
export let focus: boolean = false;
export let submit: (comment: string, embeds: Embed[]) => Promise<void>;
let submitInProgress: boolean = false;
let active: boolean = false;
let state: "collapsed" | "expanded" | "submit" = "collapsed";
</script>
<style>
@@ -30,23 +29,22 @@
}
</style>
{#if active}
{#if state !== "collapsed"}
<ExtendedTextarea
{inline}
{placeholder}
{submitCaption}
{submitInProgress}
submitInProgress={state === "submit"}
{focus}
{body}
{enableAttachments}
on:close={() => (active = false)}
on:close={() => (state = "collapsed")}
on:submit={async ({ detail: { comment, embeds } }) => {
try {
submitInProgress = true;
state = "submit";
await submit(comment, embeds);
} finally {
submitInProgress = false;
active = false;
state = "collapsed";
}
}} />
{:else}
@@ -55,7 +53,7 @@
class="inactive"
role="button"
tabindex="0"
on:click={() => (active = true)}>
on:click={() => (state = "expanded")}>
{placeholder}
</div>
{/if}