blob: 584fd68921300fbfb277f52cf937827b5fb7a42c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
<script lang="ts">
import type { WorkspaceEntry } from "@dispatch/wire";
import type { WorkspaceStore } from "../store.svelte";
import { relativeTime } from "../logic/view-model";
let {
store,
onOpen,
onClose,
}: {
store: WorkspaceStore;
/** Open (view) a workspace — navigates to `/<id>`. */
onOpen: (id: string) => void;
onClose: () => void;
} = $props();
// Load the archived list when the modal mounts.
$effect(() => {
void store.refreshArchived();
});
let busyId = $state<string | null>(null);
let actionError = $state<string | null>(null);
async function unarchive(ws: WorkspaceEntry): Promise<void> {
if (busyId !== null) return;
busyId = ws.id;
actionError = null;
const result = await store.setArchived(ws.id, false);
busyId = null;
if (!result.ok) {
actionError = result.error;
return;
}
// Refresh the archived list so the unarchived workspace leaves it.
void store.refreshArchived();
}
function open(ws: WorkspaceEntry): void {
onOpen(ws.id);
onClose();
}
</script>
<div class="modal modal-open" role="dialog" aria-label="Archived workspaces">
<div class="modal-box max-w-lg">
<div class="flex items-start justify-between gap-2">
<div>
<h2 class="text-lg font-bold">Archived workspaces</h2>
<p class="text-xs opacity-50">Hidden from the home grid. Unarchive to restore.</p>
</div>
<button
type="button"
class="btn btn-circle btn-ghost btn-sm"
aria-label="Close archived workspaces"
onclick={onClose}>✕</button
>
</div>
{#if actionError}
<p class="mt-3 text-xs text-error">{actionError}</p>
{/if}
<div class="mt-4">
{#if store.archivedLoading && store.archivedList.length === 0}
<div class="flex justify-center py-8">
<span class="loading loading-spinner loading-md opacity-60"></span>
</div>
{:else if store.archivedList.length === 0}
<p class="py-8 text-center text-sm opacity-50">No archived workspaces.</p>
{:else}
<ul class="flex flex-col gap-2">
{#each store.archivedList as ws (ws.id)}
<li
class="flex items-center justify-between gap-3 rounded-box border border-base-content/10 bg-base-200/40 px-3 py-2"
>
<div class="min-w-0 flex-1">
<p class="truncate font-semibold">{ws.title}</p>
<p class="font-mono text-xs opacity-50">
/{ws.id} · {ws.conversationCount} conv · {relativeTime(
ws.lastActivityAt,
Date.now(),
)} ago
</p>
</div>
<div class="flex shrink-0 items-center gap-1">
<button
type="button"
class="btn btn-ghost btn-xs"
onclick={() => open(ws)}
aria-label={`Open ${ws.title}`}>View</button
>
<button
type="button"
class="btn btn-outline btn-xs"
disabled={busyId === ws.id}
onclick={() => void unarchive(ws)}
aria-label={`Unarchive ${ws.title}`}
>
{#if busyId === ws.id}
<span class="loading loading-spinner loading-xs"></span>
{:else}
Unarchive
{/if}
</button>
</div>
</li>
{/each}
</ul>
{/if}
</div>
</div>
<!-- Click outside closes. -->
<button
type="button"
class="modal-backdrop"
aria-label="Close archived workspaces backdrop"
onclick={onClose}></button>
</div>
|