Clean up and typing

This commit is contained in:
Sean Edmunds
2025-03-27 16:22:34 -05:00
parent b46d89721e
commit 67293b20ca
47 changed files with 450 additions and 540 deletions

View File

@@ -2,8 +2,10 @@ import { useLocalStorage } from '@mantine/hooks';
import { appTheme } from 'contexts';
import { useAtom } from 'jotai';
import { useState } from 'react';
import { useMutationAPI } from './useAPI';
export function useCommonHooks() {
const { mutateAsync } = useMutationAPI();
const isMobile = window.matchMedia('(max-width: 600px)').matches;
const [theme, setTheme] = useAtom(appTheme);
const [themeName, setThemeName] = useLocalStorage<any>({
@@ -51,6 +53,25 @@ export function useCommonHooks() {
},
});
const modalStyle = {
'--color-text-pri': theme.primaryColor,
'--color-text-acc': theme.accentColor,
'--color-background': theme.backgroundColor,
'--color-border': theme.borderColor,
'--color-search-background': theme.searchColor,
'--image-background': `url(${theme.backgroundImage})`,
};
const urlPattern = new RegExp(
'^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$',
'i',
); // fragment locator
const handleThemeChange = (themes: any, save: any) => {
const enabled = themes
.filter((t: any) => t.randomEnabled)
@@ -69,11 +90,26 @@ export function useCommonHooks() {
}
};
const handleDelete = (item: any, endpoint: any) => {
mutateAsync({ method: 'DELETE', endpoint: endpoint, body: item });
};
function fixDigits(k: any) {
if (k < 10) {
return `0${k}`;
}
return k;
}
return {
isMobile,
theme,
setTheme,
modalStyle,
urlPattern,
fixDigits,
handleThemeChange,
handleDelete,
themeName,
setThemeName,
appFilter,