Open History to see the last commit
1import { toast } from 'sonner'
2
3import {
4 setProjectStarter,
5 useApplicationMode,
6 useRegistry,
7 useStartupDialog,
8} from '../store/project'
9import { loadRemoteStarter } from '../lib/api'
10
11import {
12 Dialog,
13 DialogContent,
14 DialogFooter,
15 DialogHeader,
16 DialogTitle,
17} from './ui/dialog'
18import { StartersCarousel } from './starters-carousel'
19import { Button } from './ui/button'
20import { Switch } from './ui/switch'
21import { Label } from './ui/label'
22
23export default function StartupDialog() {
24 const mode = useApplicationMode()
25 const registry = useRegistry()
26 const { open, setOpen, dontShowAgain, setDontShowAgain } = useStartupDialog()
27
28 if (mode !== 'setup' || !registry || registry?.starters?.length === 0) {
29 return null
30 }
31
32 async function onImport(registryUrl: string) {
33 const data = await loadRemoteStarter(registryUrl)
34
35 if ('error' in data) {
36 toast.error('Failed to load starter', {
37 description: data.error,
38 })
39 } else {
40 setProjectStarter(data)
41 setOpen(false)
42 }
43 }
44
45 return (
46 <Dialog modal open={open} onOpenChange={setOpen}>
47 <DialogContent className="sm:min-w-[425px] sm:max-w-fit">
48 <DialogHeader>
49 <DialogTitle className="text-center text-2xl font-bold">
50 Would you like to use a starter project?
51 </DialogTitle>
52 </DialogHeader>
53 <div>
54 <StartersCarousel onImport={onImport} />
55 </div>
56 <DialogFooter className="flex sm:justify-between w-full">
57 <div className="flex items-center gap-2">
58 <Switch
59 id="show-startup-dialog"
60 checked={dontShowAgain}
61 onCheckedChange={setDontShowAgain}
62 />
63 <Label htmlFor="show-startup-dialog">Don't show this again</Label>
64 </div>
65 <Button onClick={() => setOpen(false)}>
66 No, I want to start from scratch
67 </Button>
68 </DialogFooter>
69 </DialogContent>
70 </Dialog>
71 )
72}