@@ -37,6 +37,10 @@ import {
3737import { Button } from '@/components/ui/button' ;
3838import { exportTasksAsJSON , exportTasksAsTXT } from '@/exports-tasks' ;
3939import { DevLogs } from '../DevLogs/DevLogs' ;
40+ import { useTaskAutoSync } from '@/Task-AutoSync' ;
41+ import { Label } from '@/components/ui/label' ;
42+ import { Switch } from '@/components/ui/switch' ;
43+ import { Slider } from '@/components/ui/slider' ;
4044
4145export const NavbarMobile = (
4246 props : Props & { setIsOpen : ( isOpen : boolean ) => void ; isOpen : boolean } & {
@@ -45,7 +49,16 @@ export const NavbarMobile = (
4549 }
4650) => {
4751 const [ isExportDialogOpen , setIsExportDialogOpen ] = useState ( false ) ;
52+ const [ isAutoSyncDialogOpen , setIsAutoSyncDialogOpen ] = useState ( false ) ;
4853 const [ isDevLogsOpen , setIsDevLogsOpen ] = useState ( false ) ;
54+ const [ autoSyncEnable , setAutoSyncEnable ] = useState ( false ) ;
55+ const [ syncInterval , setSyncInterval ] = useState ( 1 ) ;
56+ useTaskAutoSync ( {
57+ isLoading : props . isLoading ,
58+ setIsLoading : props . setIsLoading ,
59+ isAutoSyncEnabled : autoSyncEnable ,
60+ syncInterval : syncInterval * 60000 ,
61+ } ) ;
4962
5063 const handleExportJSON = ( ) => {
5164 exportTasksAsJSON ( props . tasks || [ ] ) ;
@@ -76,34 +89,35 @@ export const NavbarMobile = (
7689 < SheetHeader >
7790 < SheetTitle className = "font-bold text-xl" > CCSync</ SheetTitle >
7891 </ SheetHeader >
79- < Dialog
80- open = { isExportDialogOpen }
81- onOpenChange = { setIsExportDialogOpen }
82- >
83- < nav className = "flex flex-col justify-center items-center gap-2 mt-4" >
84- { routeList . map ( ( { href, label } : RouteProps ) => (
85- < a
86- rel = "noreferrer noopener"
87- key = { label }
88- href = { href }
89- onClick = { ( ) => props . setIsOpen ( false ) }
90- className = { buttonVariants ( { variant : 'ghost' } ) }
91- >
92- { label }
93- </ a >
94- ) ) }
92+
93+ < nav className = "flex flex-col justify-center items-center gap-2 mt-4" >
94+ { routeList . map ( ( { href, label } : RouteProps ) => (
9595 < a
9696 rel = "noreferrer noopener"
97- href = { url . githubRepoURL }
98- target = "_blank"
99- className = { `w-[130px] border ${ buttonVariants ( {
100- variant : 'secondary' ,
101- } ) } `}
97+ key = { label }
98+ href = { href }
99+ onClick = { ( ) => props . setIsOpen ( false ) }
100+ className = { buttonVariants ( { variant : 'ghost' } ) }
102101 >
103- < Github className = "mr-2 w-5 h-5" />
104- Github
102+ { label }
105103 </ a >
104+ ) ) }
105+ < a
106+ rel = "noreferrer noopener"
107+ href = { url . githubRepoURL }
108+ target = "_blank"
109+ className = { `w-[130px] border ${ buttonVariants ( {
110+ variant : 'secondary' ,
111+ } ) } `}
112+ >
113+ < Github className = "mr-2 w-5 h-5" />
114+ Github
115+ </ a >
106116
117+ < Dialog
118+ open = { isExportDialogOpen }
119+ onOpenChange = { setIsExportDialogOpen }
120+ >
107121 < DialogTrigger asChild >
108122 < div
109123 className = { `w-[130px] cursor-pointer border ${ buttonVariants ( {
@@ -114,63 +128,107 @@ export const NavbarMobile = (
114128 Export Tasks
115129 </ div >
116130 </ DialogTrigger >
117- < div
118- onClick = { ( ) => {
119- setIsDevLogsOpen ( true ) ;
120- props . setIsOpen ( false ) ;
121- } }
122- className = { `w-[130px] cursor-pointer border ${ buttonVariants ( {
123- variant : 'secondary' ,
124- } ) } `}
125- >
126- < Terminal className = "mr-2 w-5 h-5" />
127- Developer Logs
128- </ div >
129- < div
130- onClick = { ( ) => deleteAllTasks ( props ) }
131- className = { `w-[130px] border ${ buttonVariants ( {
132- variant : 'destructive' ,
133- } ) } `}
134- >
135- < Trash2 className = "mr-2 w-5 h-5" />
136- Delete All Tasks
137- </ div >
138- < div
139- onClick = { handleLogout }
140- className = { `w-[130px] border ${ buttonVariants ( {
141- variant : 'destructive' ,
142- } ) } `}
143- >
144- < LogOut className = "mr-2 w-5 h-5" />
145- Log out
146- </ div >
147- </ nav >
148- < DialogContent >
149- < DialogHeader >
150- < DialogTitle > Choose Export Format</ DialogTitle >
151- < DialogDescription >
152- Would you like to download your tasks as a JSON file or a TXT
153- file?
154- </ DialogDescription >
155- </ DialogHeader >
156- < div className = "flex flex-col sm:flex-row justify-end gap-2 mt-4" >
157- < Button
158- onClick = { handleExportTXT }
159- className = "w-full sm:w-auto hover:bg-white bg-[#3B82F6]"
160- >
161- < FileText className = "mr-2 h-4 w-4" />
162- Download .txt
163- </ Button >
164- < Button
165- onClick = { handleExportJSON }
166- className = "w-full sm:w-auto hover:bg-white bg-[#3B82F6]"
131+ < DialogContent >
132+ < DialogHeader >
133+ < DialogTitle > Choose Export Format</ DialogTitle >
134+ < DialogDescription >
135+ Would you like to download your tasks as a JSON file or a
136+ TXT file?
137+ </ DialogDescription >
138+ </ DialogHeader >
139+ < div className = "flex flex-col sm:flex-row justify-end gap-2 mt-4" >
140+ < Button
141+ onClick = { handleExportTXT }
142+ className = "w-full sm:w-auto hover:bg-white bg-[#3B82F6]"
143+ >
144+ < FileText className = "mr-2 h-4 w-4" />
145+ Download .txt
146+ </ Button >
147+ < Button
148+ onClick = { handleExportJSON }
149+ className = "w-full sm:w-auto hover:bg-white bg-[#3B82F6]"
150+ >
151+ < FileJson className = "mr-2 h-4 w-4" />
152+ Download .json
153+ </ Button >
154+ </ div >
155+ </ DialogContent >
156+ </ Dialog >
157+ < Dialog
158+ open = { isAutoSyncDialogOpen }
159+ onOpenChange = { setIsAutoSyncDialogOpen }
160+ >
161+ < DialogTrigger asChild >
162+ < div
163+ className = { `w-[130px] cursor-pointer border ${ buttonVariants ( {
164+ variant : 'secondary' ,
165+ } ) } `}
167166 >
168- < FileJson className = "mr-2 h-4 w-4" />
169- Download .json
170- </ Button >
171- </ div >
172- </ DialogContent >
173- </ Dialog >
167+ Auto-sync
168+ </ div >
169+ </ DialogTrigger >
170+ < DialogContent >
171+ < div className = "flex flex-col space-y-4 pt-2" >
172+ < div className = "flex mt-2 items-center justify-between space-x-2" >
173+ < Label htmlFor = "autosync-switch" className = "text-base" >
174+ Enable Auto-Sync
175+ </ Label >
176+ < Switch
177+ id = "autosync-switch"
178+ checked = { autoSyncEnable }
179+ onCheckedChange = { setAutoSyncEnable }
180+ />
181+ </ div >
182+
183+ { autoSyncEnable && (
184+ < div className = "flex flex-col space-y-3 pt-2" >
185+ < Label htmlFor = "sync-slider" className = "text-sm" >
186+ Sync every { syncInterval } minutes
187+ </ Label >
188+ < Slider
189+ id = "sync-slider"
190+ min = { 1 }
191+ max = { 10 }
192+ step = { 1 }
193+ value = { [ syncInterval ] }
194+ onValueChange = { ( value ) => setSyncInterval ( value [ 0 ] ) }
195+ />
196+ </ div >
197+ ) }
198+ </ div >
199+ </ DialogContent >
200+ </ Dialog >
201+ < div
202+ onClick = { ( ) => {
203+ setIsDevLogsOpen ( true ) ;
204+ props . setIsOpen ( false ) ;
205+ } }
206+ className = { `w-[130px] cursor-pointer border ${ buttonVariants ( {
207+ variant : 'secondary' ,
208+ } ) } `}
209+ >
210+ < Terminal className = "mr-2 w-5 h-5" />
211+ Developer Logs
212+ </ div >
213+ < div
214+ onClick = { ( ) => deleteAllTasks ( props ) }
215+ className = { `w-[130px] border ${ buttonVariants ( {
216+ variant : 'destructive' ,
217+ } ) } `}
218+ >
219+ < Trash2 className = "mr-2 w-5 h-5" />
220+ Delete All Tasks
221+ </ div >
222+ < div
223+ onClick = { handleLogout }
224+ className = { `w-[130px] border ${ buttonVariants ( {
225+ variant : 'destructive' ,
226+ } ) } `}
227+ >
228+ < LogOut className = "mr-2 w-5 h-5" />
229+ Log out
230+ </ div >
231+ </ nav >
174232 </ SheetContent >
175233 </ Sheet >
176234 < DevLogs isOpen = { isDevLogsOpen } onOpenChange = { setIsDevLogsOpen } />
0 commit comments