chore: better Prettier config for easier reviews

This commit is contained in:
2023-10-23 23:33:39 +02:00
parent a8781724d4
commit 71ea41695f
209 changed files with 4093 additions and 4114 deletions

View File

@ -1,8 +1,8 @@
import { useEffect } from 'react'
import { useEffect } from "react"
export const useClickOutsideAlerter = (
ref: React.RefObject<HTMLElement>,
callback: () => void
callback: () => void,
): void => {
useEffect(() => {
const handleClickOutside = (event: MouseEvent): void => {
@ -14,9 +14,9 @@ export const useClickOutsideAlerter = (
callback()
}
}
document.addEventListener('mousedown', handleClickOutside)
document.addEventListener("mousedown", handleClickOutside)
return () => {
document.removeEventListener('mousedown', handleClickOutside)
document.removeEventListener("mousedown", handleClickOutside)
}
}, [ref, callback])
}

View File

@ -1,34 +1,34 @@
import useTranslation from 'next-translate/useTranslation'
import type { Error } from 'react-component-form'
import useTranslation from "next-translate/useTranslation"
import type { Error } from "react-component-form"
const knownErrorKeywords = ['minLength', 'maxLength', 'format']
const knownErrorKeywords = ["minLength", "maxLength", "format"]
const getErrorTranslationKey = (error: Error): string => {
if (knownErrorKeywords.includes(error?.keyword)) {
if (
error.keyword === 'minLength' &&
typeof error.data === 'string' &&
error.keyword === "minLength" &&
typeof error.data === "string" &&
error.data.length === 0
) {
return 'errors:required'
return "errors:required"
}
if (error.keyword === 'format') {
if (error.params['format'] === 'email') {
return 'errors:invalid-email'
if (error.keyword === "format") {
if (error.params["format"] === "email") {
return "errors:invalid-email"
}
return 'errors:invalid'
return "errors:invalid"
}
return `errors:${error.keyword}`
}
return 'errors:invalid'
return "errors:invalid"
}
export type GetErrorTranslation = (
error: Error | undefined
error: Error | undefined,
) => string | undefined
export type GetFirstErrorTranslation = (
errors: Error[] | undefined
errors: Error[] | undefined,
) => string | undefined
export interface UseFormTranslationResult {
@ -42,8 +42,8 @@ export const useFormTranslation = (): UseFormTranslationResult => {
const getErrorTranslation: GetErrorTranslation = (error) => {
if (error != null) {
return t(getErrorTranslationKey(error)).replace(
'{expected}',
error?.params?.['limit']
"{expected}",
error?.params?.["limit"],
)
}
return undefined

View File

@ -1,9 +1,9 @@
import { useState, useRef, useCallback } from 'react'
import type { AxiosInstance } from 'axios'
import type { FetchState } from 'react-component-form'
import { useState, useRef, useCallback } from "react"
import type { AxiosInstance } from "axios"
import type { FetchState } from "react-component-form"
import type { CacheKey } from '../tools/cache'
import { getPaginationCache, savePaginationCache } from '../tools/cache'
import type { CacheKey } from "../tools/cache"
import { getPaginationCache, savePaginationCache } from "../tools/cache"
export interface Query {
[key: string]: string
@ -33,28 +33,28 @@ export interface UsePaginationResult<T> {
}
export const usePagination = <T extends PaginationItem>(
options: UsePaginationOptions
options: UsePaginationOptions,
): UsePaginationResult<T> => {
const { api, url, inverse = false, cacheKey } = options
const [items, setItems] = useState<T[]>([])
const [hasMore, setHasMore] = useState(true)
const fetchState = useRef<FetchState>('idle')
const fetchState = useRef<FetchState>("idle")
const afterId = useRef<number | null>(null)
const nextPageAsync: NextPageAsync = useCallback(
async (query) => {
if (fetchState.current !== 'idle') {
if (fetchState.current !== "idle") {
return
}
fetchState.current = 'loading'
fetchState.current = "loading"
const searchParameters = new URLSearchParams(query)
searchParameters.append('limit', '20')
searchParameters.append("limit", "20")
if (afterId.current != null) {
searchParameters.append('after', afterId.current.toString())
searchParameters.append("after", afterId.current.toString())
}
const { data: newItems } = await api.get<T[]>(
`${url}?${searchParameters.toString()}`
`${url}?${searchParameters.toString()}`,
)
if (!inverse) {
const endIndex = newItems.length - 1
@ -84,9 +84,9 @@ export const usePagination = <T extends PaginationItem>(
return unique
})
setHasMore(newItems.length > 0)
fetchState.current = 'idle'
fetchState.current = "idle"
},
[api, url, inverse, cacheKey]
[api, url, inverse, cacheKey],
)
const nextPage: NextPage = useCallback(
@ -101,7 +101,7 @@ export const usePagination = <T extends PaginationItem>(
console.error(error)
})
},
[nextPageAsync]
[nextPageAsync],
)
const resetPagination = useCallback((): void => {
@ -109,7 +109,7 @@ export const usePagination = <T extends PaginationItem>(
afterId.current = null
setItems([])
} else {
fetchState.current = 'loading'
fetchState.current = "loading"
const newItems = getPaginationCache<T>(cacheKey)
setItems(newItems)
if (!inverse) {
@ -121,7 +121,7 @@ export const usePagination = <T extends PaginationItem>(
afterId.current =
newItems.length > 0 && newItems[0] != null ? newItems[0].id : null
}
fetchState.current = 'idle'
fetchState.current = "idle"
}
}, [cacheKey, inverse])