Skip to content

Commit 44d313f

Browse files
fix(frontend): distinguish draft errors from empty state
1 parent 50519c6 commit 44d313f

4 files changed

Lines changed: 24 additions & 6 deletions

File tree

frontend/src/features/draft/draft-list-screen.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export function DraftListScreen() {
1919
statesById,
2020
drafts,
2121
showCapture,
22+
showEmptyState,
2223
isLoadingDrafts,
2324
draftsLoadError,
2425
statesLoadError,
@@ -97,7 +98,7 @@ export function DraftListScreen() {
9798

9899
{showCapture && (
99100
<div
100-
className={drafts.length === 0
101+
className={showEmptyState
101102
? "draft-home__empty"
102103
: "draft-home__content"}
103104
>
@@ -133,10 +134,10 @@ export function DraftListScreen() {
133134
stacksById={stacksById}
134135
showStackContext
135136
onDraftCreated={handleDraftCreated}
136-
formHeading={drafts.length === 0
137+
formHeading={showEmptyState
137138
? "Capture your first Draft"
138139
: undefined}
139-
emptyLead={drafts.length === 0
140+
emptyLead={showEmptyState
140141
? "Record work in seconds without creating a Stack first."
141142
: undefined}
142143
/>

frontend/src/features/draft/stack-draft-section.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function StackDraftSection({ stackId }: StackDraftSectionProps) {
1010
statesById,
1111
drafts,
1212
showCapture,
13+
showEmptyState,
1314
isLoadingDrafts,
1415
draftsLoadError,
1516
statesLoadError,
@@ -70,7 +71,9 @@ export function StackDraftSection({ stackId }: StackDraftSectionProps) {
7071
showStackContext={false}
7172
stackId={stackId}
7273
onDraftCreated={handleDraftCreated}
73-
emptyLead="Capture the first Draft for this Stack."
74+
emptyLead={showEmptyState
75+
? "Capture the first Draft for this Stack."
76+
: undefined}
7477
/>
7578
</div>
7679
)}

frontend/src/features/draft/use-draft-list-data.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface UseDraftListDataResult {
2626
readonly statesById: ReadonlyMap<string, State>;
2727
readonly drafts: readonly Draft[];
2828
readonly showCapture: boolean;
29+
readonly showEmptyState: boolean;
2930
readonly isLoadingDrafts: boolean;
3031
readonly draftsLoadError: string | null;
3132
readonly statesLoadError: string | null;
@@ -161,6 +162,8 @@ export const useDraftListData = ({
161162
: draftsCreatedDuringError;
162163
const showCapture = draftsState.kind === "ready" ||
163164
draftsState.kind === "error";
165+
const showEmptyState = draftsState.kind === "ready" &&
166+
draftsState.data.length === 0;
164167
const isLoadingDrafts = draftsState.kind === "loading";
165168
const draftsLoadError = draftsState.kind === "error"
166169
? draftsState.message
@@ -173,6 +176,7 @@ export const useDraftListData = ({
173176
statesById,
174177
drafts,
175178
showCapture,
179+
showEmptyState,
176180
isLoadingDrafts,
177181
draftsLoadError,
178182
statesLoadError,

frontend/tests/draft-list.test.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,13 @@ describe("draft list screen", () => {
671671
});
672672

673673
expect(
674-
screen.getByRole("form", { name: "Capture your first Draft" }),
674+
screen.getByRole("form", { name: "Capture Draft" }),
675675
).toBeInTheDocument();
676+
expect(
677+
screen.queryByText(
678+
"Record work in seconds without creating a Stack first.",
679+
),
680+
).not.toBeInTheDocument();
676681
});
677682

678683
it("keeps the draft list error visible after creating during a list failure", async () => {
@@ -714,7 +719,7 @@ describe("draft list screen", () => {
714719
renderApp("/");
715720

716721
const createForm = await screen.findByRole("form", {
717-
name: "Capture your first Draft",
722+
name: "Capture Draft",
718723
});
719724

720725
await user.type(
@@ -1135,6 +1140,11 @@ describe("stack detail draft capture", () => {
11351140
const createForm = await within(draftsSection).findByRole("form", {
11361141
name: "Capture Draft",
11371142
});
1143+
expect(
1144+
within(draftsSection).queryByText(
1145+
"Capture the first Draft for this Stack.",
1146+
),
1147+
).not.toBeInTheDocument();
11381148

11391149
await user.type(
11401150
within(createForm).getByLabelText("Title"),

0 commit comments

Comments
 (0)