Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

NewTaskDraftRouteScreen.tsx

45 lines1.4 KB

1import type { StaticScreenProps } from "@react-navigation/native";
2import { useMemo } from "react";
3import { NativeStackScreenOptions } from "../../native/StackHeader";
4​
5import { NewTaskDraftScreen } from "./NewTaskDraftScreen";
6​
7type NewTaskDraftRouteParams = {
8 readonly environmentId?: string | string[];
9 readonly projectId?: string | string[];
10 readonly title?: string | string[];
11 readonly pendingTaskId?: string | string[];
12};
13​
14export function NewTaskDraftRouteScreen({ route }: StaticScreenProps<NewTaskDraftRouteParams>) {
15 const params = route.params ?? {};
16​
17 // Keyed on the params object so a fresh navigation to this (already
18 // mounted) screen produces a new reference, letting the draft screen
19 // re-apply the requested project.
20 const initialProjectRef = useMemo(
21 () => ({
22 environmentId: Array.isArray(params.environmentId)
23 ? params.environmentId[0]
24 : params.environmentId,
25 projectId: Array.isArray(params.projectId) ? params.projectId[0] : params.projectId,
26 }),
27 [route.params],
28 );
29​
30 return (
31 <>
32 <NativeStackScreenOptions
33 options={{
34 title: Array.isArray(params.title) ? params.title[0] : (params.title ?? "New task"),
35 }}
36 />
37 <NewTaskDraftScreen
38 initialProjectRef={initialProjectRef}
39 pendingTaskId={
40 Array.isArray(params.pendingTaskId) ? params.pendingTaskId[0] : params.pendingTaskId
41 }
42 />
43 </>
44 );