An overview
The page / opens on: the week's figures, its visits as bars, the pinned notes and what is due
This recipe draws OverviewGrid arrangement="tiles-wide-pair"; the others (agent/layout-chooser.md) take the same slots. Your page fits another? Change the one prop:
card-grid(metrics: many; Meadow draws it astiles-wide-pair):OverviewGridStatsthe headline numbers, across the row;OverviewGridWideone combined chart, across the row;childrenthe other chart and list cards, an even grid.chart-over-table(metrics: report; Meadow draws it astiles-wide-pair):OverviewGridWidethe one chart;childrenits filters and its table.home-column(metrics: start):childrena greeting, quick actions, a feed.
Copy the file below whole (src/screens/overview.tsx) beside frame.tsx (docs/screen-frame.md) and swap the sample rows for your data; keep the parts and their props. Meadow's overview is written as its collection page, never a dashboard of tiles and cards: one quiet reading column (PageBody wide, 716 px, centred) on the page's one fill, its heading in the display type, then OverviewGrid's parts, each a section 40 px apart. First the figures as a band (each a StatLabel over its Stat: the number in the title's type, after it a status Badge for the change or a grey word for what it counts), nothing round them. Then sections, each a ListGroup whose section bar names it in the muted grey, over its rows on the column's edge: the visits a bar row a week, in the week's order, on the property band (Properties variant="band": the week in the label column, its Progress and its count in one fixed end column, the busiest week a full bar); then side by side (one over the other on a phone) the pinned notes as linked rows, the day each changed first (Item ghost), and what is due as to-do rows (Item todo, its round box a Checkbox done, the day as a plain Badge). The notes are the app's, read from the store (docs/screen-app.md), so a note pinned on the list counts here and its row links to its page (docs/screen-record.md); a box ticked counts in its figure at once. Every figure is counted from the rows, never typed. A section with no rows shows a bare Empty in their place. No Card, StatTile or chart round any part: the grid's rhythm and the column are the page's. Light, dark, phone and desktop are the parts' own: add no class for them.
Show the code191 lines
// src/screens/overview.tsx: the overview, the page `/` opens on
import { type ReactNode, useState } from 'react';
import { AppFramePanel } from '@/components/goop/patterns/app-frame';
import {
OverviewGrid,
OverviewGridPair,
OverviewGridStats,
OverviewGridWide,
} from '@/components/goop/patterns/overview-grid';
import { PageBody } from '@/components/goop/patterns/page-body';
import { Badge } from '@/components/ui/goop/badge';
import { Checkbox } from '@/components/ui/goop/checkbox';
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from '@/components/ui/goop/empty';
import { Item, ItemContent, ItemControl, ItemEnd, ItemTitle } from '@/components/ui/goop/item';
import { ListGroup, ListGroupContent, ListGroupHeader, ListGroupTitle } from '@/components/ui/goop/list-group';
import {
PageHeader,
PageHeaderContent,
PageHeaderDescription,
PageHeaderTitle,
} from '@/components/ui/goop/page-header';
import { Progress } from '@/components/ui/goop/progress';
import { Properties, PropertyRow } from '@/components/ui/goop/properties';
import { Stat, StatLabel, StatValue } from '@/components/ui/goop/stat';
import { ScreenFrame, ScreenTopBar } from './frame';
import { hrefOf } from './router';
import { useStore } from './store';
// ---- the sample data: swap it for yours
const WEEKS = [
{ week: '2 Nov', visits: 9 },
{ week: '9 Nov', visits: 12 },
{ week: '16 Nov', visits: 10 },
{ week: '23 Nov', visits: 14 },
];
const DUE = [
{ id: 'd1', title: 'Order the hazel trays', due: 'Thursday' },
{ id: 'd2', title: 'Send the soil results', due: 'Friday' },
{ id: 'd3', title: 'Book the planting crew', due: 'Friday' },
];
// every figure is counted from the rows above, never typed
const thisWeek = WEEKS[WEEKS.length - 1] ?? { visits: 0 };
const lastWeek = WEEKS[WEEKS.length - 2] ?? thisWeek;
const change = Math.round(((thisWeek.visits - lastWeek.visits) / Math.max(lastWeek.visits, 1)) * 100);
/** The busiest week: a full bar in the visits' rows. */
const most = Math.max(1, ...WEEKS.map((one) => one.visits));
/** A day as the rows say it (`23 Nov`), from `YYYY-MM-DD`. */
const dayOf = (day: string) =>
new Date(`${day}T00:00:00Z`).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', timeZone: 'UTC' });
/** A bar row's value: its track taking what the count leaves, 12 px before the count. */
const BAR_VALUE = 'flex grow items-center gap-3';
/** The count: one fixed end column, so every row's track ends on one line, its words starting right after the track. */
const BAR_COUNT = 'w-20 shrink-0 text-start tabular-nums text-muted-foreground';
/** A section of the page: its muted label (the list group's `section` bar) over its rows. */
function Section({ title, children }: { title: string; children: ReactNode }) {
return (
<ListGroup>
<ListGroupHeader variant="section">
<ListGroupTitle asChild>
<h2>{title}</h2>
</ListGroupTitle>
</ListGroupHeader>
{children}
</ListGroup>
);
}
export default function OverviewScreen() {
const { notes } = useStore();
const [done, setDone] = useState<readonly string[]>([]);
const pinned = notes.filter((note) => note.pinned);
const left = DUE.filter((task) => !done.includes(task.id)).length;
return (
<ScreenFrame current="/">
<AppFramePanel header={<ScreenTopBar title="Home" />}>
<PageBody variant="wide">
<PageHeader variant="display">
<PageHeaderContent>
<PageHeaderTitle asChild>
<h1>This week</h1>
</PageHeaderTitle>
<PageHeaderDescription>Site visits, your notes and what is due, to today.</PageHeaderDescription>
</PageHeaderContent>
</PageHeader>
<OverviewGrid arrangement="tiles-wide-pair">
<OverviewGridStats aria-label="This week at a glance">
<div>
<StatLabel>Site visits</StatLabel>
<Stat>
<StatValue>{thisWeek.visits}</StatValue>
<Badge variant={change < 0 ? 'destructive' : 'success'} stateLabel={change < 0 ? 'Down' : 'Up'}>
{`${change < 0 ? '−' : '+'}${Math.abs(change)}%`}
</Badge>
</Stat>
</div>
<div>
<StatLabel>Notes</StatLabel>
<Stat>
<StatValue>{notes.length}</StatValue>
<StatLabel>{`${pinned.length} pinned`}</StatLabel>
</Stat>
</div>
<div>
<StatLabel>Due this week</StatLabel>
<Stat>
<StatValue>{left}</StatValue>
<StatLabel>{`${DUE.length - left} done`}</StatLabel>
</Stat>
</div>
</OverviewGridStats>
<OverviewGridWide>
<Section title="Site visits">
<Properties variant="band" aria-label="Site visits each week">
{WEEKS.map((one) => (
<PropertyRow key={one.week} label={one.week}>
<span className={BAR_VALUE}>
<Progress
value={one.visits}
max={most}
aria-label={`Week of ${one.week}`}
aria-valuetext={`${one.visits} visits`}
/>
<span className={BAR_COUNT}>{one.visits}</span>
</span>
</PropertyRow>
))}
</Properties>
</Section>
</OverviewGridWide>
<OverviewGridPair>
<Section title="Pinned notes">
{pinned.length === 0 ? (
<Empty>
<EmptyHeader>
<EmptyTitle>No note pinned</EmptyTitle>
<EmptyDescription>Pin one from its menu on the notes page.</EmptyDescription>
</EmptyHeader>
</Empty>
) : (
<ListGroupContent role="list" aria-label="Pinned notes">
{pinned.map((note) => (
<div key={note.id} role="listitem">
<Item variant="ghost" asChild>
<a href={hrefOf(`/notes/${note.id}`)}>
<ItemEnd>
<time dateTime={note.updated}>{dayOf(note.updated)}</time>
</ItemEnd>
<ItemContent>
<ItemTitle>{note.title}</ItemTitle>
</ItemContent>
</a>
</Item>
</div>
))}
</ListGroupContent>
)}
</Section>
<Section title="Due this week">
<ListGroupContent role="list" aria-label="Due this week">
{DUE.map((task) => (
<Item key={task.id} variant="todo" role="listitem">
<ItemControl reveal={false}>
<Checkbox
variant="done"
aria-label={task.title}
checked={done.includes(task.id)}
onCheckedChange={(next) =>
setDone((now) => (next ? [...now, task.id] : now.filter((id) => id !== task.id)))
}
/>
</ItemControl>
<ItemContent>
<ItemTitle>{task.title}</ItemTitle>
</ItemContent>
<ItemEnd>
<Badge variant="plain">{task.due}</Badge>
</ItemEnd>
</Item>
))}
</ListGroupContent>
</Section>
</OverviewGridPair>
</OverviewGrid>
</PageBody>
</AppFramePanel>
</ScreenFrame>
);
}