Skip to content
36 linesCodeBlameRaw
1/**
2 * Each person's dock pins, kept with their account by identity
3 * (`dock_pins` / `set_dock_pins`), so their dock follows them to every
4 * device. lib/apps.ts says which apps can be pinned; identity only keeps
5 * the list in order.
6 */
7import type { User } from "@g1t/contracts";
8
9import { type PinnableApp, pinsFrom } from "./apps";
10import { identity } from "./services.server";
11
12/**
13 * The pins `user` saved in the workspace `slug`, or null when they never
14 * saved any there or identity could not be asked: the caller falls back
15 * to the cookie (lib/apps.ts `pinsToShow`).
16 */
17export async function savedPins(user: User, slug: string): Promise<PinnableApp[] | null> {
18 try {
19 const stored = await identity.dockPins(user, slug);
20 return stored ? pinsFrom(stored) : null;
21 } catch (error) {
22 console.error("dock: pins could not be read", error);
23 return null;
24 }
25}
26
27/** Saves `pins` as `user`'s in `slug`, in their order; the pins as kept, or null when they could not be saved. */
28export async function savePins(user: User, slug: string, pins: PinnableApp[]): Promise<PinnableApp[] | null> {
29 try {
30 const result = await identity.setDockPins(user, slug, pins);
31 return result.ok ? pinsFrom(result.value) : null;
32 } catch (error) {
33 console.error("dock: pins could not be saved", error);
34 return null;
35 }
36}