-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add drop zone, change bundler chunks
- Loading branch information
Showing
7 changed files
with
148 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,82 @@ | ||
import { cn } from '@/ui/utils/cn.ts'; | ||
import { memo } from 'react'; | ||
import { faFileCode } from '@fortawesome/free-regular-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { Group, Text } from '@mantine/core'; | ||
import { Dropzone } from '@mantine/dropzone'; | ||
import { memo, useCallback, useEffect } from 'react'; | ||
import type { FileWithPath } from 'react-dropzone-esm'; | ||
import { recoverySchema } from '../models/recovery.model.ts'; | ||
|
||
export const RecoveryImportPage = memo(() => { | ||
return <div className={cn(`flex flex-col gap-4`)}>Work is in progress</div>; | ||
const processExportFile = ({ currentTarget }: ProgressEvent<FileReader>) => { | ||
if (!currentTarget) { | ||
throw new Error(`currentTarget is missing`); | ||
} | ||
|
||
const { result } = currentTarget as FileReader; | ||
if (typeof result !== 'string') { | ||
throw new Error(`type of result should be string`); | ||
} | ||
|
||
// TODO validate dbVersion | ||
const { dbVersion, subscriptions } = recoverySchema.parse( | ||
JSON.parse(result), | ||
); | ||
console.log(dbVersion, subscriptions); | ||
}; | ||
|
||
useEffect(() => { | ||
reader.addEventListener('load', processExportFile); | ||
|
||
return () => { | ||
reader.removeEventListener('load', processExportFile); | ||
}; | ||
}); | ||
|
||
const readExportFile = useCallback( | ||
([file]: Array<FileWithPath>) => file && reader.readAsText(file), | ||
[], | ||
); | ||
|
||
return ( | ||
<div className={cn(`flex flex-col gap-4`)}> | ||
<Dropzone | ||
onDrop={readExportFile} | ||
multiple={false} | ||
accept={['application/json']}> | ||
<Group | ||
justify="center" | ||
gap="xl" | ||
mih={220} | ||
style={{ pointerEvents: 'none' }}> | ||
<Dropzone.Idle> | ||
<FontAwesomeIcon | ||
style={{ | ||
color: 'var(--mantine-color-dimmed)', | ||
}} | ||
size="4x" | ||
icon={faFileCode} | ||
/> | ||
</Dropzone.Idle> | ||
|
||
<div> | ||
<Text | ||
size="xl" | ||
inline> | ||
Drag file here or click to select it | ||
</Text> | ||
<Text | ||
size="sm" | ||
c="dimmed" | ||
inline | ||
mt={7}> | ||
Attach one file of JSON format | ||
</Text> | ||
</div> | ||
</Group> | ||
</Dropzone> | ||
</div> | ||
); | ||
}); | ||
|
||
const reader = new FileReader(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters