diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..f23377e --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +yarn run lint-staged diff --git a/components/contexts/GroupProvider.tsx b/components/contexts/GroupProvider.tsx index eaefb84..7ff2bf6 100644 --- a/components/contexts/GroupProvider.tsx +++ b/components/contexts/GroupProvider.tsx @@ -9,7 +9,7 @@ import { GroupSetFactoryArrayBody, SetFactoryArrayBody } from '../../src/types/ApiSchemasFrontend' -import {NextRouter, useRouter} from 'next/router' +import { NextRouter, useRouter } from 'next/router' interface Props { children: ReactNodeLike @@ -93,7 +93,7 @@ interface StoredFile { } export const postFetchJson = async (router: NextRouter, url: string, body: unknown) => { - const res = await fetch(router.basePath+url, { + const res = await fetch(router.basePath + url, { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -129,7 +129,7 @@ export const GroupProvider: FC = ({ children, id, initial }) => { factories: val } as SetFactoryArrayBody).catch(console.error) }, - [id] + [id, router] ) const setBasicValues = useCallback( @@ -140,7 +140,7 @@ export const GroupProvider: FC = ({ children, id, initial }) => { factories: val } as SetFactoryArrayBody).catch(console.error) }, - [id] + [id, router] ) const addGroup = useCallback( @@ -180,7 +180,7 @@ export const GroupProvider: FC = ({ children, id, initial }) => { })().catch(console.error) return true }, - [groups, id] + [groups, id, router] ) const removeGroup = useCallback( (name: string) => { @@ -195,7 +195,7 @@ export const GroupProvider: FC = ({ children, id, initial }) => { {} ).catch(console.error) }, - [id] + [id, router] ) const renameGroup = useCallback( (name: string, newName: string) => { @@ -215,7 +215,7 @@ export const GroupProvider: FC = ({ children, id, initial }) => { } as GroupRenameBody ).catch(console.error) }, - [groups, id] + [groups, id, router] ) const setFactories = useCallback( @@ -234,7 +234,7 @@ export const GroupProvider: FC = ({ children, id, initial }) => { } as GroupSetFactoryArrayBody ).catch(console.error) }, - [id] + [id, router] ) const getInputType = useCallback( (uid: string) => { diff --git a/components/home/Home.tsx b/components/home/Home.tsx index 4fabe61..a9d0f0a 100644 --- a/components/home/Home.tsx +++ b/components/home/Home.tsx @@ -4,12 +4,12 @@ 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 { postFetchJson, 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' +import { UploadDataBody } from '../../src/types/ApiSchemasFrontend' export const Home: FC = () => { const router = useRouter() @@ -50,7 +50,13 @@ export const Home: FC = () => { Store diff --git a/pages/_app.tsx b/pages/_app.tsx index 8934ec1..e06af82 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -2,16 +2,18 @@ import '../styles/globals.css' import type { AppProps } from 'next/app' import { FC } from 'react' import Head from 'next/head' -import {useRouter} from 'next/router' +import { useRouter } from 'next/router' const MyApp: FC = ({ Component, pageProps }) => { const router = useRouter() - return <> - - - - - + return ( + <> + + + + + + ) } export default MyApp diff --git a/pages/api/[id]/upload.ts b/pages/api/[id]/upload.ts index a858f26..3f4fbba 100644 --- a/pages/api/[id]/upload.ts +++ b/pages/api/[id]/upload.ts @@ -1,8 +1,8 @@ import { setData } from '../../../src/database/groups' import { nextHandler } from '../../../src/utils/errors' import { waitForInitSchemas } from '../../../src/validation/schemas' -import {validate} from '../../../src/validation' -import {IdParam, UploadDataBody} from '../../../src/types/ApiSchemas' +import { validate } from '../../../src/validation' +import { IdParam, UploadDataBody } from '../../../src/types/ApiSchemas' const handler = nextHandler(async (req, res) => { if (req.method !== 'POST') throw new Error('Invalid method') diff --git a/src/database/groups.ts b/src/database/groups.ts index 05c8610..973ec0d 100644 --- a/src/database/groups.ts +++ b/src/database/groups.ts @@ -16,7 +16,10 @@ export type InsertMeta = T & { type GroupFilter = Filter> -export async function setData(uuid: string|undefined, data: GroupData): Promise { +export async function setData( + uuid: string | undefined, + data: GroupData +): Promise { const collection = (await database.resolve())?.collection('setups') if (!collection) return if (!uuid) { diff --git a/src/validation/schemas.ts b/src/validation/schemas.ts index 791ced3..1b4d4e8 100644 --- a/src/validation/schemas.ts +++ b/src/validation/schemas.ts @@ -43,15 +43,16 @@ export function addSchemas() { type: 'object', required: ['groups', 'ignored', 'base'], properties: { - groups: { type: 'object', + groups: { + type: 'object', additionalProperties: { type: 'object', required: ['name', 'exports', 'malls'], properties: { - name: {type: 'string', minLength: 1}, - exports: {type: 'array', items: {type: 'string', minLength: 3}}, - malls: {type: 'array', items: {type: 'string', minLength: 3}} - }, + name: { type: 'string', minLength: 1 }, + exports: { type: 'array', items: { type: 'string', minLength: 3 } }, + malls: { type: 'array', items: { type: 'string', minLength: 3 } } + } } }, ignored: { type: 'array', items: { type: 'string', minLength: 3 } },