Standardization
This commit is contained in:
@@ -7,7 +7,7 @@ import { useMutationAPI } from './useAPI';
|
||||
|
||||
export function useCommonHooks() {
|
||||
const { mutateAsync } = useMutationAPI();
|
||||
const isMobile = window.matchMedia('(max-width: 600px)').matches;
|
||||
const isMobile = globalThis.matchMedia('(max-width: 600px)').matches;
|
||||
const [theme, setTheme] = useAtom<Theme>(appTheme);
|
||||
const [themeName, setThemeName] = useLocalStorage<string>({
|
||||
key: 'theme',
|
||||
@@ -109,12 +109,12 @@ export function useCommonHooks() {
|
||||
});
|
||||
|
||||
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_]*)?$',
|
||||
String.raw`^(https?:\/\/)?` +
|
||||
String.raw`((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|` +
|
||||
String.raw`((\d{1,3}\.){3}\d{1,3}))` +
|
||||
String.raw`(\:\d+)?(\/[-a-z\d%_.~+]*)*` +
|
||||
String.raw`(\?[;&a-z\d%_.~+=-]*)?` +
|
||||
String.raw`(\#[-a-z\d_]*)?$`,
|
||||
'i',
|
||||
);
|
||||
|
||||
@@ -152,8 +152,8 @@ export function useCommonHooks() {
|
||||
mutateAsync({ method: 'DELETE', endpoint: endpoint, body: item });
|
||||
};
|
||||
|
||||
const filter = (selectedTheme?: Theme) => {
|
||||
if (selectedTheme && selectedTheme.appShadowsEnabled === 1) {
|
||||
const iconFilter = (selectedTheme?: Theme) => {
|
||||
if (selectedTheme?.appShadowsEnabled === 1) {
|
||||
return 'drop-shadow(2px 2px color-mix(in srgb, var(--mantine-color-accent-0), transparent 30%))';
|
||||
}
|
||||
if (!selectedTheme && theme.appShadowsEnabled === 1) {
|
||||
@@ -163,14 +163,14 @@ export function useCommonHooks() {
|
||||
return 'none';
|
||||
};
|
||||
|
||||
function fixDigits(k: number) {
|
||||
const fixDigits = (k: number) => {
|
||||
if (k < 10) {
|
||||
return `0${k}`;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
};
|
||||
|
||||
function getObjectDiff(original: any, current: any) {
|
||||
const getObjectDiff = (original: any, current: any) => {
|
||||
const changes: any = {};
|
||||
|
||||
// Check current object's properties
|
||||
@@ -210,14 +210,14 @@ export function useCommonHooks() {
|
||||
}
|
||||
|
||||
return Object.keys(changes).length === 0 ? null : changes;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
isMobile,
|
||||
theme,
|
||||
setTheme,
|
||||
urlPattern,
|
||||
filter,
|
||||
iconFilter,
|
||||
fixDigits,
|
||||
reorder,
|
||||
getObjectDiff,
|
||||
|
||||
Reference in New Issue
Block a user