Skip to content

A personal agent with a browser, terminal, files, and work that keeps going built with CopilotKit and AG-UI.

TypeScript

fix: clear the mail draft error and ignore stale loads (#99)

nvtoan0201-swee9d249074c82
diff --git a/apps/mobile/src/screens.tsx b/apps/mobile/src/screens.tsx
index 86ba851..2e4afca 100644
--- a/apps/mobile/src/screens.tsx
+++ b/apps/mobile/src/screens.tsx
@@ -453,10 +453,19 @@ export function MailScreen() {
const [drafts, setDrafts] = useState<(EmailDraft & { id: string; createdAt: string })[]>([]);
const [error, setError] = useState("");
useEffect(() => {
+ let active = true;
+ setError("");
void api
.request<(EmailDraft & { id: string; createdAt: string })[]>("/api/drafts")
- .then(setDrafts)
- .catch((e) => setError(e instanceof Error ? e.message : String(e)));
+ .then((next) => {
+ if (active) setDrafts(next);
+ })
+ .catch((e) => {
+ if (active) setError(e instanceof Error ? e.message : String(e));
+ });
+ return () => {
+ active = false;
+ };
}, [api, w]);
const items = w.mail.filter(
(m) =>