@@ -27,7 +27,12 @@ import {
2727 parseMaxDeliveryAge ,
2828} from "@t3tools/client-runtime/scheduled-task-webhook" ;
2929import { useEffect , useLayoutEffect , useRef , useState , type ReactNode } from "react" ;
30- import { useFocusEffect , useNavigation , usePreventRemove } from "@react-navigation/native" ;
30+ import {
31+ type StaticScreenProps ,
32+ useFocusEffect ,
33+ useNavigation ,
34+ usePreventRemove ,
35+ } from "@react-navigation/native" ;
3136import type { NativeStackNavigationProp } from "@react-navigation/native-stack" ;
3237import { AppState , Platform , Pressable , TextInput as RNTextInput , View } from "react-native" ;
3338import { useSafeAreaInsets } from "react-native-safe-area-context" ;
@@ -75,8 +80,11 @@ import { useScheduledTaskEditor } from "./scheduled-task-editor";
7580import { scheduledTaskEditorSessionAtom } from "./scheduled-task-editor-state" ;
7681import { appAtomRegistry } from "../../state/atom-registry" ;
7782import {
83+ describeSchedule ,
7884 formatNextScheduledTaskRun ,
79- formatScheduledTaskInterval ,
85+ formatTime ,
86+ repeatLabel ,
87+ SCHEDULE_DAYS ,
8088} from "./scheduledTaskPresentation" ;
8189
8290type ScheduledTaskRoutes = {
@@ -86,31 +94,6 @@ type ScheduledTaskRoutes = {
8694 SettingsScheduledTaskBranch : undefined ;
8795} ;
8896
89- const DAYS = [
90- { index : 1 , label : "Mon" } ,
91- { index : 2 , label : "Tue" } ,
92- { index : 3 , label : "Wed" } ,
93- { index : 4 , label : "Thu" } ,
94- { index : 5 , label : "Fri" } ,
95- { index : 6 , label : "Sat" } ,
96- { index : 0 , label : "Sun" } ,
97- ] as const ;
98-
99- function describeSchedule ( task : ScheduledTask ) : string {
100- if ( task . schedule . type === "webhook" ) return "On webhook" ;
101- if ( task . schedule . type === "interval" ) return formatScheduledTaskInterval ( task . schedule . everyMs ) ;
102- const days = task . schedule . weekdays ?. length ? repeatLabel ( task . schedule . weekdays ) : "Every day" ;
103- return `${ days } at ${ formatTime ( task . schedule . timeOfDay ) } ` ;
104- }
105-
106- function formatTime ( value : string ) : string {
107- const [ hours , minutes ] = value . split ( ":" ) . map ( Number ) ;
108- if ( ! Number . isInteger ( hours ) || ! Number . isInteger ( minutes ) ) return value ;
109- const time = new Date ( ) ;
110- time . setHours ( hours ?? 9 , minutes ?? 0 , 0 , 0 ) ;
111- return time . toLocaleTimeString ( [ ] , { hour : "numeric" , minute : "2-digit" } ) ;
112- }
113-
11497function timePickerValue ( value : string ) : Date {
11598 const [ hours , minutes ] = value . split ( ":" ) . map ( Number ) ;
11699 const time = new Date ( ) ;
@@ -123,17 +106,6 @@ function timePickerValue(value: string): Date {
123106 return time ;
124107}
125108
126- function repeatLabel ( weekdays : ReadonlyArray < number > ) : string {
127- const days = new Set ( weekdays ) ;
128- if ( days . size === 7 ) return "Every day" ;
129- if ( days . size === 5 && [ 1 , 2 , 3 , 4 , 5 ] . every ( ( day ) => days . has ( day ) ) ) return "Weekdays" ;
130- return (
131- DAYS . filter ( ( day ) => days . has ( day . index ) )
132- . map ( ( day ) => day . label )
133- . join ( ", " ) || "Choose days"
134- ) ;
135- }
136-
137109function FormField ( props : {
138110 readonly label : string ;
139111 readonly value : string ;
@@ -365,10 +337,13 @@ export function SettingsScheduledTasksRouteScreen() {
365337 ) ;
366338}
367339
368- export function SettingsScheduledTaskNewRouteScreen ( ) {
340+ /** `prefilled` keeps the editor session a caller has already started, such as from a draft. */
341+ export function SettingsScheduledTaskNewRouteScreen ( {
342+ route,
343+ } : StaticScreenProps < { readonly prefilled ?: boolean } | undefined > ) {
369344 const { resetEditor } = useScheduledTaskEditor ( ) ;
370345 const { availableTargets } = useSettingsEnvironmentFilter ( ) ;
371- const initialized = useRef ( false ) ;
346+ const initialized = useRef ( route . params ?. prefilled === true ) ;
372347 useLayoutEffect ( ( ) => {
373348 if ( initialized . current || availableTargets . length === 0 ) return ;
374349 initialized . current = true ;
@@ -511,6 +486,7 @@ function SettingsScheduledTaskEditorScreen({ title }: { readonly title: string }
511486 onChangeSelection = { setSelection }
512487 disabled = { saving }
513488 voiceInput = { voiceInput }
489+ note = { editor . note }
514490 />
515491 }
516492 setDraft = { ( draft ) => {
@@ -913,7 +889,7 @@ function TaskForm({
913889 title : "Weekdays" ,
914890 state : repeatLabel ( draft . schedule . weekdays ) === "Weekdays" ? "on" : undefined ,
915891 } ,
916- ...DAYS . map ( ( day ) => ( {
892+ ...SCHEDULE_DAYS . map ( ( day ) => ( {
917893 id : String ( day . index ) ,
918894 title : day . label ,
919895 attributes : { keepsMenuPresented : true } ,
@@ -925,11 +901,11 @@ function TaskForm({
925901 onSelect = { ( id ) => {
926902 const weekdays =
927903 id === "every_day"
928- ? DAYS . map ( ( day ) => day . index )
904+ ? SCHEDULE_DAYS . map ( ( day ) => day . index )
929905 : id === "weekdays"
930906 ? [ 1 , 2 , 3 , 4 , 5 ]
931907 : ( ( ) => {
932- const day = DAYS . find ( ( item ) => String ( item . index ) === id ) ;
908+ const day = SCHEDULE_DAYS . find ( ( item ) => String ( item . index ) === id ) ;
933909 if ( ! day ) return draft . schedule . weekdays ;
934910 return draft . schedule . weekdays . includes ( day . index )
935911 ? draft . schedule . weekdays . filter ( ( index ) => index !== day . index )
0 commit comments