Files
thoughtsync/frontend/src/stores/devices.ts
T
bvandeusenandClaude Opus 4.8 20cf15c99c
CI & Build / Python lint (push) Successful in 3s
CI & Build / TypeScript typecheck (push) Successful in 7s
CI & Build / Python tests (push) Successful in 9s
CI & Build / Build & push image (push) Successful in 29s
desktop M10.3: frontend data-source adapter seam (repo interface + rest.ts)
Extract a typed repository interface (adapters/repo.ts) from the scattered
store/view -> api.* calls, backed by adapters/rest.ts (verbatim HTTP mapping)
and selected through adapters/index.ts. Every store and the notes-facing views
now depend on `repo`, never the HTTP client directly -- the seam the offline
local source (M10.5, over Tauri invoke) plugs into next.

Behavior-preserving for web: rest.ts maps each semantic method to the exact
endpoint the code called before; query-string and multipart building moved out
of the stores/views into rest.ts (the one place that knows the URL shape).
Client-side logic (reconcile/sort/optimistic reorder/toasts) stays in the
stores. GraphView + admin SettingsView keep direct api calls -- out of the
offline-core scope (M10.5 is board/editor/capture/search/filter/labels/
checklists/reminders).

Task 1992.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FRgehjoz7Yv8LkUfADxACm
2026-07-24 22:31:00 -04:00

41 lines
1.1 KiB
TypeScript

import { defineStore } from "pinia";
import { ref } from "vue";
import { repo } from "../adapters";
// A linked native client (Tauri/Android) that holds a device bearer token.
export interface Device {
id: string;
name: string;
created_at: string | null;
last_used_at: string | null;
}
export const useDevicesStore = defineStore("devices", () => {
const items = ref<Device[]>([]);
const loading = ref(false);
async function load(): Promise<void> {
loading.value = true;
try {
items.value = await repo.devices.list();
} finally {
loading.value = false;
}
}
// Issues a token for the current user; the plaintext token is returned ONCE
// (never retrievable again) for the caller to display + copy.
async function create(name: string): Promise<string> {
const res = await repo.devices.create(name);
items.value.unshift(res.device);
return res.token;
}
async function revoke(id: string): Promise<void> {
await repo.devices.remove(id);
items.value = items.value.filter((d) => d.id !== id);
}
return { items, loading, load, create, revoke };
});