Added git hooks
This commit is contained in:
4
.husky/pre-commit
Executable file
4
.husky/pre-commit
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
. "$(dirname "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
yarn run lint-staged
|
||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
GroupSetFactoryArrayBody,
|
GroupSetFactoryArrayBody,
|
||||||
SetFactoryArrayBody
|
SetFactoryArrayBody
|
||||||
} from '../../src/types/ApiSchemasFrontend'
|
} from '../../src/types/ApiSchemasFrontend'
|
||||||
import {NextRouter, useRouter} from 'next/router'
|
import { NextRouter, useRouter } from 'next/router'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children: ReactNodeLike
|
children: ReactNodeLike
|
||||||
@@ -93,7 +93,7 @@ interface StoredFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const postFetchJson = async (router: NextRouter, url: string, body: unknown) => {
|
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',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@@ -129,7 +129,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
|||||||
factories: val
|
factories: val
|
||||||
} as SetFactoryArrayBody).catch(console.error)
|
} as SetFactoryArrayBody).catch(console.error)
|
||||||
},
|
},
|
||||||
[id]
|
[id, router]
|
||||||
)
|
)
|
||||||
|
|
||||||
const setBasicValues = useCallback<typeof _setBasicValues>(
|
const setBasicValues = useCallback<typeof _setBasicValues>(
|
||||||
@@ -140,7 +140,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
|||||||
factories: val
|
factories: val
|
||||||
} as SetFactoryArrayBody).catch(console.error)
|
} as SetFactoryArrayBody).catch(console.error)
|
||||||
},
|
},
|
||||||
[id]
|
[id, router]
|
||||||
)
|
)
|
||||||
|
|
||||||
const addGroup = useCallback(
|
const addGroup = useCallback(
|
||||||
@@ -180,7 +180,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
|||||||
})().catch(console.error)
|
})().catch(console.error)
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
[groups, id]
|
[groups, id, router]
|
||||||
)
|
)
|
||||||
const removeGroup = useCallback(
|
const removeGroup = useCallback(
|
||||||
(name: string) => {
|
(name: string) => {
|
||||||
@@ -195,7 +195,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
|||||||
{}
|
{}
|
||||||
).catch(console.error)
|
).catch(console.error)
|
||||||
},
|
},
|
||||||
[id]
|
[id, router]
|
||||||
)
|
)
|
||||||
const renameGroup = useCallback(
|
const renameGroup = useCallback(
|
||||||
(name: string, newName: string) => {
|
(name: string, newName: string) => {
|
||||||
@@ -215,7 +215,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
|||||||
} as GroupRenameBody
|
} as GroupRenameBody
|
||||||
).catch(console.error)
|
).catch(console.error)
|
||||||
},
|
},
|
||||||
[groups, id]
|
[groups, id, router]
|
||||||
)
|
)
|
||||||
|
|
||||||
const setFactories = useCallback(
|
const setFactories = useCallback(
|
||||||
@@ -234,7 +234,7 @@ export const GroupProvider: FC<Props> = ({ children, id, initial }) => {
|
|||||||
} as GroupSetFactoryArrayBody
|
} as GroupSetFactoryArrayBody
|
||||||
).catch(console.error)
|
).catch(console.error)
|
||||||
},
|
},
|
||||||
[id]
|
[id, router]
|
||||||
)
|
)
|
||||||
const getInputType = useCallback(
|
const getInputType = useCallback(
|
||||||
(uid: string) => {
|
(uid: string) => {
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import styles from './Home.module.css'
|
|||||||
import { useFactories } from '../../src/hooks/useFactories'
|
import { useFactories } from '../../src/hooks/useFactories'
|
||||||
import { EnrichedEntity } from '../../src/types'
|
import { EnrichedEntity } from '../../src/types'
|
||||||
import { EntitySpan } from './EntitySpan/EntitySpan'
|
import { EntitySpan } from './EntitySpan/EntitySpan'
|
||||||
import {postFetchJson, useGroups} from '../contexts/GroupProvider'
|
import { postFetchJson, useGroups } from '../contexts/GroupProvider'
|
||||||
import { Preferences } from './Preferences/Preferences'
|
import { Preferences } from './Preferences/Preferences'
|
||||||
import { download, streamToArrayBuffer } from '../../src/download'
|
import { download, streamToArrayBuffer } from '../../src/download'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import {UploadDataBody} from '../../src/types/ApiSchemasFrontend'
|
import { UploadDataBody } from '../../src/types/ApiSchemasFrontend'
|
||||||
|
|
||||||
export const Home: FC = () => {
|
export const Home: FC = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -50,7 +50,13 @@ export const Home: FC = () => {
|
|||||||
Store
|
Store
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => postFetchJson(router, `/api/${router.query.id}/upload`, { groups, ignored: ignoredFactories, base: baseFactories } as UploadDataBody)}
|
onClick={() =>
|
||||||
|
postFetchJson(router, `/api/${router.query.id}/upload`, {
|
||||||
|
groups,
|
||||||
|
ignored: ignoredFactories,
|
||||||
|
base: baseFactories
|
||||||
|
} as UploadDataBody)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
Upload
|
Upload
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -2,16 +2,18 @@ import '../styles/globals.css'
|
|||||||
import type { AppProps } from 'next/app'
|
import type { AppProps } from 'next/app'
|
||||||
import { FC } from 'react'
|
import { FC } from 'react'
|
||||||
import Head from 'next/head'
|
import Head from 'next/head'
|
||||||
import {useRouter} from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
|
|
||||||
const MyApp: FC<AppProps> = ({ Component, pageProps }) => {
|
const MyApp: FC<AppProps> = ({ Component, pageProps }) => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
return <>
|
return (
|
||||||
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
<link rel='icon' href={`${router.basePath}/favicon.ico`} />
|
<link rel='icon' href={`${router.basePath}/favicon.ico`} />
|
||||||
</Head>
|
</Head>
|
||||||
<Component {...pageProps} />
|
<Component {...pageProps} />
|
||||||
</>
|
</>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MyApp
|
export default MyApp
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { setData } from '../../../src/database/groups'
|
import { setData } from '../../../src/database/groups'
|
||||||
import { nextHandler } from '../../../src/utils/errors'
|
import { nextHandler } from '../../../src/utils/errors'
|
||||||
import { waitForInitSchemas } from '../../../src/validation/schemas'
|
import { waitForInitSchemas } from '../../../src/validation/schemas'
|
||||||
import {validate} from '../../../src/validation'
|
import { validate } from '../../../src/validation'
|
||||||
import {IdParam, UploadDataBody} from '../../../src/types/ApiSchemas'
|
import { IdParam, UploadDataBody } from '../../../src/types/ApiSchemas'
|
||||||
|
|
||||||
const handler = nextHandler(async (req, res) => {
|
const handler = nextHandler(async (req, res) => {
|
||||||
if (req.method !== 'POST') throw new Error('Invalid method')
|
if (req.method !== 'POST') throw new Error('Invalid method')
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ export type InsertMeta<T> = T & {
|
|||||||
|
|
||||||
type GroupFilter = Filter<InsertMeta<GroupData>>
|
type GroupFilter = Filter<InsertMeta<GroupData>>
|
||||||
|
|
||||||
export async function setData(uuid: string|undefined, data: GroupData): Promise<string | undefined> {
|
export async function setData(
|
||||||
|
uuid: string | undefined,
|
||||||
|
data: GroupData
|
||||||
|
): Promise<string | undefined> {
|
||||||
const collection = (await database.resolve())?.collection('setups')
|
const collection = (await database.resolve())?.collection('setups')
|
||||||
if (!collection) return
|
if (!collection) return
|
||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
|
|||||||
@@ -43,15 +43,16 @@ export function addSchemas() {
|
|||||||
type: 'object',
|
type: 'object',
|
||||||
required: ['groups', 'ignored', 'base'],
|
required: ['groups', 'ignored', 'base'],
|
||||||
properties: {
|
properties: {
|
||||||
groups: { type: 'object',
|
groups: {
|
||||||
|
type: 'object',
|
||||||
additionalProperties: {
|
additionalProperties: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: ['name', 'exports', 'malls'],
|
required: ['name', 'exports', 'malls'],
|
||||||
properties: {
|
properties: {
|
||||||
name: {type: 'string', minLength: 1},
|
name: { type: 'string', minLength: 1 },
|
||||||
exports: {type: 'array', items: {type: 'string', minLength: 3}},
|
exports: { type: 'array', items: { type: 'string', minLength: 3 } },
|
||||||
malls: {type: 'array', items: {type: 'string', minLength: 3}}
|
malls: { type: 'array', items: { type: 'string', minLength: 3 } }
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ignored: { type: 'array', items: { type: 'string', minLength: 3 } },
|
ignored: { type: 'array', items: { type: 'string', minLength: 3 } },
|
||||||
|
|||||||
Reference in New Issue
Block a user