import { Button, Divider, TextField, Tooltip } from '@mui/material' import JSZip from 'jszip' import { useEffect, useRef, useState } from 'react' import { useNavigate } from 'react-router-dom' import { toast } from 'react-toastify' import { useAppSelector } from '../../hooks' import { appPrivateRoutes, appPublicRoutes } from '../../routes' import { Meta, ProfileMetadata } from '../../types' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faAdd, faFilter, faFilterCircleXmark, faSearch } from '@fortawesome/free-solid-svg-icons' import { Select } from '../../components/Select' import { DisplaySigit } from '../../components/DisplaySigit' import { Container } from '../../components/Container' import styles from './style.module.scss' // Unsupported Filter options are commented const FILTERS = [ 'Show all', // 'Drafts', 'In-progress', 'Completed' // 'Archived' ] as const type Filter = (typeof FILTERS)[number] const SORT_BY = [ { label: 'Newest', value: 'desc' }, { label: 'Oldest', value: 'asc' } ] as const type Sort = (typeof SORT_BY)[number]['value'] export const HomePage = () => { const navigate = useNavigate() const fileInputRef = useRef(null) const [sigits, setSigits] = useState([]) const [profiles, setProfiles] = useState<{ [key: string]: ProfileMetadata }>( {} ) const usersAppData = useAppSelector((state) => state.userAppData) useEffect(() => { if (usersAppData) { setSigits(Object.values(usersAppData.sigits)) } }, [usersAppData]) const handleUploadClick = () => { if (fileInputRef.current) { fileInputRef.current.click() } } const handleFileChange = async ( event: React.ChangeEvent ) => { const file = event.target.files?.[0] if (file) { // Check if the file extension is .sigit.zip const fileName = file.name const fileExtension = fileName.slice(-10) // ".sigit.zip" has 10 characters if (fileExtension === '.sigit.zip') { const zip = await JSZip.loadAsync(file).catch((err) => { console.log('err in loading zip file :>> ', err) toast.error(err.message || 'An error occurred in loading zip file.') return null }) if (!zip) return // navigate to sign page if zip contains keys.json if ('keys.json' in zip.files) { return navigate(appPrivateRoutes.sign, { state: { uploadedZip: file } }) } // navigate to verify page if zip contains meta.json if ('meta.json' in zip.files) { return navigate(appPublicRoutes.verify, { state: { uploadedZip: file } }) } toast.error('Invalid zip file') return } // navigate to create page navigate(appPrivateRoutes.create, { state: { uploadedFile: file } }) } } const [filter, setFilter] = useState('Show all') const [isFilterVisible, setIsFilterVisible] = useState(true) const [sort, setSort] = useState('asc') return (
{isFilterVisible && ( <> { return { ...s } })} /> )}
Click or drag files to upload!
{sigits.map((sigit, index) => ( ))}
) }