Skip to content

Commit d83d11d

Browse files
committed
update useNC logic.
1 parent f91febe commit d83d11d

File tree

4 files changed

+30
-42
lines changed

4 files changed

+30
-42
lines changed

src/components/LandingHome.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export function LandingHome() {
5959
if (initStore.startsWith('local')){ // Don't fetch store if local
6060
return
6161
}
62+
setUseNC(false)
6263
const newStore = GetStore(initStore)
6364
setCurrentStore(newStore)
6465
}, [initStore, setCurrentStore])

src/components/ui/MainPanel/Dataset.tsx

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
DialogContent,
2121
DialogTitle,
2222
} from "@/components/ui/dialog";
23-
23+
import { Switcher } from '../Switcher';
2424

2525
const ZARR_STORES = {
2626
ESDC: 'https://s3.bgc-jena.mpg.de:9000/esdl-esdc-v3.0.2/esdc-16d-2.5deg-46x72x1440-3.0.2.zarr',
@@ -90,13 +90,15 @@ const DatasetOption = ({
9090

9191
const Dataset = ({setOpenVariables} : {setOpenVariables: React.Dispatch<React.SetStateAction<boolean>>}) => {
9292
const [showStoreInput, setShowStoreInput] = useState(false);
93-
const [showLocalZarrInput, setShowLocalZarrInput] = useState(false);
94-
const [showLocalNetCDFInput, setShowLocalNetCDFInput] = useState(false);
93+
const [showLocalInput, setShowLocalInput] = useState(false);
9594
const [popoverSide, setPopoverSide] = useState<"left" | "top">("left");
9695
const [activeOption, setActiveOption] = useState<string>('ESDC')
9796
const [showDescriptionDialog, setShowDescriptionDialog] = useState<boolean>(false)
9897
const [openDescriptionPopover, setOpenDescriptionPopover] = useState<boolean>(false)
9998
const [isSafari, setIsSafari] = useState<boolean>(false)
99+
const {useNC} = useZarrStore(useShallow(state => ({
100+
useNC:state.fetchNC
101+
})))
100102

101103
const { initStore, setInitStore } = useGlobalStore(
102104
useShallow((state) => ({
@@ -169,8 +171,7 @@ const Dataset = ({setOpenVariables} : {setOpenVariables: React.Dispatch<React.Se
169171
active={activeOption === 'ESDC'}
170172
onClick={() => {
171173
setShowStoreInput(false);
172-
setShowLocalZarrInput(false);
173-
setShowLocalNetCDFInput(false);
174+
setShowLocalInput(false);
174175
setActiveOption('ESDC');
175176
setInitStore(ZARR_STORES.ESDC);
176177
if (popoverSide === 'top') {
@@ -186,8 +187,7 @@ const Dataset = ({setOpenVariables} : {setOpenVariables: React.Dispatch<React.Se
186187
active={activeOption === 'seasfire'}
187188
onClick={() => {
188189
setShowStoreInput(false);
189-
setShowLocalZarrInput(false);
190-
setShowLocalNetCDFInput(false);
190+
setShowLocalInput(false);
191191
setActiveOption('seasfire');
192192
setInitStore(ZARR_STORES.SEASFIRE);
193193
if (popoverSide === 'top') {
@@ -206,8 +206,7 @@ const Dataset = ({setOpenVariables} : {setOpenVariables: React.Dispatch<React.Se
206206
active={activeOption === 'remote'}
207207
onClick={() => {
208208
setShowStoreInput((prev) => !prev);
209-
setShowLocalZarrInput(false);
210-
setShowLocalNetCDFInput(false);
209+
setShowLocalInput(false);
211210
setActiveOption('remote');
212211
}}
213212
>
@@ -245,43 +244,30 @@ const Dataset = ({setOpenVariables} : {setOpenVariables: React.Dispatch<React.Se
245244
</div>
246245
<div className="w-full">
247246
<DatasetOption
248-
active={activeOption === 'localZarr'}
249-
onClick={() => {
250-
setShowLocalZarrInput((prev) => !prev);
251-
setShowStoreInput(false);
252-
setShowLocalNetCDFInput(false);
253-
setActiveOption('localZarr');
254-
}}
255-
>
256-
Local Zarr
257-
</DatasetOption>
258-
{showLocalZarrInput &&
259-
<div className="mt-2">
260-
{isSafari ?
261-
<div className="p-3 rounded-md border border-yellow-600 text-tiny max-w-[300px]">
262-
<strong>Local folder upload is not supported in Safari.</strong> Please use Chrome, Firefox, or Edge instead.
263-
</div>
264-
:
265-
<LocalZarr setShowLocal={setShowLocalZarrInput} setOpenVariables={popoverSide === 'top' ? setShowDescriptionDialog : setOpenDescriptionPopover} setInitStore={setInitStore} />
266-
}
267-
</div>
268-
}
269-
</div>
270-
<div className="w-full">
271-
<DatasetOption
272-
active={activeOption === 'localNetCDF'}
247+
active={activeOption === 'local'}
273248
onClick={() => {
274-
setShowLocalNetCDFInput((prev) => !prev);
249+
setShowLocalInput((prev) => !prev);
275250
setShowStoreInput(false);
276-
setShowLocalZarrInput(false);
277-
setActiveOption('localNetCDF');
251+
setActiveOption('local');
278252
}}
279253
>
280-
Local NetCDF
254+
Local
281255
</DatasetOption>
282-
{showLocalNetCDFInput &&
256+
{showLocalInput &&
283257
<div className="mt-2">
284-
<LocalNetCDF setShowLocal={setShowLocalNetCDFInput} setOpenVariables={popoverSide === 'top' ? setShowDescriptionDialog : setOpenDescriptionPopover} />
258+
<>
259+
<Switcher leftText='Zarr' rightText='NetCDF' state={!useNC} onClick={()=>useZarrStore.setState({fetchNC:!useNC})} />
260+
{
261+
useNC ?
262+
<LocalNetCDF setShowLocal={setShowLocalInput} setOpenVariables={popoverSide === 'top' ? setShowDescriptionDialog : setOpenDescriptionPopover} />
263+
: isSafari ?
264+
<div className="p-3 rounded-md border border-yellow-600 text-tiny max-w-[300px]">
265+
<strong>Local folder upload is not supported in Safari.</strong> Please use Chrome, Firefox, or Edge instead.
266+
</div>
267+
:
268+
<LocalZarr setShowLocal={setShowLocalInput} setOpenVariables={popoverSide === 'top' ? setShowDescriptionDialog : setOpenDescriptionPopover} setInitStore={setInitStore} />
269+
}
270+
</>
285271
</div>
286272
}
287273
</div>

src/components/ui/MainPanel/LocalNetCDF.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ interface LocalNCType {
1010
setOpenVariables: React.Dispatch<React.SetStateAction<boolean>>;
1111
}
1212

13-
const LocalNetCDF = ({setShowLocal, setOpenVariables}:LocalNCType) => {
14-
const {setStatus, setVariables, setZMeta, setInitStore} = useGlobalStore.getState()
13+
const LocalNetCDF = ({ setOpenVariables}:LocalNCType) => {
14+
const {setStatus } = useGlobalStore.getState()
1515
const {ncModule} = useZarrStore.getState()
1616

1717
const handleFileSelect = async (event: ChangeEvent<HTMLInputElement>) => {

src/components/ui/MainPanel/LocalZarr.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const LocalZarr = ({setShowLocal, setOpenVariables, setInitStore}:LocalZarrType)
5656
setOpenVariables(true);
5757
setInitStore(`local_${baseDir}`)
5858
setStatus(null)
59+
useZarrStore.setState({ useNC: false})
5960
} catch (error) {
6061
setStatus(null)
6162
if (error instanceof Error) {

0 commit comments

Comments
 (0)