1+ "use client" ;
2+ import React , { useState } from 'react' ;
3+ import { useGlobalStore } from '@/GlobalStates/GlobalStore' ;
4+ import { useShallow } from 'zustand/shallow' ;
5+ import {
6+ Dialog ,
7+ DialogContent ,
8+ DialogTitle ,
9+ } from "@/components/ui/dialog" ;
10+ import {
11+ ButtonGroup ,
12+ } from "@/components/ui/button-group" ;
13+ import { Button } from "@/components/ui/button-enhanced" ;
14+ import { DescriptionContent } from './DescriptionContent' ;
15+ import CuratedDatasets from './CuratedDatasets' ;
16+ import RemoteZarr from './RemoteZarr' ;
17+ import LocalContent from './LocalContent' ;
18+
19+ type Tab = 'curated' | 'remote' | 'local' ;
20+
21+ const TABS : { value : Tab ; label : string } [ ] = [
22+ { value : 'curated' , label : 'Curated' } ,
23+ { value : 'remote' , label : 'Remote Zarr' } ,
24+ { value : 'local' , label : 'Local' } ,
25+ ] ;
26+
27+ type Props = {
28+ open : boolean ;
29+ onOpenChange : ( v : boolean ) => void ;
30+ isSafari : boolean ;
31+ } ;
32+
33+ const DatasetsModal = ( { open, onOpenChange, isSafari } : Props ) => {
34+ const [ activeOption , setActiveOption ] = useState < string > ( '' ) ;
35+ const [ showDescription , setShowDescription ] = useState ( false ) ;
36+ const [ activeTab , setActiveTab ] = useState < Tab > ( 'curated' ) ;
37+
38+ const { initStore, setInitStore, setOpenVariables } = useGlobalStore (
39+ useShallow ( state => ( {
40+ setInitStore : state . setInitStore ,
41+ setOpenVariables : state . setOpenVariables ,
42+ initStore : state . initStore ,
43+ } ) )
44+ ) ;
45+
46+ const openDescription = ( ) => setShowDescription ( true ) ;
47+
48+ const handleTabChange = ( tab : Tab ) => {
49+ setActiveTab ( tab ) ;
50+ setShowDescription ( false ) ;
51+ } ;
52+
53+ return (
54+ < Dialog open = { open } onOpenChange = { onOpenChange } >
55+ < DialogContent className = "max-w-md max-h-[80vh] overflow-y-auto p-0" >
56+ < DialogTitle className = "sr-only" > Open Dataset</ DialogTitle >
57+
58+ { /* Header */ }
59+ < div className = "px-4 pt-4 pb-3 border-b border-border" >
60+ < p className = "text-xs font-medium mb-2 uppercase tracking-wide" >
61+ Open dataset
62+ </ p >
63+ < ButtonGroup className = "justify-between border-1 rounded-md" >
64+ { TABS . map ( ( { value, label } ) => (
65+ < Button
66+ key = { value }
67+ className = 'cursor-pointer'
68+ variant = { activeTab === value ? 'secondary' : 'ghost' }
69+ size = "sm"
70+ onClick = { ( ) => handleTabChange ( value ) }
71+ >
72+ { label }
73+ </ Button >
74+ ) ) }
75+ </ ButtonGroup >
76+ </ div >
77+
78+ < div className = "p-4 flex flex-col gap-1 -mt-3" >
79+ { activeTab === 'curated' && (
80+ < CuratedDatasets
81+ activeOption = { activeOption }
82+ setActiveOption = { setActiveOption }
83+ setInitStore = { setInitStore }
84+ onOpenDescription = { openDescription }
85+ />
86+ ) }
87+ { activeTab === 'remote' && (
88+ < RemoteZarr
89+ initStore = { initStore }
90+ setInitStore = { setInitStore }
91+ onOpenDescription = { openDescription }
92+ />
93+ ) }
94+ { activeTab === 'local' && (
95+ < LocalContent
96+ setInitStore = { setInitStore }
97+ onOpenDescription = { openDescription }
98+ isSafari = { isSafari }
99+ />
100+ ) }
101+ { showDescription && (
102+ < DescriptionContent
103+ setOpenVariables = { setOpenVariables }
104+ onCloseDialog = { ( ) => {
105+ setShowDescription ( false ) ;
106+ onOpenChange ( false ) ;
107+ } }
108+ />
109+ ) }
110+ </ div >
111+ </ DialogContent >
112+ </ Dialog >
113+ ) ;
114+ } ;
115+
116+ export default DatasetsModal ;
0 commit comments