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

NewTaskDraftRouteScreen.tsx

51 lines1.7 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 readonly draftId?: string | string[];
13 readonly incomingShareId?: string | string[];
14};
15​
16export function NewTaskDraftRouteScreen({ route }: StaticScreenProps<NewTaskDraftRouteParams>) {
17 const params = route.params ?? {};
18​
19 // Keyed on the params object so a fresh navigation to this (already
20 // mounted) screen produces a new reference, letting the draft screen
21 // re-apply the requested project.
22 const initialProjectRef = useMemo(
23 () => ({
24 environmentId: Array.isArray(params.environmentId)
25 ? params.environmentId[0]
26 : params.environmentId,
27 projectId: Array.isArray(params.projectId) ? params.projectId[0] : params.projectId,
28 }),
29 [route.params],
30 );
31​
32 return (
33 <>
34 <NativeStackScreenOptions
35 options={{
36 title: Array.isArray(params.title) ? params.title[0] : (params.title ?? "New task"),
37 }}
38 />
39 <NewTaskDraftScreen
40 initialProjectRef={initialProjectRef}
41 incomingShareId={
42 Array.isArray(params.incomingShareId) ? params.incomingShareId[0] : params.incomingShareId
43 }
44 pendingTaskId={
45 Array.isArray(params.pendingTaskId) ? params.pendingTaskId[0] : params.pendingTaskId
46 }
47 draftId={Array.isArray(params.draftId) ? params.draftId[0] : params.draftId}
48 />
49 </>
50 );