Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Template card reads the profile through the store selector

milind-soni103482f4305e
diff --git a/src/components/TemplateCard.test.ts b/src/components/TemplateCard.test.ts
index 78c7612b0c..4967010a9c 100644
--- a/src/components/TemplateCard.test.ts
+++ b/src/components/TemplateCard.test.ts
@@ -15,6 +15,7 @@ vi.mock("@/state/store", async () => {
return { StoreContext: createContext(null), useStore: () => ({ state: place.state, dispatch }), api: (path: string, init?: RequestInit) => api(path, init) };
});
vi.mock("@/lib/use-owner-or-admin", () => ({ useOwnerOrAdmin: () => place.admin }));
+vi.mock("@/state/store-select", () => ({ useStoreSelector: <T,>(select: (state: never) => T) => select(place.state as never) }));
vi.mock("@/lib/session", () => ({
readSessionState: async () => ({ kind: "loopback" }),
profileForSession: (profile: { name?: string } | undefined, session: unknown) => (session && place.own ? profile : undefined),
diff --git a/src/components/TemplateCard.tsx b/src/components/TemplateCard.tsx
index 51536e4eb3..69c7bdc7fa 100644
--- a/src/components/TemplateCard.tsx
+++ b/src/components/TemplateCard.tsx
@@ -16,6 +16,7 @@ import { profileForSession, readSessionState, type SessionState } from "@/lib/se
import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
import { useModalDialog } from "@/hooks/use-modal-dialog";
import { useStore, type Message } from "@/state/store";
+import { useStoreSelector } from "@/state/store-select";
import { ASK_CHIP, ASK_CHIP_IDLE, ASK_PRIMARY_BUTTON } from "./AskCard";
import { BotAvatar } from "./Avatar";
import { SidebarPopoverMenu, type SidebarMenuItem } from "./SidebarPopoverMenu";
@@ -85,14 +86,14 @@ export function TemplateCardBody({ card }: { card: TemplateCard }) {
/** The profile's name when the profile is this person's own (not a shared workspace's owner's). */
function useOwnProfileName(): string {
- const { state } = useStore();
+ const profile = useStoreSelector((state) => state.config?.profile);
const [session, setSession] = useState<SessionState | null>(null);
useEffect(() => {
let live = true;
void readSessionState().then((next) => { if (live) setSession(next); });
return () => { live = false; };
}, []);
- return profileForSession(state.config?.profile, session)?.name?.trim() ?? "";
+ return profileForSession(profile, session)?.name?.trim() ?? "";
}
/** What the card's buttons do. The card shown is the latest the server answered, until the message brings a newer one. */