An inbox
Conversations in the list column, the open one beside it, its status and assignee, a reply box
This recipe draws ListDetail arrangement="reading-pane", the one arrangement Meadow draws: the conversations in the frame's 244 px list column, the open one read at length in the frame's second container.
Copy the file below whole (src/screens/inbox.tsx) beside frame.tsx (docs/screen-frame.md) and swap the sample conversations for yours; keep the parts and their props. The list column: its header row (the list's name and the frame's list toggle), the search and the queues (a ToggleGroup strip of pills, each counting what it would show), then a row a conversation (its customer's avatar, its subject), the open one washed; the arrows move between the rows and Escape closes. The open conversation: its subject and customer as the page's heading and line, the bar's Close conversation action, its status and assignee in the property band (a quiet Select and a PersonSelect that change it in place, the queues' counts following), the thread (MessageList: an internal note in its warm box), then the reply box with Reply and Internal note. A reply waits on the customer; a note leaves the status as it was. Nothing open, the page holds a hint. Below 768 px the conversation takes the list's place, the bar's back control returning. Light, dark, phone and desktop are the parts' own: add no class for them.
Show the code318 lines
// src/screens/inbox.tsx: the inbox, a conversation open beside its list, a reply box under its thread
import { useState } from 'react';
import { AppFrameListToggle, AppFramePanel, AppFrameTrigger } from '@/components/goop/patterns/app-frame';
import {
ListDetail,
ListDetailItem,
ListDetailList,
ListDetailPanel,
ListDetailTrigger,
} from '@/components/goop/patterns/list-detail';
import { Avatar } from '@/components/ui/goop/avatar';
import { ChatMessage } from '@/components/ui/goop/chat-message';
import {
Composer,
ComposerActions,
ComposerEditor,
type ComposerMode,
ComposerSubmit,
ComposerToolbar,
} from '@/components/ui/goop/composer';
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from '@/components/ui/goop/empty';
import { MessageList } from '@/components/ui/goop/message-list';
import { PersonSelect } from '@/components/ui/goop/person-select';
import { Properties, PropertyRow } from '@/components/ui/goop/properties';
import { SearchInput } from '@/components/ui/goop/search-input';
import {
Select,
SelectContent,
SelectIcon,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/goop/select';
import { SidebarHeader, SidebarHeaderRow, SidebarTitle } from '@/components/ui/goop/sidebar';
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/goop/toggle-group';
import { TopBarAction } from '@/components/ui/goop/top-bar';
import { ScreenFrame } from './frame';
// ---- the sample data: swap it for yours
type Status = 'open' | 'waiting' | 'closed';
const STATUS_WORDS: Record<Status, string> = { open: 'Open', waiting: 'Waiting on the customer', closed: 'Closed' };
const STATUSES = Object.keys(STATUS_WORDS) as Status[];
const TEAM = [
{ id: 'teodora', name: 'Teodora Valk' },
{ id: 'ngozi', name: 'Ngozi Ilori' },
{ id: 'cormac', name: 'Cormac Foley' },
];
const ME = 'teodora';
interface Message {
id: string;
from: 'customer' | 'you';
text: string;
time: string;
note?: boolean;
}
interface Conversation {
id: string;
subject: string;
customer: string;
email: string;
status: Status;
/** A TEAM id, or '' for nobody. */
assignee: string;
messages: Message[];
}
const CONVERSATIONS: Conversation[] = [
{
id: 'c-2041',
subject: 'Seed order arrived short',
customer: 'Rhys Pugh',
email: 'rhys.pugh@example.org',
status: 'open',
assignee: ME,
messages: [
{ id: 'm1', from: 'customer', text: 'Two trays of hazel are missing from Friday’s order.', time: '09:12' },
{ id: 'm2', from: 'you', text: 'Sorry about that. I’ll check the packing list now.', time: '09:20' },
{ id: 'm3', from: 'you', text: 'The nursery split it in two: the rest ships Monday.', time: '09:24', note: true },
],
},
{
id: 'c-2040',
subject: 'Moving our planting day',
customer: 'Lupe Ortega',
email: 'lupe@example.org',
status: 'waiting',
assignee: '',
messages: [{ id: 'm1', from: 'customer', text: 'Can the crew come on Sunday instead?', time: '08:47' }],
},
{
id: 'c-2038',
subject: 'Last year’s soil results',
customer: 'Amara Diallo',
email: 'amara@example.org',
status: 'closed',
assignee: 'ngozi',
messages: [
{ id: 'm1', from: 'customer', text: 'Could we have last year’s soil results again?', time: 'Mon 10:02' },
{ id: 'm2', from: 'you', text: 'Here they are, one page a bed.', time: 'Mon 11:15' },
],
},
];
const QUEUES = [
{ id: 'all', words: 'All' },
{ id: 'mine', words: 'Yours' },
{ id: 'unassigned', words: 'Unassigned' },
] as const;
type Queue = (typeof QUEUES)[number]['id'];
const inQueue = (queue: Queue, one: Conversation) => queue === 'all' || one.assignee === (queue === 'mine' ? ME : '');
const MODES: ComposerMode[] = [
{ value: 'reply', label: 'Reply', placeholder: 'Write to the customer…' },
{ value: 'note', label: 'Internal note', variant: 'note', placeholder: 'Only your team sees this…' },
];
export default function InboxScreen() {
const [conversations, setConversations] = useState(CONVERSATIONS);
const [queue, setQueue] = useState<Queue>('all');
const [query, setQuery] = useState('');
const [openId, setOpenId] = useState<string | null>(null);
const words = query.trim().toLowerCase();
const found = conversations.filter((one) => `${one.customer} ${one.subject}`.toLowerCase().includes(words));
const shown = found.filter((one) => inQueue(queue, one));
const open = conversations.find((one) => one.id === openId);
const change = (id: string, next: Partial<Conversation>) =>
setConversations((all) => all.map((one) => (one.id === id ? { ...one, ...next } : one)));
const send = (one: Conversation, text: string, note: boolean) =>
change(one.id, {
messages: [...one.messages, { id: `m${one.messages.length + 1}`, from: 'you', text, time: 'Now', note }],
status: note ? one.status : 'waiting',
});
return (
<ScreenFrame>
<ListDetail arrangement="reading-pane" value={openId} onValueChange={setOpenId}>
<AppFramePanel
size="list"
aria-label="Inbox"
header={
<SidebarHeader>
<SidebarHeaderRow>
<AppFrameTrigger />
<SidebarTitle>Inbox</SidebarTitle>
<AppFrameListToggle />
</SidebarHeaderRow>
</SidebarHeader>
}
>
<ListDetailList
filters={
<>
<SearchInput
label="Search conversations"
placeholder="Search"
value={query}
onChange={(event) => setQuery(event.currentTarget.value)}
/>
<ToggleGroup
type="single"
scroll
aria-label="Queues"
value={queue}
onValueChange={(next) => next && setQueue(next as Queue)}
>
{QUEUES.map((each) => (
<ToggleGroupItem
key={each.id}
value={each.id}
count={found.filter((one) => inQueue(each.id, one)).length}
>
{each.words}
</ToggleGroupItem>
))}
</ToggleGroup>
</>
}
>
{shown.length === 0 ? (
<Empty>
<EmptyHeader>
<EmptyTitle>No conversation matches.</EmptyTitle>
<EmptyDescription>Try other words or another queue.</EmptyDescription>
</EmptyHeader>
</Empty>
) : (
<ul aria-label="Conversations" className="flex flex-col gap-0.5">
{shown.map((one) => (
<ListDetailItem key={one.id} value={one.id} asChild>
<li>
<ListDetailTrigger
media={
<Avatar variant="solid" size="xs" name={one.customer} aria-hidden="true">
{one.customer}
</Avatar>
}
>
{one.subject}
</ListDetailTrigger>
</li>
</ListDetailItem>
))}
</ul>
)}
</ListDetailList>
</AppFramePanel>
<ListDetailPanel
title={open?.subject ?? ''}
description={open ? `${open.customer}, ${open.email}` : undefined}
closeLabel="Back to the inbox"
actions={
open ? (
<TopBarAction
icon="circle-check"
aria-label="Close conversation"
disabled={open.status === 'closed'}
onClick={() => change(open.id, { status: 'closed' })}
/>
) : null
}
placeholder={
<Empty>
<EmptyHeader>
<EmptyTitle>Choose a conversation</EmptyTitle>
<EmptyDescription>Its messages open here, with the reply box under them.</EmptyDescription>
</EmptyHeader>
</Empty>
}
>
{open ? (
<>
<Properties variant="band" aria-label="Conversation">
<PropertyRow label="Status">
{(control) => (
<Select value={open.status} onValueChange={(next) => change(open.id, { status: next as Status })}>
<SelectTrigger {...control} variant="ghost">
<SelectValue />
<SelectIcon />
</SelectTrigger>
<SelectContent searchLabel="Status" search={false}>
{STATUSES.map((value) => (
<SelectItem key={value} value={value}>
{STATUS_WORDS[value]}
</SelectItem>
))}
</SelectContent>
</Select>
)}
</PropertyRow>
<PropertyRow label="Assignee">
<PersonSelect
people={TEAM}
optional
value={open.assignee}
onValueChange={(next) => change(open.id, { assignee: next })}
/>
</PropertyRow>
</Properties>
<Thread key={open.id} conversation={open} onSend={(text, note) => send(open, text, note)} />
</>
) : null}
</ListDetailPanel>
</ListDetail>
</ScreenFrame>
);
}
/** The open conversation's messages (a note in its warm box), then the reply box with its two modes. */
function Thread({
conversation,
onSend,
}: {
conversation: Conversation;
onSend: (text: string, note: boolean) => void;
}) {
const [mode, setMode] = useState('reply');
const [draft, setDraft] = useState('');
const { customer } = conversation;
return (
<>
<MessageList aria-label={`Conversation with ${customer}`} inset={false}>
{conversation.messages.map((message) => (
<ChatMessage
key={message.id}
from={message.from === 'you' ? 'self' : 'other'}
author={message.from === 'you' ? 'You' : customer}
avatar={
message.from === 'you' ? undefined : (
<Avatar variant="solid" name={customer} aria-hidden="true">
{customer}
</Avatar>
)
}
time={message.time}
variant={message.note ? 'note' : 'default'}
>
{message.text}
</ChatMessage>
))}
</MessageList>
<Composer
variant="reply"
aria-label={`Reply to ${customer}`}
modes={MODES}
mode={mode}
onModeChange={setMode}
onSubmit={(event) => {
event.preventDefault();
if (draft.trim()) onSend(draft.trim(), mode === 'note');
setDraft('');
}}
>
<ComposerEditor aria-label="Message" value={draft} onChange={(event) => setDraft(event.target.value)} />
<ComposerToolbar>
<ComposerActions>
<ComposerSubmit aria-label="Send" disabled={!draft.trim()} />
</ComposerActions>
</ComposerToolbar>
</Composer>
</>
);
}