From 4e11388086c7a16bd164875caf1b4d9197dd0d2d Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Thu, 18 Aug 2022 15:36:54 +0200 Subject: [PATCH] Fixed import --- components/contexts/GroupProvider.tsx | 16 ++++++++++------ components/home/Home.tsx | 26 +++----------------------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/components/contexts/GroupProvider.tsx b/components/contexts/GroupProvider.tsx index 7ff2bf6..d18b554 100644 --- a/components/contexts/GroupProvider.tsx +++ b/components/contexts/GroupProvider.tsx @@ -7,7 +7,8 @@ import { fixedEncodeURIComponent } from '../../src/utils' import { GroupRenameBody, GroupSetFactoryArrayBody, - SetFactoryArrayBody + SetFactoryArrayBody, + UploadDataBody } from '../../src/types/ApiSchemasFrontend' import { NextRouter, useRouter } from 'next/router' @@ -257,16 +258,19 @@ export const GroupProvider: FC = ({ children, id, initial }) => { }, [basicValues, excludedSuggestions, groups]) const load = useCallback( - (compressed: Uint8Array) => { + async (compressed: Uint8Array) => { // const atob = (str: string) => Buffer.from(str, 'base64') const uncompressed = pako.inflate(compressed, { to: 'string' }) const value: StoredFile = JSON.parse(uncompressed) if (!value.groups || !value.basicValues || !value.excludedSuggestions) return - setGroups(value.groups) - setBasicValues(value.basicValues) - setExcludedSuggestions(value.excludedSuggestions) + await postFetchJson(router, `/api/${router.query.id}/upload`, { + groups: value.groups, + ignored: value.excludedSuggestions, + base: value.basicValues + } as UploadDataBody) + router.reload() }, - [setBasicValues, setExcludedSuggestions] + [router] ) const value: GroupContextType = useMemo( diff --git a/components/home/Home.tsx b/components/home/Home.tsx index a9d0f0a..03f96f1 100644 --- a/components/home/Home.tsx +++ b/components/home/Home.tsx @@ -4,26 +4,17 @@ import styles from './Home.module.css' import { useFactories } from '../../src/hooks/useFactories' import { EnrichedEntity } from '../../src/types' import { EntitySpan } from './EntitySpan/EntitySpan' -import { postFetchJson, useGroups } from '../contexts/GroupProvider' +import { useGroups } from '../contexts/GroupProvider' import { Preferences } from './Preferences/Preferences' import { download, streamToArrayBuffer } from '../../src/download' import Link from 'next/link' import { useRouter } from 'next/router' -import { UploadDataBody } from '../../src/types/ApiSchemasFrontend' export const Home: FC = () => { const router = useRouter() const { factories } = useFactories() - const { - groups, - addGroup, - doNotSuggest, - baseFactories, - ignoredFactories, - setIgnoredFactories, - store, - load - } = useGroups() + const { groups, addGroup, doNotSuggest, ignoredFactories, setIgnoredFactories, store, load } = + useGroups() const [newGroupValue, setNewGroupValue] = useState('New group') const inputRef = useRef(null) @@ -49,17 +40,6 @@ export const Home: FC = () => { > Store -