Some checks failed
Build & Release APK / build (push) Failing after 24s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
20 lines
982 B
TypeScript
20 lines
982 B
TypeScript
// Headless entry point for widget events. When the app's JS context is
|
|
// alive this shares the in-memory store; when launched cold, hydrate() loads
|
|
// AsyncStorage — so completing from the widget goes through the exact same
|
|
// local-first mutation path (instant local write, op queued, synced later).
|
|
import type { WidgetTaskHandlerProps } from "react-native-android-widget";
|
|
import { hydrate, updateTask } from "../lib/store";
|
|
import { renderNextUpWidget } from "./render";
|
|
|
|
export async function widgetTaskHandler(props: WidgetTaskHandlerProps) {
|
|
if (props.widgetAction === "WIDGET_DELETED") return;
|
|
await hydrate();
|
|
if (props.widgetAction === "WIDGET_CLICK") {
|
|
// OPEN_APP / OPEN_URI are handled natively; only completion reaches JS.
|
|
if (props.clickAction !== "COMPLETE_TASK") return;
|
|
const taskId = props.clickActionData?.taskId;
|
|
if (typeof taskId === "string") updateTask(taskId, { status: "done" });
|
|
}
|
|
props.renderWidget(renderNextUpWidget());
|
|
}
|