Tell every card of a proposal when one of them is decided
A bot's message can name the same card more than once, and each chip kept its own copy of the view, so confirming one left the others saying "Waiting for you" until a reload. primed views now reach the chips already showing them, for proposals, hook proposals, questions and secret requests. Bump to 0.25.1.
This commit is contained in:
@@ -95,7 +95,7 @@ Enables SQLite foreign keys (`enableForeignKeys`), `bunextInit()`, `ensureDocker
|
||||
- **Conversation loading:** pages render everything server-side (`grabConversationProps`) **except the history**, which the client loads (`api/admin/bots/conversation-history`, merged with what's already shown, refetched on bfcache restore) and pages older messages on scroll. Rail lists go through `railBots`/`railWorkspaces` (no prompts/memory, previews cut). Every return to the page (window focus, a hidden tab visible, back online: `use-refocus`, `AppData.RefocusGapMs`) reads the crew again (`use-live-crew-refresh` -> `api/admin/bots/live-crew` -> `cobble:live-crew-refreshed`, taken by `useLiveBots`/`useLiveWorkspaces`) and the session's latest messages plus its bot's face, task and the step its reply is on (`session-messages`, `use-reply-catch-up`; the history's own `step` seeds that row on load, `use-reply-progress`, and a row only ever moves forward in `bots_queue_updates` ids), and the page polls the same while a reply is due (read with the live face, never the page's): pushes missed while the phone slept left threads thinking and faces stale until a reload. On a phone, pulling the thread up past its bottom lifts the newest message off the edge, opening just enough room for a lone refresh icon (a ghost button, no label; no deeper, however far the drag goes), and letting go only reloads once that full room has been held for half a second, which lights the icon (`AppData.PullToRefreshHoldMs`: an exhausted thread reaches the limit by accident too easily) and then turns it into its spinner for at least a second (`AppData.PullToRefreshMinLoadingMs`) while the conversation and the rail are read again (`use-pull-to-refresh` writes that room straight onto the content as the finger moves, never through a render, and owns the gesture until release; the gesture is a plain state machine in `(utils)/pull-to-refresh-gesture.ts`, its steps tested without a browser, which takes the pull's anchor the moment the thread reaches its end, so one swipe that runs out of conversation hands over instead of stopping dead, and reads the end with `AppData.PullToRefreshEndSlackPx` of slack through `atThreadEnd`, since a phone's fractional device pixel ratio leaves the content a hair short and demanding an exact zero made the whole gesture do nothing; `PullToRefreshIndicator`; dragged back down before the release, the icon hides at the travel that showed it).
|
||||
- **Sending:** `api/admin/bots/send-message.ts` -> `enqueueBotReply` -> `wakeBotsQueue`. **Never import `src/bots-queue/index.ts` from a page or API route** (pulls the bunext runtime into page bundles). Optimistic bubble in `pending_messages` until the saved message replaces it. A message is capped at the app setting `bot_message_max_chars` (Settings > General, default `AppData.BotMessageMaxChars`, counted on the trimmed markdown, up to `BotMessageMaxCharsMax`), checked by the composer before it sends (the reason shows under the input) and again by the route (`messageTooLongMessage` says how far over it is and to attach the text as a file). Once stored, a message is never cut: it goes into every turn whole.
|
||||
- **Composer:** Tiptap editor reading/writing markdown, drafts in `localStorage`, `@` bots / `#` workspaces written as `[bot:ID]`/`[workspace:ID]`. Enter sends (Mod+Enter in lists/code). **Up/Down walk the user's own earlier messages** (`use-composer-history`, from `composerHistoryTexts` over the thread's user messages, never a crew message): Up recalls the newest from an empty input and older ones from there, Down comes forward again and back to what was being typed, a keystroke takes the input back, an open mention menu or a selection keeps the arrows. A clear button (X, disabled while the input is empty) empties the text without sending, keeping the quote and the picked files. Ordered lists are read back from digit markers only (`composer-ordered-list`): Tiptap also takes `a.`/`i.`, so a recalled "Ok. Do that." came back as item 401 with "Ok." eaten. `@tiptap/react` needs `use-sync-external-store`; the app ships an ESM stand-in in `packages/use-sync-external-store-esm` (file dependency + override; the Dockerfile copies `packages/` before `bun install`).
|
||||
- **Rendering:** markdown via `react-markdown` + `remark-gfm`, raw HTML never rendered, component map in `[bot_id]/(data)/message-markdown-components.tsx`. Inline refs, all linked by `link-computer-refs.ts` and rendered by chips in `(partials)/`: `[bot:ID]`, `[workspace:ID]`, `[computer:ID]`, `[file:ID]` (a saved file), `[folder:<volume>:<owner>:<path>]` (opens `FolderPreviewModal`, the files browser's listing over the chat, files opening their own preview; a modified click or its Open in Files goes to `/admin/files`), `[take-over:ID:mode]`, `[proposal:ID]`, `[hook-proposal:ID]`, `[secret:ID]` (masked env, Reveal/Copy), `[secret-request:ID]` (masked input card), `[question:ID]` (a bot's questions), `[suggestion:ID]` (its suggested next steps, buttons that fill the composer), `[plan:ID]` (a plan, as its card: steps, the one being worked, and the buttons to approve or change them), `[graphic:ID]` (a bot graphic, framed inline), `[task:ID]` (a tracker task, opening `TaskDetailModal`), `[setting:<section>:<field>]` (`SettingRefChip`: the exact Settings > General page and field to change, from `src/dict/general-settings-dict.ts`; every group of that page also has its own page under `/admin/settings/general/<section>`, and its fields are anchors). Parsers in `src/utils/*-ref.ts`. A chip reads its own row through `(utils)/ref-view-loader.ts`, which keeps only what it read: a read that failed or hung is retried (`AppData.BotRefViewRetryDelaysMs`, each after `BotRefViewTimeoutMs`), so a chip pushed with a run shows its steps or card without a reload. Anywhere else that renders bot-written markdown with `MessageMarkdownComponents` (a workspace's context on its dashboard, a task's description and notes through `TaskMarkdown`) runs it through `linkComputerRefs` and provides `CrewBotsContext`/`CrewWorkspacesContext` too. A ref quoted alone in a code span still links; one inside longer code stays literal (`linkComputerRefs` splits out code first). A file chip opens a file from another bot's folder for a user who reaches that folder (`userReachesFileScope`, the same rule as its bytes), so answers another bot passed on keep working.
|
||||
- **Rendering:** markdown via `react-markdown` + `remark-gfm`, raw HTML never rendered, component map in `[bot_id]/(data)/message-markdown-components.tsx`. Inline refs, all linked by `link-computer-refs.ts` and rendered by chips in `(partials)/`: `[bot:ID]`, `[workspace:ID]`, `[computer:ID]`, `[file:ID]` (a saved file), `[folder:<volume>:<owner>:<path>]` (opens `FolderPreviewModal`, the files browser's listing over the chat, files opening their own preview; a modified click or its Open in Files goes to `/admin/files`), `[take-over:ID:mode]`, `[proposal:ID]`, `[hook-proposal:ID]`, `[secret:ID]` (masked env, Reveal/Copy), `[secret-request:ID]` (masked input card), `[question:ID]` (a bot's questions), `[suggestion:ID]` (its suggested next steps, buttons that fill the composer), `[plan:ID]` (a plan, as its card: steps, the one being worked, and the buttons to approve or change them), `[graphic:ID]` (a bot graphic, framed inline), `[task:ID]` (a tracker task, opening `TaskDetailModal`), `[setting:<section>:<field>]` (`SettingRefChip`: the exact Settings > General page and field to change, from `src/dict/general-settings-dict.ts`; every group of that page also has its own page under `/admin/settings/general/<section>`, and its fields are anchors). Parsers in `src/utils/*-ref.ts`. A chip reads its own row through `(utils)/ref-view-loader.ts`, which keeps only what it read: a read that failed or hung is retried (`AppData.BotRefViewRetryDelaysMs`, each after `BotRefViewTimeoutMs`), so a chip pushed with a run shows its steps or card without a reload, and a chip whose card the user just decided (`primeRefView`) tells every other chip naming the same ref, since a thread can carry the same card twice and the others otherwise went on saying "Waiting for you" until a reload (`subscribeRefView`; `useBotPlan` instead re-reads on `server:bot-plan`). Anywhere else that renders bot-written markdown with `MessageMarkdownComponents` (a workspace's context on its dashboard, a task's description and notes through `TaskMarkdown`) runs it through `linkComputerRefs` and provides `CrewBotsContext`/`CrewWorkspacesContext` too. A ref quoted alone in a code span still links; one inside longer code stays literal (`linkComputerRefs` splits out code first). A file chip opens a file from another bot's folder for a user who reaches that folder (`userReachesFileScope`, the same rule as its bytes), so answers another bot passed on keep working.
|
||||
- **Message images:** a bot message shows the images it's about under its text (`MessageImages` in `(partials)/`, on `BotMessageLine` and `CrewMessageLine`): its image attachments plus every image `[file:ID]` it names (`liveFileRefIds`, which keeps the renderer's code rules), deduped when a named file is also attached (`file_id`). Each is a `MessageAttachment` thumbnail opening the shared `FilePreviewModal`; in a thread its gallery is the whole conversation (`sessionImageGallery` + `SessionGalleryContext` from `MessageThread`): every image in the session, bot and user, in message order, deduped by URL, falling back to the message's own images outside a thread. Non-image files and unreachable refs show nothing. Named files resolve through `useBotFile`/`useReferencedFiles` (page props first, then the cached `api/admin/bots/files` read shared with `FileRefChip`). A thumbnail URL serves the original when no smaller copy was made (`mediaServeWritePath`), since bot files keep no thumbnail.
|
||||
- **Task chips:** which tracker tasks a bot message is about is the app's record, not the bot's word: a run's task tools report each task they touch (`onTask`: `list_tasks` with `task_id`, `create_task`, `update_task`, `delete_task`, `delegate_task`'s hand-over), plus a handed-over job's `tracker_task_id`, into `bot_messages.task_ids` (also on its failure notice and its report relayed to the requester). The thread shows them under the message (`MessageTaskChips`) with title and status, read per viewer and only for tasks they reach (`grabMessagesTasks`; pushes carry them through `withMessageTasks`).
|
||||
- **File preview:** every file link (chips, attachments, files modal, task files, `/admin/files`) is a `FilePreviewLink`: a plain click opens `FilePreviewModal` (its header shows the size and the file's full path on the data volume, `full_path`, e.g. `bots/3/reports/q3.md`, absolute when outside it; every opener passes it; markdown rendered with the message elements, CSV/TSV as a table via `parseCsv`, images in `ImageViewer` (zoom buttons and keys, Ctrl/Cmd+wheel or pinch at the pointer, Fit, Fit width (a full-page screenshot opens that way and scrolls down), Actual size, double click, drag to pan; sized by the `width` attribute and centred with auto margins, never flex centring, which cuts off a tall picture's top), PDF/audio/video in place, HTML in a frame with `sandbox=""` (plus the media server's `sandbox` CSP), other text as code, the kind from `filePreviewKind`; Download and Open in a new tab), a modified click still opens a tab. Text is read up to `AppData.FilePreviewMaxTextBytes`. Never render a file's HTML on the app's origin or with scripts. Opened from a list (a folder, the files modal, a conversation's images), an image gets that list's images as its `gallery` (`imagePreviewGallery`): Previous/Next (side arrows at the far middle left/right, the header's stepper, and the arrow keys) step through them in the same modal, neighbours preloaded. Escape closes only the top modal of a stack (`useTopModalEscape`; twui closes every open one). The message elements and the preview import each other (through the file chips), so the preview merges `MessageMarkdownComponents` when it renders, never at module load.
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cobble",
|
||||
"version": "0.25.0",
|
||||
"version": "0.25.1",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import type { BotQuestionView } from "@/src/types";
|
||||
import loadRefView, { primeRefView } from "../(utils)/ref-view-loader";
|
||||
import loadRefView, { primeRefView, subscribeRefView } from "../(utils)/ref-view-loader";
|
||||
|
||||
type Params = {
|
||||
question_id: number;
|
||||
@@ -11,7 +11,8 @@ type Params = {
|
||||
* when the chip renders, so it shows whether they're still waiting. Only
|
||||
* the user they were asked of can read them; anyone else gets null. A
|
||||
* read that failed or hung is tried again (`loadRefView`) instead of
|
||||
* leaving the card unopenable until the page is reloaded.
|
||||
* leaving the card unopenable until the page is reloaded, and answering
|
||||
* one card tells the thread's other cards of the same question.
|
||||
*/
|
||||
export default function useBotQuestion({ question_id }: Params) {
|
||||
const [view, setViewState] = useState<BotQuestionView | null>(null);
|
||||
@@ -19,11 +20,21 @@ export default function useBotQuestion({ question_id }: Params) {
|
||||
|
||||
useEffect(() => {
|
||||
let live = true;
|
||||
const key = `question:${question_id}`;
|
||||
|
||||
setLoading(true);
|
||||
|
||||
const unsubscribe = subscribeRefView({
|
||||
key,
|
||||
listener: (next) => {
|
||||
if (!live) return;
|
||||
setViewState(next as BotQuestionView);
|
||||
setLoading(false);
|
||||
},
|
||||
});
|
||||
|
||||
loadRefView<BotQuestionView>({
|
||||
key: `question:${question_id}`,
|
||||
key,
|
||||
url: `/api/admin/bot-questions/get-question?question_id=${question_id}`,
|
||||
}).then((result) => {
|
||||
if (!live) return;
|
||||
@@ -33,6 +44,7 @@ export default function useBotQuestion({ question_id }: Params) {
|
||||
|
||||
return () => {
|
||||
live = false;
|
||||
unsubscribe();
|
||||
};
|
||||
}, [question_id]);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import type { ExtensionProposalView } from "@/src/types";
|
||||
import loadRefView, { primeRefView } from "../(utils)/ref-view-loader";
|
||||
import loadRefView, { primeRefView, subscribeRefView } from "../(utils)/ref-view-loader";
|
||||
|
||||
type Params = {
|
||||
proposal_id: number;
|
||||
@@ -12,7 +12,8 @@ type Params = {
|
||||
* waiting. Only the super admin it was proposed to can read it; anyone
|
||||
* else gets null. A read that failed or hung is tried again
|
||||
* (`loadRefView`), so the card isn't unopenable until the page is
|
||||
* reloaded.
|
||||
* reloaded, and deciding on one card tells the thread's other cards of
|
||||
* the same proposal, so none of them goes on saying "Waiting for you".
|
||||
*/
|
||||
export default function useExtensionProposal({ proposal_id }: Params) {
|
||||
const [view, setViewState] = useState<ExtensionProposalView | null>(null);
|
||||
@@ -20,11 +21,21 @@ export default function useExtensionProposal({ proposal_id }: Params) {
|
||||
|
||||
useEffect(() => {
|
||||
let live = true;
|
||||
const key = `extension-proposal:${proposal_id}`;
|
||||
|
||||
setLoading(true);
|
||||
|
||||
const unsubscribe = subscribeRefView({
|
||||
key,
|
||||
listener: (next) => {
|
||||
if (!live) return;
|
||||
setViewState(next as ExtensionProposalView);
|
||||
setLoading(false);
|
||||
},
|
||||
});
|
||||
|
||||
loadRefView<ExtensionProposalView>({
|
||||
key: `extension-proposal:${proposal_id}`,
|
||||
key,
|
||||
url: `/api/admin/extension-proposals/get-proposal?proposal_id=${proposal_id}`,
|
||||
}).then((result) => {
|
||||
if (!live) return;
|
||||
@@ -34,6 +45,7 @@ export default function useExtensionProposal({ proposal_id }: Params) {
|
||||
|
||||
return () => {
|
||||
live = false;
|
||||
unsubscribe();
|
||||
};
|
||||
}, [proposal_id]);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import type { HookProposalView } from "@/src/types";
|
||||
import loadRefView, { primeRefView } from "../(utils)/ref-view-loader";
|
||||
import loadRefView, { primeRefView, subscribeRefView } from "../(utils)/ref-view-loader";
|
||||
|
||||
type Params = {
|
||||
proposal_id: number;
|
||||
@@ -11,7 +11,8 @@ type Params = {
|
||||
* card: read when the chip renders, so it shows whether it's still
|
||||
* waiting. Only the user it was proposed to can read it; anyone else gets
|
||||
* null. A read that failed or hung is tried again (`loadRefView`), so the
|
||||
* card isn't unopenable until the page is reloaded.
|
||||
* card isn't unopenable until the page is reloaded, and deciding on one
|
||||
* card tells the thread's other cards of the same proposal.
|
||||
*/
|
||||
export default function useHookProposal({ proposal_id }: Params) {
|
||||
const [view, setViewState] = useState<HookProposalView | null>(null);
|
||||
@@ -19,11 +20,21 @@ export default function useHookProposal({ proposal_id }: Params) {
|
||||
|
||||
useEffect(() => {
|
||||
let live = true;
|
||||
const key = `hook-proposal:${proposal_id}`;
|
||||
|
||||
setLoading(true);
|
||||
|
||||
const unsubscribe = subscribeRefView({
|
||||
key,
|
||||
listener: (next) => {
|
||||
if (!live) return;
|
||||
setViewState(next as HookProposalView);
|
||||
setLoading(false);
|
||||
},
|
||||
});
|
||||
|
||||
loadRefView<HookProposalView>({
|
||||
key: `hook-proposal:${proposal_id}`,
|
||||
key,
|
||||
url: `/api/admin/hook-proposals/get-proposal?proposal_id=${proposal_id}`,
|
||||
}).then((result) => {
|
||||
if (!live) return;
|
||||
@@ -33,6 +44,7 @@ export default function useHookProposal({ proposal_id }: Params) {
|
||||
|
||||
return () => {
|
||||
live = false;
|
||||
unsubscribe();
|
||||
};
|
||||
}, [proposal_id]);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import type { SecretRequestView } from "@/src/types";
|
||||
import loadRefView, { primeRefView } from "../(utils)/ref-view-loader";
|
||||
import loadRefView, { primeRefView, subscribeRefView } from "../(utils)/ref-view-loader";
|
||||
|
||||
type Params = {
|
||||
request_id: number;
|
||||
@@ -11,7 +11,8 @@ type Params = {
|
||||
* read when the chip renders, so it shows whether it's still waiting.
|
||||
* Only the user it was asked of can read it; anyone else gets null. A
|
||||
* read that failed or hung is tried again (`loadRefView`), so the card
|
||||
* isn't unopenable until the page is reloaded.
|
||||
* isn't unopenable until the page is reloaded, and answering one card
|
||||
* tells the thread's other cards of the same request.
|
||||
*/
|
||||
export default function useSecretRequest({ request_id }: Params) {
|
||||
const [view, setViewState] = useState<SecretRequestView | null>(null);
|
||||
@@ -19,11 +20,21 @@ export default function useSecretRequest({ request_id }: Params) {
|
||||
|
||||
useEffect(() => {
|
||||
let live = true;
|
||||
const key = `secret-request:${request_id}`;
|
||||
|
||||
setLoading(true);
|
||||
|
||||
const unsubscribe = subscribeRefView({
|
||||
key,
|
||||
listener: (next) => {
|
||||
if (!live) return;
|
||||
setViewState(next as SecretRequestView);
|
||||
setLoading(false);
|
||||
},
|
||||
});
|
||||
|
||||
loadRefView<SecretRequestView>({
|
||||
key: `secret-request:${request_id}`,
|
||||
key,
|
||||
url: `/api/admin/secret-requests/get-request?request_id=${request_id}`,
|
||||
}).then((result) => {
|
||||
if (!live) return;
|
||||
@@ -33,6 +44,7 @@ export default function useSecretRequest({ request_id }: Params) {
|
||||
|
||||
return () => {
|
||||
live = false;
|
||||
unsubscribe();
|
||||
};
|
||||
}, [request_id]);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import loadRefView, { primeRefView } from "./ref-view-loader";
|
||||
import loadRefView, { primeRefView, subscribeRefView } from "./ref-view-loader";
|
||||
|
||||
/**
|
||||
* A read standing in for the app's: one answer per call, in order, and a
|
||||
@@ -100,4 +100,65 @@ describe("loadRefView", () => {
|
||||
|
||||
expect(asked).toEqual(["/get-question?question_id=15", "/get-suggestion?suggestion_id=15"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("subscribeRefView", () => {
|
||||
test("tells every chip naming a view when one of them changes it", () => {
|
||||
const first: unknown[] = [];
|
||||
const second: unknown[] = [];
|
||||
|
||||
const stopFirst = subscribeRefView({ key: "test:shared-chip", listener: (view) => first.push(view) });
|
||||
const stopSecond = subscribeRefView({ key: "test:shared-chip", listener: (view) => second.push(view) });
|
||||
|
||||
primeRefView({ key: "test:shared-chip", view: { id: 21, status: "confirmed" } });
|
||||
|
||||
expect(first).toEqual([{ id: 21, status: "confirmed" }]);
|
||||
expect(second).toEqual([{ id: 21, status: "confirmed" }]);
|
||||
|
||||
stopFirst();
|
||||
stopSecond();
|
||||
});
|
||||
|
||||
test("tells only the chips naming that view", () => {
|
||||
const mine: unknown[] = [];
|
||||
const other: unknown[] = [];
|
||||
|
||||
const stopMine = subscribeRefView({ key: "test:mine", listener: (view) => mine.push(view) });
|
||||
const stopOther = subscribeRefView({ key: "test:other", listener: (view) => other.push(view) });
|
||||
|
||||
primeRefView({ key: "test:mine", view: { id: 23 } });
|
||||
|
||||
expect(mine).toEqual([{ id: 23 }]);
|
||||
expect(other).toEqual([]);
|
||||
|
||||
stopMine();
|
||||
stopOther();
|
||||
});
|
||||
|
||||
test("stops following once the chip is gone", () => {
|
||||
const seen: unknown[] = [];
|
||||
|
||||
const stop = subscribeRefView({ key: "test:unsubscribed", listener: (view) => seen.push(view) });
|
||||
|
||||
stop();
|
||||
primeRefView({ key: "test:unsubscribed", view: { id: 25 } });
|
||||
|
||||
expect(seen).toEqual([]);
|
||||
});
|
||||
|
||||
test("tells the chips already showing it when a read lands", async () => {
|
||||
const seen: unknown[] = [];
|
||||
|
||||
const stop = subscribeRefView({ key: "test:read-lands", listener: (view) => seen.push(view) });
|
||||
|
||||
await loadRefView({
|
||||
key: "test:read-lands",
|
||||
url: "/get?id=27",
|
||||
readOnce: async () => ({ id: 27 }),
|
||||
retryDelaysMs: [],
|
||||
});
|
||||
|
||||
expect(seen).toEqual([{ id: 27 }]);
|
||||
|
||||
stop();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,12 +31,48 @@ type Params = {
|
||||
const known = new Map<string, unknown>();
|
||||
const inFlight = new Map<string, Promise<unknown | null>>();
|
||||
|
||||
type RefViewListener = (view: RefView) => void;
|
||||
|
||||
/**
|
||||
* Who is showing one view on the page now, by key. A bot's message can
|
||||
* carry the same card twice (the one that made it, and a later one saying
|
||||
* it's still waiting), and each chip keeps its own state, so without this
|
||||
* the other card went on saying "Waiting for you" after the user decided
|
||||
* on it, until a reload.
|
||||
*/
|
||||
const listeners = new Map<string, Set<RefViewListener>>();
|
||||
|
||||
/**
|
||||
* Follows one view, so a change another chip made reaches this one:
|
||||
* returns the unsubscribe. Called before the read, since a card decided
|
||||
* while it loads must not be overwritten by the answer already in flight.
|
||||
*/
|
||||
export function subscribeRefView({ key, listener }: { key: string; listener: RefViewListener }) {
|
||||
const listening = listeners.get(key) || new Set<RefViewListener>();
|
||||
|
||||
listening.add(listener);
|
||||
listeners.set(key, listening);
|
||||
|
||||
return () => {
|
||||
listening.delete(listener);
|
||||
|
||||
if (!listening.size) listeners.delete(key);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps a view the page already has (a question answered in its card, its
|
||||
* chip now saying so) without asking the app for it again.
|
||||
* chip now saying so) without asking the app for it again, and tells every
|
||||
* chip naming it, so they all say so.
|
||||
*/
|
||||
export function primeRefView({ key, view }: { key: string; view: unknown }) {
|
||||
remember({ key, view });
|
||||
}
|
||||
|
||||
function remember({ key, view }: { key: string; view: unknown }) {
|
||||
known.set(key, view);
|
||||
|
||||
for (const listener of listeners.get(key) || []) listener(view as RefView);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +100,7 @@ export default async function loadRefView<T extends RefView>({
|
||||
.then((view) => {
|
||||
inFlight.delete(key);
|
||||
|
||||
if (view) known.set(key, view);
|
||||
if (view) remember({ key, view });
|
||||
|
||||
return view as T | null;
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user