Skip to content

Commit 43da9e5

Browse files
committed
Fuse the openmuse skin's review fixes
2 parents 7817424 + bf4b831 commit 43da9e5

16 files changed

Lines changed: 428 additions & 1961 deletions

‎app/src/skins/openmuse/approvals.tsx‎

Lines changed: 0 additions & 182 deletions
This file was deleted.

‎app/src/skins/openmuse/bots-sheet.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { Divider, ErrorNotice, LinkRow, MuseSheet, museText } from "./ui";
2727
* one place the difference shows, and it stays a sheet behind the name rather than a fixture.
2828
*/
2929
export function BotsSheet({ onClose }: { onClose: () => void }) {
30-
const { bot: centre } = useMuse();
30+
const { bot: centre, userId } = useMuse();
3131
const agents = useQuery(agentListQueryOptions());
3232
const attention = useQuery(botAttentionQueryOptions());
3333
const channels = useInfiniteQuery(channelListQueryOptions());
@@ -37,7 +37,7 @@ export function BotsSheet({ onClose }: { onClose: () => void }) {
3737
const navigate = useNavigate();
3838

3939
const choose = (agentId: string) => {
40-
chooseBot(agentId);
40+
if (userId) chooseBot(userId, agentId);
4141
onClose();
4242
// On Chat, choosing a Bot means talking to it; elsewhere the tab stays and follows the Bot.
4343
if (tabFor(pathname) !== "chat") return;
Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,57 @@
11
import { useSyncExternalStore } from "react";
22

33
/*
4-
* Which Bot the person put at the centre of OpenMuse. A per-browser preference, like the skin itself:
5-
* it lives in localStorage and nowhere else, so choosing a Bot here changes nothing on the server.
4+
* Which Bot each person put at the centre of the frame. Kept in this browser, and kept per signed-in
5+
* person: the key carries their user id, so the next person on a shared machine starts from OpenBot's
6+
* own default Bot rather than the last person's choice. Choosing a Bot changes nothing on the server.
67
*/
7-
export const CHOSEN_BOT_KEY = "openmuse-bot";
8-
9-
function read(): string | null {
10-
try {
11-
return window.localStorage.getItem(CHOSEN_BOT_KEY);
12-
} catch {
13-
return null;
14-
}
8+
export function chosenBotKey(userId: string): string {
9+
return `openmuse-bot:${userId}`;
1510
}
1611

17-
let current: string | null = typeof window === "undefined" ? null : read();
12+
const choices = new Map<string, string | null>();
1813
const listeners = new Set<() => void>();
1914

20-
export function chooseBot(id: string) {
21-
if (current === id) return;
22-
current = id;
23-
// localStorage throws in some privacy modes; the choice still holds for this visit.
15+
function read(userId: string): string | null {
16+
if (!choices.has(userId)) {
17+
let stored: string | null = null;
18+
// localStorage throws in some privacy modes; the frame then starts from the default Bot.
19+
try {
20+
stored = window.localStorage.getItem(chosenBotKey(userId));
21+
} catch {}
22+
choices.set(userId, stored);
23+
}
24+
return choices.get(userId) ?? null;
25+
}
26+
27+
export function chooseBot(userId: string, agentId: string) {
28+
if (read(userId) === agentId) return;
29+
choices.set(userId, agentId);
30+
// The choice still holds for this visit when the browser refuses to store it.
2431
try {
25-
window.localStorage.setItem(CHOSEN_BOT_KEY, id);
32+
window.localStorage.setItem(chosenBotKey(userId), agentId);
2633
} catch {}
2734
for (const listener of listeners) listener();
2835
}
2936

37+
/** Forgets every choice read into memory, as a new page load would. */
38+
export function forgetChosenBots() {
39+
choices.clear();
40+
for (const listener of listeners) listener();
41+
}
42+
3043
function subscribe(listener: () => void) {
3144
listeners.add(listener);
3245
return () => {
3346
listeners.delete(listener);
3447
};
3548
}
3649

37-
export function useChosenBotId(): string | null {
50+
/** The Bot this person chose, or null before they choose one or while nobody is known yet. */
51+
export function useChosenBotId(userId: string | undefined): string | null {
3852
return useSyncExternalStore(
3953
subscribe,
40-
() => current,
54+
() => (userId ? read(userId) : null),
4155
() => null,
4256
);
4357
}

‎app/src/skins/openmuse/context.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export type MuseSheetKind = "menu" | "notifications" | "bots";
66
export type MuseContextValue = {
77
/** The Bot at the centre of the frame, or undefined while the roster loads or when there is none. */
88
bot: AgentProfile | undefined;
9+
/** The signed-in person, whose choice of centre Bot this browser remembers. */
10+
userId: string | undefined;
911
openSheet: (sheet: MuseSheetKind) => void;
1012
};
1113

0 commit comments

Comments
 (0)