mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Cleaning up state flags
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user