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

+11 -3
View File
@@ -17,6 +17,7 @@
import { formatBytes, mediaKindLabel } from "#lib/format/media.js";
import { t } from "#lib/i18n/locale.svelte.js";
import { poster } from "#lib/media/poster.js";
import { createFlash } from "#lib/stores/flash.svelte.js";
import { shareUi } from "#lib/stores/shares.svelte.js";
import { toasts } from "#lib/stores/toasts.svelte.js";
@@ -49,6 +50,7 @@
let loading = $state(false);
let saving = $state(false);
let token = 0;
const queued = createFlash<number>();
const mime = $derived(result?.state === "ready" ? (result.mime ?? "") : "");
const isImage = $derived(mime.startsWith("image/") || kind === "photo");
@@ -140,9 +142,10 @@
if (messageId === null) {
return;
}
const target = messageId;
try {
await fetchMedia(chatId, messageId);
toasts.success(t("media.queued"));
await fetchMedia(chatId, target);
queued.show(target);
} catch {
toasts.error(t("media.queueFailed"));
}
@@ -312,7 +315,12 @@
<div class="media-message">
<p>{t("media.notDownloaded")}</p>
<Button fluid onclick={queueFetch} variant="primary">
{t("media.downloadToArchive")}
{#if queued.current === messageId}
<Icon name="check" />
{t("chat.media.queued")}
{:else}
{t("media.downloadToArchive")}
{/if}
</Button>
</div>
{:else if result?.state === "missing"}
+8 -4
View File
@@ -6,6 +6,7 @@
import { accounts } from "#lib/stores/accounts.svelte.js";
import { chats } from "#lib/stores/chats.svelte.js";
import { discover } from "#lib/stores/discover.svelte.js";
import { createFlash } from "#lib/stores/flash.svelte.js";
import { toasts } from "#lib/stores/toasts.svelte.js";
interface Props {
@@ -15,6 +16,7 @@
let { chatId }: Props = $props();
let busy = $state(false);
const started = createFlash<true>();
const item = $derived(discover.get(chatId));
const tracked = $derived(item?.tracked ?? false);
@@ -34,7 +36,7 @@
busy = true;
try {
discover.set(await trackChat(chatId, true));
toasts.success(t("track.started"));
started.show(true);
chats.refresh();
} catch {
toasts.error(t("track.failed"));
@@ -50,7 +52,7 @@
busy = true;
try {
await enqueueBackfill(chatId, true, true);
toasts.success(t("jobs.backfillStarted"));
started.show(true);
} catch {
toasts.error(t("jobs.backfillFailed"));
} finally {
@@ -67,8 +69,10 @@
<div class="actions">
{#if tracked}
<Button loading={busy} onclick={backfill} pill variant="secondary">
<Icon name="cloud-download" />
<span>{t("track.loadHistory")}</span>
<Icon name={started.current ? "check" : "cloud-download"} />
<span
>{started.current ? t("track.loading") : t("track.loadHistory")}</span
>
</Button>
{:else}
<Button loading={busy} onclick={track} pill variant="primary">
@@ -11,6 +11,7 @@
import { t } from "#lib/i18n/locale.svelte.js";
import { createChatPicker } from "#lib/stores/chat-picker.svelte.js";
import { chats } from "#lib/stores/chats.svelte.js";
import { createFlash } from "#lib/stores/flash.svelte.js";
import { toasts } from "#lib/stores/toasts.svelte.js";
import { page } from "$app/state";
@@ -24,6 +25,7 @@
let starting = $state(false);
let syncing = $state(false);
let syncingContacts = $state(false);
const started = createFlash<"backfill" | "sync" | "contacts">();
const picker = createChatPicker();
const availableChats = $derived(picker.results);
@@ -58,7 +60,7 @@
starting = true;
try {
await enqueueBackfill(selected, media, true);
toasts.success(t("jobs.backfillStarted"));
started.show("backfill");
version += 1;
} catch {
toasts.error(t("jobs.backfillFailed"));
@@ -74,7 +76,7 @@
syncing = true;
try {
await syncDialogs();
toasts.success(t("jobs.syncStarted"));
started.show("sync");
version += 1;
} catch {
toasts.error(t("jobs.syncFailed"));
@@ -90,7 +92,7 @@
syncingContacts = true;
try {
await syncContacts();
toasts.success(t("jobs.contactsStarted"));
started.show("contacts");
version += 1;
} catch {
toasts.error(t("jobs.contactsFailed"));
@@ -110,8 +112,13 @@
<p class="hint">{t("jobs.dialogsHint")}</p>
<div class="action">
<Button fluid loading={syncing} onclick={sync} variant="secondary">
<Icon name="reload" />
<span>{t("jobs.syncDialogs")}</span>
{#if started.current === "sync"}
<Icon name="check" />
<span>{t("jobs.status.pending")}</span>
{:else}
<Icon name="reload" />
<span>{t("jobs.syncDialogs")}</span>
{/if}
</Button>
</div>
<p class="hint">{t("jobs.contactsHint")}</p>
@@ -122,8 +129,13 @@
onclick={syncContactList}
variant="secondary"
>
<Icon name="user" />
<span>{t("jobs.syncContacts")}</span>
{#if started.current === "contacts"}
<Icon name="check" />
<span>{t("jobs.status.pending")}</span>
{:else}
<Icon name="user" />
<span>{t("jobs.syncContacts")}</span>
{/if}
</Button>
</div>
</section>
@@ -188,8 +200,13 @@
onclick={start}
variant="primary"
>
<Icon name="cloud-download" />
<span>{t("jobs.startBackfill")}</span>
{#if started.current === "backfill"}
<Icon name="check" />
<span>{t("jobs.status.pending")}</span>
{:else}
<Icon name="cloud-download" />
<span>{t("jobs.startBackfill")}</span>
{/if}
</Button>
</div>
</section>
@@ -11,6 +11,7 @@
import Spinner from "#lib/components/ui/Spinner.svelte";
import { t } from "#lib/i18n/locale.svelte.js";
import { poster } from "#lib/media/poster.js";
import { createFlash } from "#lib/stores/flash.svelte.js";
import { toasts } from "#lib/stores/toasts.svelte.js";
interface Props {
@@ -24,7 +25,17 @@
let loaded = $state(false);
let inline = $state<InlineMedia | null>(null);
let queuing = $state(false);
const queued = createFlash<true>();
const queueIcon = $derived.by(() => {
if (queuing) {
return "timer";
}
return queued.current ? "check" : "download";
});
const queueLabel = $derived(
queued.current ? t("chat.media.queued") : t("media.downloadToArchive")
);
const ready = $derived(inline?.state === "ready" ? inline : null);
const isVideo = $derived(ready ? visualKind(ready.kind) === "video" : false);
@@ -40,7 +51,7 @@
queuing = true;
try {
await fetchMedia(chatId, media.message_id);
toasts.success(t("media.queued"));
queued.show(true);
} catch {
toasts.error(t("media.queueFailed"));
} finally {
@@ -66,8 +77,14 @@
<img alt={t("media.attachment")} src={ready.url}>
</button>
{:else if inline?.state === "not-downloaded"}
<button class="tile placeholder" onclick={queue} type="button">
<Icon name={queuing ? "timer" : "download"} size="1.5rem" />
<button
aria-label={queueLabel}
class="tile placeholder"
onclick={queue}
title={queueLabel}
type="button"
>
<Icon name={queueIcon} size="1.5rem" />
</button>
{:else if loaded}
<div class="tile placeholder"><Icon name="photo" size="1.5rem" /></div>
@@ -55,9 +55,8 @@
loginId = "";
await accounts.load();
if (state.account) {
accounts.select(state.account.account_id);
accounts.switchTo(state.account.account_id);
}
toasts.success(t("login.added"));
open = false;
}
@@ -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;
@@ -1,4 +1,5 @@
<script lang="ts">
import { SvelteSet } from "svelte/reactivity";
import {
deleteShare,
listShares,
@@ -11,6 +12,7 @@
import ShareLinkField from "#lib/components/shares/ShareLinkField.svelte";
import ContextMenu from "#lib/components/ui/ContextMenu.svelte";
import ContextMenuItem from "#lib/components/ui/ContextMenuItem.svelte";
import CopyItem from "#lib/components/ui/CopyItem.svelte";
import EmptyState from "#lib/components/ui/EmptyState.svelte";
import Icon from "#lib/components/ui/Icon.svelte";
import Spinner from "#lib/components/ui/Spinner.svelte";
@@ -19,6 +21,7 @@
import { formatDownloads, formatExpiry } from "#lib/format/shares.js";
import { t } from "#lib/i18n/locale.svelte.js";
import { accounts } from "#lib/stores/accounts.svelte.js";
import { createFlash } from "#lib/stores/flash.svelte.js";
import { shareUi } from "#lib/stores/shares.svelte.js";
import { toasts } from "#lib/stores/toasts.svelte.js";
import { ui } from "#lib/stores/ui.svelte.js";
@@ -31,10 +34,14 @@
let filter = $state<Filter>("active");
let expanded = $state<number | null>(null);
let token = 0;
const kept = new SvelteSet<number>();
const done = createFlash<number>();
const visible = $derived(
filter === "active"
? items.filter((item) => shareState(item) === "active")
? items.filter(
(item) => kept.has(item.id) || shareState(item) === "active"
)
: items
);
const activeCount = $derived(
@@ -50,6 +57,7 @@
const rows = await listShares(activeOnly);
if (current === token) {
items = rows;
kept.clear();
}
} catch {
if (current === token) {
@@ -79,15 +87,11 @@
ui.closePanel();
}
async function copy(share: FileShare) {
await navigator.clipboard.writeText(shareUrl(share));
toasts.success(t("shares.copied"));
}
async function revoke(share: FileShare) {
try {
replace(await revokeShare(share.id));
toasts.success(t("shares.revokedToast"));
kept.add(share.id);
done.show(share.id);
} catch {
toasts.error(t("shares.revokeFailed"));
}
@@ -96,7 +100,7 @@
async function reissue(share: FileShare) {
try {
replace(await reissueShare(share.id));
toasts.success(t("shares.reissued"));
done.show(share.id);
} catch {
toasts.error(t("shares.reissueFailed"));
}
@@ -205,9 +209,12 @@
</button>
{/snippet}
{#snippet menu()}
<ContextMenuItem icon="copy" onselect={() => copy(share)}>
{t("shares.copy")}
</ContextMenuItem>
<CopyItem
done={t("shares.copied")}
icon="copy"
label={t("shares.copy")}
text={() => shareUrl(share)}
/>
{#if share.message_id !== null || share.peer_id !== null}
<ContextMenuItem icon="reply" onselect={() => jump(share)}>
{t("ui.jumpToMessage")}
@@ -247,7 +254,14 @@
<Icon name="reply" size="1rem" />{t("shares.toMessage")}
</button>
{/if}
{#if state === "active"}
{#if done.current === share.id}
<span class="done">
<Icon name="check" size="1rem" />
{state === "active"
? t("shares.reissued")
: t("shares.accessRevoked")}
</span>
{:else if state === "active"}
<button
class="pill danger"
onclick={() => revoke(share)}
@@ -461,6 +475,18 @@
}
}
.done {
display: inline-flex;
align-items: center;
gap: 0.25rem;
padding: 0.3125rem 0;
border: 1px solid transparent;
font-size: 0.8125rem;
color: var(--color-text-green);
}
.footnote {
margin: 0;
padding: 0 1rem 1rem;
@@ -18,6 +18,7 @@
import { peerName } from "#lib/format/peer.js";
import { t } from "#lib/i18n/locale.svelte.js";
import { accounts } from "#lib/stores/accounts.svelte.js";
import { createFlash } from "#lib/stores/flash.svelte.js";
import { toasts } from "#lib/stores/toasts.svelte.js";
interface Group {
@@ -45,6 +46,7 @@
let viewerItems = $state<StoryView[]>([]);
let viewerPeerId = $state(0);
let backfilling = $state<number | null>(null);
const started = createFlash<number>();
async function load() {
const current = token;
@@ -150,7 +152,7 @@
backfilling = peerId;
try {
await enqueueStoriesBackfill(peerId);
toasts.success(t("stories.backfillStarted"));
started.show(peerId);
} catch {
toasts.error(t("stories.backfillFailed"));
} finally {
@@ -178,6 +180,10 @@
{/if}
{:else}
{#each groups as group (group.peerId)}
{@const fresh = started.current === group.peerId}
{@const backfillLabel = fresh
? t("stories.backfillStarted")
: t("stories.loadOlderStories")}
<section class="group">
<header class="group-head">
<button
@@ -200,14 +206,15 @@
</span>
</button>
<Button
aria-label={t("stories.loadOlderStories")}
aria-label={backfillLabel}
loading={backfilling === group.peerId}
onclick={() => backfill(group.peerId)}
round
smaller
title={backfillLabel}
variant="translucent"
>
<Icon name="cloud-download" />
<Icon name={fresh ? "check" : "cloud-download"} />
</Button>
</header>
{#if expanded[group.peerId]}
@@ -11,6 +11,7 @@
import Spinner from "#lib/components/ui/Spinner.svelte";
import { t } from "#lib/i18n/locale.svelte.js";
import { accounts } from "#lib/stores/accounts.svelte.js";
import { createFlash } from "#lib/stores/flash.svelte.js";
import { toasts } from "#lib/stores/toasts.svelte.js";
import { page } from "$app/state";
@@ -27,6 +28,7 @@
);
let backfilling = $state(false);
const started = createFlash<number>();
let items = $state<StoryView[]>([]);
let loading = $state(false);
@@ -109,7 +111,7 @@
backfilling = true;
try {
await enqueueStoriesBackfill(id);
toasts.success(t("stories.backfillStarted"));
started.show(id);
} catch {
toasts.error(t("stories.backfillFailed"));
} finally {
@@ -137,7 +139,11 @@
smaller
variant="secondary"
>
<Icon name="cloud-download" />{t("stories.loadOlder")}
{#if started.current === peerId}
<Icon name="check" />{t("stories.backfillStarted")}
{:else}
<Icon name="cloud-download" />{t("stories.loadOlder")}
{/if}
</Button>
<Button
aria-label={t("ui.refresh")}