11"use client" ;
2- import React , { ChangeEvent } from 'react'
2+ import React , { ChangeEvent , useState } from 'react'
33import { Input } from '../input'
44import { useGlobalStore , useZarrStore } from '@/utils/GlobalStates' ;
55import { NetCDF4 } from '@earthyscience/netcdf4-wasm' ;
6-
6+ import {
7+ Alert ,
8+ AlertDescription ,
9+ AlertTitle ,
10+ } from '@/components/ui/alert' ;
711
812interface LocalNCType {
913 setShowLocal : React . Dispatch < React . SetStateAction < boolean > > ;
1014 setOpenVariables : React . Dispatch < React . SetStateAction < boolean > > ;
1115}
1216
17+ const NETCDF_EXT_REGEX = / \. ( n c | n e t c d f | n c 3 | n c 4 ) $ / i;
18+
1319const LocalNetCDF = ( { setOpenVariables} :LocalNCType ) => {
1420 const { setStatus } = useGlobalStore . getState ( )
1521 const { ncModule} = useZarrStore . getState ( )
22+ const [ ncError , setError ] = useState < string | null > ( null ) ;
1623
1724 const handleFileSelect = async ( event : ChangeEvent < HTMLInputElement > ) => {
25+ setError ( null ) ;
1826 const files = event . target . files ;
1927 if ( ! files || files . length === 0 ) {
2028 setStatus ( null )
2129 return ;
2230 }
2331 const file = files [ 0 ]
32+ // Manual validation (iOS-safe)
33+ if ( ! NETCDF_EXT_REGEX . test ( file . name ) ) {
34+ setError ( 'Please select a valid NetCDF (.nc, .netcdf, .nc3, .nc4) file.' ) ;
35+ return ;
36+ }
37+
2438 if ( ncModule ) ncModule . close ( ) ;
2539 setStatus ( "Loading..." )
2640 const data = await NetCDF4 . fromBlobLazy ( file )
@@ -47,9 +61,16 @@ const LocalNetCDF = ({ setOpenVariables}:LocalNCType) => {
4761 < Input type = "file" id = "filepicker"
4862 className = 'hover:drop-shadow-md hover:scale-[102%]'
4963 style = { { width :'200px' , cursor :'pointer' } }
50- accept = '.nc, .netcdf, .nc3, .nc4'
5164 onChange = { handleFileSelect }
5265 />
66+ { ncError && (
67+ < Alert variant = "destructive" className = 'border-0 mt-1' >
68+ < AlertTitle > Hey!</ AlertTitle >
69+ < AlertDescription >
70+ { ncError }
71+ </ AlertDescription >
72+ </ Alert >
73+ ) }
5374 </ div >
5475 )
5576}
0 commit comments