summaryrefslogtreecommitdiffhomepage
path: root/src/features/workspaces/store.svelte.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-27 01:13:28 +0900
committerAdam Malczewski <[email protected]>2026-06-27 01:13:31 +0900
commit0a271e3e8aecb1ec9db3eea873b3df1ecaab8b99 (patch)
tree0a5a6e62acf2d8e15ec69fd09f641cd75a1bcb10 /src/features/workspaces/store.svelte.ts
parent397ce9b65b888121d8c7e909c37dfdbffe914673 (diff)
parent576f539670f406280f8398abf78a867d70b683b8 (diff)
downloaddispatch-web-0a271e3e8aecb1ec9db3eea873b3df1ecaab8b99.tar.gz
dispatch-web-0a271e3e8aecb1ec9db3eea873b3df1ecaab8b99.zip
Merge branch 'dev' into feature/heartbeat
# Conflicts: # src/app/App.svelte # src/app/store.svelte.ts # src/app/store.test.ts # src/features/workspaces/ui/WorkspaceCard.test.ts
Diffstat (limited to 'src/features/workspaces/store.svelte.ts')
-rw-r--r--src/features/workspaces/store.svelte.ts132
1 files changed, 66 insertions, 66 deletions
diff --git a/src/features/workspaces/store.svelte.ts b/src/features/workspaces/store.svelte.ts
index 0cf4ce2..046c235 100644
--- a/src/features/workspaces/store.svelte.ts
+++ b/src/features/workspaces/store.svelte.ts
@@ -9,80 +9,80 @@ import type { WorkspaceHttp, WorkspaceResult } from "./adapter/http";
* owned by the composition root.
*/
export interface WorkspaceStore {
- /** All workspaces (sorted by lastActivityAt desc by the backend). */
- readonly list: readonly WorkspaceEntry[];
- readonly loading: boolean;
- readonly error: string | null;
- /** Refresh the list from the backend. */
- refresh(): Promise<void>;
- /** `PUT /workspaces/:id` (create-on-miss). Returns the workspace or an error. */
- ensure(id: string, body?: EnsureWorkspaceRequest): Promise<WorkspaceResult<Workspace>>;
- /** Rename a workspace (display only; id unchanged). */
- rename(id: string, title: string): Promise<WorkspaceResult<Workspace>>;
- /** Set/clear a workspace's default cwd. */
- setDefaultCwd(id: string, defaultCwd: string | null): Promise<WorkspaceResult<Workspace>>;
- /** Set/clear a workspace's default computer (SSH `Host` alias; null = local). */
- setDefaultComputer(id: string, computerId: string | null): Promise<WorkspaceResult<Workspace>>;
- /** Delete a workspace (closes its conversations, reassigns to "default"). */
- remove(id: string): Promise<WorkspaceResult<{ closedCount: number }>>;
+ /** All workspaces (sorted by lastActivityAt desc by the backend). */
+ readonly list: readonly WorkspaceEntry[];
+ readonly loading: boolean;
+ readonly error: string | null;
+ /** Refresh the list from the backend. */
+ refresh(): Promise<void>;
+ /** `PUT /workspaces/:id` (create-on-miss). Returns the workspace or an error. */
+ ensure(id: string, body?: EnsureWorkspaceRequest): Promise<WorkspaceResult<Workspace>>;
+ /** Rename a workspace (display only; id unchanged). */
+ rename(id: string, title: string): Promise<WorkspaceResult<Workspace>>;
+ /** Set/clear a workspace's default cwd. */
+ setDefaultCwd(id: string, defaultCwd: string | null): Promise<WorkspaceResult<Workspace>>;
+ /** Set/clear a workspace's default computer (SSH `Host` alias; null = local). */
+ setDefaultComputer(id: string, computerId: string | null): Promise<WorkspaceResult<Workspace>>;
+ /** Delete a workspace (closes its conversations, reassigns to "default"). */
+ remove(id: string): Promise<WorkspaceResult<{ closedCount: number }>>;
}
export function createWorkspaceStore(http: WorkspaceHttp): WorkspaceStore {
- let list = $state<readonly WorkspaceEntry[]>([]);
- let loading = $state(false);
- let error = $state<string | null>(null);
+ let list = $state<readonly WorkspaceEntry[]>([]);
+ let loading = $state(false);
+ let error = $state<string | null>(null);
- return {
- get list(): readonly WorkspaceEntry[] {
- return list;
- },
- get loading(): boolean {
- return loading;
- },
- get error(): string | null {
- return error;
- },
+ return {
+ get list(): readonly WorkspaceEntry[] {
+ return list;
+ },
+ get loading(): boolean {
+ return loading;
+ },
+ get error(): string | null {
+ return error;
+ },
- async refresh(): Promise<void> {
- loading = true;
- error = null;
- try {
- list = await http.list();
- } catch (err) {
- error = err instanceof Error ? err.message : "Failed to load workspaces";
- } finally {
- loading = false;
- }
- },
+ async refresh(): Promise<void> {
+ loading = true;
+ error = null;
+ try {
+ list = await http.list();
+ } catch (err) {
+ error = err instanceof Error ? err.message : "Failed to load workspaces";
+ } finally {
+ loading = false;
+ }
+ },
- async ensure(id, body): Promise<WorkspaceResult<Workspace>> {
- const result = await http.ensure(id, body);
- if (result.ok) void this.refresh();
- return result;
- },
+ async ensure(id, body): Promise<WorkspaceResult<Workspace>> {
+ const result = await http.ensure(id, body);
+ if (result.ok) void this.refresh();
+ return result;
+ },
- async rename(id, title): Promise<WorkspaceResult<Workspace>> {
- const result = await http.setTitle(id, title);
- if (result.ok) void this.refresh();
- return result;
- },
+ async rename(id, title): Promise<WorkspaceResult<Workspace>> {
+ const result = await http.setTitle(id, title);
+ if (result.ok) void this.refresh();
+ return result;
+ },
- async setDefaultCwd(id, defaultCwd): Promise<WorkspaceResult<Workspace>> {
- const result = await http.setDefaultCwd(id, defaultCwd);
- if (result.ok) void this.refresh();
- return result;
- },
+ async setDefaultCwd(id, defaultCwd): Promise<WorkspaceResult<Workspace>> {
+ const result = await http.setDefaultCwd(id, defaultCwd);
+ if (result.ok) void this.refresh();
+ return result;
+ },
- async setDefaultComputer(id, computerId): Promise<WorkspaceResult<Workspace>> {
- const result = await http.setDefaultComputer(id, computerId);
- if (result.ok) void this.refresh();
- return result;
- },
+ async setDefaultComputer(id, computerId): Promise<WorkspaceResult<Workspace>> {
+ const result = await http.setDefaultComputer(id, computerId);
+ if (result.ok) void this.refresh();
+ return result;
+ },
- async remove(id): Promise<WorkspaceResult<{ closedCount: number }>> {
- const result = await http.delete(id);
- if (result.ok) void this.refresh();
- return result;
- },
- };
+ async remove(id): Promise<WorkspaceResult<{ closedCount: number }>> {
+ const result = await http.delete(id);
+ if (result.ok) void this.refresh();
+ return result;
+ },
+ };
}