feat(frontend): a finished action answers on the button that was pressed instead of a toast

This commit is contained in:
hh committed 2026-10-19 06:07:54 +00:00
1 parent e228d999dd
commit bca0b34636
15 files changed
+179 -73

No files matched your search

@@ -19,6 +19,7 @@
import { formatShareLimits } from "#lib/format/shares.js";
import { t } from "#lib/i18n/locale.svelte.js";
import type { MessageKey } from "#lib/i18n/messages.js";
import { createFlash } from "#lib/stores/flash.svelte.js";
import { toasts } from "#lib/stores/toasts.svelte.js";
interface Props {
@@ -72,6 +73,8 @@
let maxDownloads = $state<number | null>(null);
let showQr = $state(false);
let token = 0;
const saved = createFlash<number>();
const revoked = createFlash<ShareSubject>();
const settings = $derived<ShareSettings>({
expiresInSeconds: expiresIn === KEEP ? null : expiresIn,
@@ -125,7 +128,6 @@
busy = true;
try {
adopt(await createShare(subject, settings));
toasts.success(t("shares.opened"));
} catch (error) {
fail(error, "shares.openFailed");
} finally {
@@ -139,8 +141,9 @@
}
busy = true;
try {
adopt(await updateShare(share.id, settings));
toasts.success(t("shares.updated"));
const next = await updateShare(share.id, settings);
adopt(next);
saved.show(next.id);
} catch (error) {
fail(error, "shares.updateFailed");
} finally {
@@ -149,15 +152,15 @@
}
async function revoke() {
if (!share || busy) {
if (!(share && subject) || busy) {
return;
}
const target = subject;
busy = true;
try {
await revokeShare(share.id);
adopt(null);
toasts.success(t("shares.revokedToast"));
open = false;
revoked.show(target);
} catch (error) {
fail(error, "shares.revokeFailed");
} finally {
@@ -314,12 +317,22 @@
{#if !loading}
<div class="dialog-actions">
{#if share}
{#if subject && revoked.current === subject}
<p class="done">
<Icon name="check" size="1.25rem" />
{t("shares.accessRevoked")}
</p>
{:else if share}
<Button loading={busy} onclick={revoke} pill variant="danger">
{t("shares.revoke")}
</Button>
<Button loading={busy} onclick={applyLimits} pill>
{t("common.save")}
{#if saved.current === share.id}
<Icon name="check" />
{t("shares.saved")}
{:else}
{t("common.save")}
{/if}
</Button>
{:else}
<Button fluid loading={busy} onclick={publish} pill>
@@ -333,6 +346,20 @@
</Dialog.Root>
<style lang="scss">
.done {
display: flex;
flex: 1;
gap: 0.375rem;
align-items: center;
justify-content: center;
height: 3rem;
margin: 0;
font-weight: var(--font-weight-medium);
color: var(--color-text-green);
}
.center {
display: flex;
justify-content: center;