Skip to content

Commit 5c93985

Browse files
authored
Merge pull request #488 from EarthyScience/jp/modern-netcdf
Just laying the foundation for when NetCDF is added.
2 parents bc85107 + 606932a commit 5c93985

File tree

4 files changed

+64
-9
lines changed

4 files changed

+64
-9
lines changed

src/components/ui/MainPanel/Dataset.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"use client";
22

33
import React, { SetStateAction, useEffect, useState, ReactNode } from 'react';
4-
import { useGlobalStore } from '@/utils/GlobalStates';
4+
import { useGlobalStore, useZarrStore } from '@/utils/GlobalStates';
55
import { useShallow } from 'zustand/shallow';
66
import { Input } from '../input';
77
import { Button } from '../button';
88
import { TbDatabasePlus } from "react-icons/tb";
99
import { TbVariable } from "react-icons/tb";
1010
import LocalZarr from './LocalZarr';
11+
import LocalNetCDF from './LocalNetCDF';
1112
import { Popover, PopoverTrigger, PopoverContent } from "@/components/ui/popover";
1213
import {
1314
Tooltip,
@@ -19,6 +20,8 @@ import {
1920
DialogContent,
2021
DialogTitle,
2122
} from "@/components/ui/dialog";
23+
import { Switcher } from '../Switcher';
24+
2225

2326
const ZARR_STORES = {
2427
ESDC: 'https://s3.bgc-jena.mpg.de:9000/esdl-esdc-v3.0.2/esdc-16d-2.5deg-46x72x1440-3.0.2.zarr',
@@ -94,6 +97,9 @@ const Dataset = ({setOpenVariables} : {setOpenVariables: React.Dispatch<React.Se
9497
const [showDescriptionDialog, setShowDescriptionDialog] = useState<boolean>(false)
9598
const [openDescriptionPopover, setOpenDescriptionPopover] = useState<boolean>(false)
9699
const [isSafari, setIsSafari] = useState<boolean>(false)
100+
const {useNC} = useZarrStore(useShallow(state => ({
101+
useNC:state.useNC
102+
})))
97103

98104
const { initStore, setInitStore } = useGlobalStore(
99105
useShallow((state) => ({
@@ -248,17 +254,25 @@ const Dataset = ({setOpenVariables} : {setOpenVariables: React.Dispatch<React.Se
248254
>
249255
Local
250256
</DatasetOption>
251-
{showLocalInput && (
257+
{showLocalInput &&
252258
<div className="mt-2">
253-
{isSafari ? (
259+
{isSafari ?
254260
<div className="p-3 rounded-md border border-yellow-600 text-tiny max-w-[300px]">
255261
<strong>Local folder upload is not supported in Safari.</strong> Please use Chrome, Firefox, or Edge instead.
256262
</div>
257-
) : (
258-
<LocalZarr setShowLocal={setShowLocalInput} setOpenVariables={popoverSide === 'top' ? setShowDescriptionDialog : setOpenDescriptionPopover} setInitStore={setInitStore} />
259-
)}
263+
:
264+
<>
265+
<Switcher leftText='Zarr' rightText='NetCDF' state={!useNC} onClick={()=>useZarrStore.setState({useNC:!useNC})} />
266+
{
267+
useNC ?
268+
<LocalNetCDF setShowLocal={setShowLocalInput} setOpenVariables={popoverSide === 'top' ? setShowDescriptionDialog : setOpenDescriptionPopover} />
269+
:
270+
<LocalZarr setShowLocal={setShowLocalInput} setOpenVariables={popoverSide === 'top' ? setShowDescriptionDialog : setOpenDescriptionPopover} setInitStore={setInitStore} />
271+
}
272+
</>
273+
}
260274
</div>
261-
)}
275+
}
262276
</div>
263277
</div>
264278
</PopoverContent>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"use client";
2+
import React, {ChangeEvent} from 'react'
3+
import { Input } from '../input'
4+
import { useGlobalStore } from '@/utils/GlobalStates';
5+
6+
interface LocalNCType {
7+
setShowLocal: React.Dispatch<React.SetStateAction<boolean>>;
8+
setOpenVariables: React.Dispatch<React.SetStateAction<boolean>>;
9+
}
10+
11+
const LocalNetCDF = ({setShowLocal, setOpenVariables}:LocalNCType) => {
12+
13+
const {setStatus} = useGlobalStore.getState()
14+
15+
const handleFileSelect = async (event: ChangeEvent<HTMLInputElement>) => {
16+
const files = event.target.files;
17+
if (!files || files.length === 0) {
18+
setStatus(null)
19+
return;
20+
}
21+
};
22+
23+
return (
24+
<div className='w-[100%]'>
25+
Under construction
26+
<Input type="file" id="filepicker"
27+
className='hover:drop-shadow-md hover:scale-[110%]'
28+
style={{width:'200px', cursor:'pointer'}}
29+
accept='.nc, .netcdf, .nc3'
30+
onChange={handleFileSelect}
31+
disabled
32+
/>
33+
</div>
34+
)
35+
}
36+
37+
export default LocalNetCDF

src/components/ui/MainPanel/LocalZarr.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22
import React, {useState, useEffect, ChangeEvent} from 'react'
33
import * as zarr from 'zarrita'
4-
import { useZarrStore, useErrorStore, useGlobalStore } from '@/utils/GlobalStates';
4+
import { useZarrStore, useGlobalStore } from '@/utils/GlobalStates';
55
import { Input } from '../input';
66
import ZarrParser from '@/components/zarr/ZarrParser';
77

src/utils/GlobalStates.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ type ZarrState = {
454454
reFetch: boolean;
455455
currentChunks: {x:number[], y:number[], z:number[]};
456456
arraySize: number,
457+
useNC: boolean,
457458

458459
setZSlice: (zSlice: [number , number | null]) => void;
459460
setYSlice: (ySlice: [number , number | null]) => void;
@@ -464,6 +465,7 @@ type ZarrState = {
464465
ReFetch: () => void;
465466
setCurrentChunks: (currentChunks: {x:number[], y:number[], z:number[]}) => void;
466467
setArraySize: (arraySize: number) => void;
468+
setUseNC: (useNC: boolean) => void;
467469
}
468470

469471
export const useZarrStore = create<ZarrState>((set, get) => ({
@@ -475,6 +477,7 @@ export const useZarrStore = create<ZarrState>((set, get) => ({
475477
reFetch: false,
476478
currentChunks: {x:[], y:[], z:[]},
477479
arraySize: 0,
480+
useNC: false,
478481

479482
setZSlice: (zSlice) => set({ zSlice }),
480483
setYSlice: (ySlice) => set({ ySlice }),
@@ -484,7 +487,8 @@ export const useZarrStore = create<ZarrState>((set, get) => ({
484487
setReFetch: (reFetch) => set({ reFetch }),
485488
ReFetch: () => set({ reFetch: !get().reFetch }),
486489
setCurrentChunks: (currentChunks) => set({ currentChunks }),
487-
setArraySize: (arraySize) => set({ arraySize })
490+
setArraySize: (arraySize) => set({ arraySize }),
491+
setUseNC: (useNC) => set({ useNC })
488492
}))
489493

490494
type CacheState = {

0 commit comments

Comments
 (0)