---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# The app

Its screens by route, one store they share, the toasts, light and dark

Start a new app here: it makes the screen recipes one app. `node goop/agent/start.mjs <screen>…` writes the files below, the frame and the screens you name (README, "Start here"). By hand: copy the three files below whole, at the paths their first lines name, beside the frame recipe's two (`src/screens/frame.tsx` and the app's router, `src/screens/router.ts`, `docs/screen-frame.md`); then write each screen from its recipe in `src/screens/` (`overview.tsx`, `inbox.tsx`, `issues.tsx`, `issue.tsx`, `board.tsx`, `schedule.tsx`, `visits.tsx`, `chat.tsx`, `settings.tsx`) and keep only the routes your app has: a screen your app lacks is its one import and its route line in `App.tsx`. The app opens on its first screen. A sign-in is a screen of its own (`docs/screen-account.md`): with it, that recipe's three lines go into `App.tsx` (its import, the `/profile` route and `<SignedIn>` round the screens), and the app opens signed out; without it, `App.tsx` stays as it is. A record open beside a list stays in `?peek=<id>` as it is (`useRecordPeek()`; your router's own state: `useRecordPeek({ adapter })`). `App.tsx` holds the store round every screen, the one `<Toaster />` and the scroll to the top on a new route (on a phone the page scrolls). The sample rows live in `sample.ts`, read through the store: in a screen, swap the recipe's own sample constant for `const { issues, updateIssue } = useStore();` (from `./store`), so a status picked in the list shows on the record's page. Swap the rows for your data, or your API's first answer, in that one file.

To open in the kept light or dark mode with no flash, put this in `index.html`'s `<head>`; the frame's top bar holds the switch (`ColorModeToggle`), which keeps the choice under the same key:

```html
<script>
  try { var colorMode = localStorage.getItem('theme'); } catch (e) {}
  document.documentElement.classList.toggle('dark', colorMode === 'dark' ||
    (colorMode !== 'light' && matchMedia('(prefers-color-scheme: dark)').matches));
</script>
```

```tsx
// src/screens/sample.ts: the app's sample rows, in one place: swap them for your data
// ---- the sample data: swap it for yours
export const PEOPLE = ['Teodora Valk', 'Bilal Rashed', 'Ngozi Ilori', 'Dagny Holm', 'Cormac Foley'] as const;

export type IssueStatus = 'todo' | 'in-progress' | 'in-review' | 'done';

export interface Issue {
  id: string;
  title: string;
  status: IssueStatus;
  priority: 'urgent' | 'high' | 'medium' | 'low';
  assignee: (typeof PEOPLE)[number];
}

export const ISSUES: readonly Issue[] = [
  { id: 'FW-121', title: 'Tags vanish on sync', status: 'in-review', priority: 'urgent', assignee: 'Bilal Rashed' },
  { id: 'FW-117', title: 'Recruit 8 participants', status: 'todo', priority: 'high', assignee: 'Dagny Holm' },
  {
    id: 'FW-112',
    title: 'Consent form for Eastgate Library',
    status: 'todo',
    priority: 'medium',
    assignee: 'Ngozi Ilori',
  },
  { id: 'FW-110', title: 'Help page on tags', status: 'in-progress', priority: 'low', assignee: 'Teodora Valk' },
  {
    id: 'FW-108',
    title: 'Diallo Dental interview notes',
    status: 'done',
    priority: 'medium',
    assignee: 'Cormac Foley',
  },
];
```

```tsx
// src/screens/store.tsx: what every screen shares, held once, so a change on one screen shows on all
import { createContext, type ReactNode, useContext, useMemo, useState } from 'react';
import { type Issue, ISSUES } from './sample';

interface Store {
  /** Every issue, as the screens show it. */
  issues: readonly Issue[];
  /** Changes one issue (a status picked in the list, an assignee on its page): every screen showing it follows. */
  updateIssue: (id: string, change: Partial<Omit<Issue, 'id'>>) => void;
  /** Puts a new issue at the top (a create dialog's result). */
  addIssue: (issue: Issue) => void;
}

const StoreContext = createContext<Store | null>(null);

/** The store for the screens under it: mounted once, in `App.tsx`, round them all. */
export function StoreProvider({ children }: { children: ReactNode }) {
  const [issues, setIssues] = useState(ISSUES);
  const store = useMemo<Store>(
    () => ({
      issues,
      updateIssue: (id, change) =>
        setIssues((now) => now.map((issue) => (issue.id === id ? { ...issue, ...change } : issue))),
      addIssue: (issue) => setIssues((now) => [issue, ...now]),
    }),
    [issues],
  );
  return <StoreContext value={store}>{children}</StoreContext>;
}

/** The store, in any screen: `const { issues, updateIssue } = useStore();`. */
export function useStore(): Store {
  const store = useContext(StoreContext);
  if (!store) throw new Error('useStore() needs <StoreProvider> round the screens, in App.tsx');
  return store;
}
```

```tsx
// src/App.tsx: the app, its screens by route, the store round them and the toasts' one region
import { type ReactNode, useEffect, useRef } from 'react';
import { AppFramePanel } from '@/components/goop/patterns/app-frame';
import { PageBody } from '@/components/goop/patterns/page-body';
import { Button } from '@/components/ui/goop/button';
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle } from '@/components/ui/goop/empty';
import { Toaster } from '@/components/ui/goop/toast';
import BoardScreen from './screens/board';
import ChatScreen from './screens/chat';
import { ScreenFrame, ScreenTopBar } from './screens/frame';
import InboxScreen from './screens/inbox';
import IssueScreen from './screens/issue';
import IssuesScreen from './screens/issues';
import OverviewScreen from './screens/overview';
import { go, useRoute } from './screens/router';
import ScheduleScreen from './screens/schedule';
import SettingsScreen from './screens/settings';
import { StoreProvider } from './screens/store';
import VisitsScreen from './screens/visits';

/** The screen a route shows: one a page of the frame's navigation, and a record's page by its id. */
function screenFor(route: string): ReactNode {
  const at = route.split('/');
  const page = at[1];
  if (page === '') return <OverviewScreen />;
  if (page === 'inbox') return <InboxScreen />;
  // the record's page reads its record by its id from the store once you give it the prop: <IssueScreen id={at[2]} />
  if (page === 'issues' && at[2]) return <IssueScreen key={at[2]} />;
  if (page === 'issues') return <IssuesScreen />;
  // a card's own page (`/board/<id>`) is a record's page you write from docs/screen-record.md
  if (page === 'board') return <BoardScreen />;
  if (page === 'schedule') return <ScheduleScreen />;
  if (page === 'visits') return <VisitsScreen />;
  if (page === 'chat') return <ChatScreen />;
  if (page === 'settings') return <SettingsScreen />;
  return <NotFoundScreen key={page} />;
}

/** A route the app has no screen for: said in the frame, with the way back. */
function NotFoundScreen() {
  return (
    <ScreenFrame>
      <AppFramePanel header={<ScreenTopBar title="Not found" />}>
        <PageBody>
          <Empty>
            <EmptyHeader>
              <EmptyTitle asChild>
                <h1>No page here</h1>
              </EmptyTitle>
              <EmptyDescription>The link may be old, or the page has moved.</EmptyDescription>
            </EmptyHeader>
            <EmptyContent>
              <Button onClick={() => go('/')}>Back to the start</Button>
            </EmptyContent>
          </Empty>
        </PageBody>
      </AppFramePanel>
    </ScreenFrame>
  );
}

export default function App() {
  const route = useRoute();
  // On a phone the document scrolls under the top bar: a new route opens at its top (the first is left where it is).
  const shown = useRef(route);
  useEffect(() => {
    if (shown.current === route) return;
    shown.current = route;
    if (document.scrollingElement) document.scrollingElement.scrollTop = 0;
  }, [route]);
  return (
    <StoreProvider>
      {screenFor(route)}
      <Toaster />
    </StoreProvider>
  );
}
```
