refactor: remove all legacy files

+ comment/delete things that haven't yet migrated to mantine
This commit is contained in:
Sonny
2024-11-07 00:29:58 +01:00
committed by Sonny
parent 861906d29b
commit 5c37fe9c31
148 changed files with 469 additions and 4728 deletions

View File

@@ -1,22 +0,0 @@
import { RefObject, useEffect } from 'react';
// Source : https://stackoverflow.com/a/63359693
/**
* This Hook can be used for detecting clicks outside the Opened Menu
*/
export default function useClickOutside(
ref: RefObject<HTMLElement>,
onClickOutside: () => void
) {
useEffect(() => {
function handleClickOutside(event: MouseEvent) {
if (ref?.current && !ref.current?.contains(event.target as any)) {
onClickOutside();
}
}
document.addEventListener('mousedown', handleClickOutside);
return () => document.removeEventListener('mousedown', handleClickOutside);
}, [ref, onClickOutside]);
}

View File

@@ -1,5 +0,0 @@
import { useContext } from 'react';
import { DarkThemeContext } from '~/contexts/dark_theme_context';
const useDarkTheme = () => useContext(DarkThemeContext);
export default useDarkTheme;

View File

@@ -1,5 +0,0 @@
import { useContext } from 'react';
import FavoritesContext from '~/contexts/favorites_context';
const useFavorites = () => useContext(FavoritesContext);
export default useFavorites;

View File

@@ -1,5 +0,0 @@
import { useContext } from 'react';
import GlobalHotkeysContext from '~/contexts/global_hotkeys_context';
const useGlobalHotkeys = () => useContext(GlobalHotkeysContext);
export default useGlobalHotkeys;

View File

@@ -1,8 +0,0 @@
const MOBILE_SCREEN_SIZE = 768;
export default function useIsMobile() {
return (
typeof window !== 'undefined' &&
window.matchMedia(`screen and (max-width: ${MOBILE_SCREEN_SIZE}px)`).matches
);
}

View File

@@ -1,30 +0,0 @@
import { useState } from 'react';
export function useLocalStorage(key: string, initialValue: any) {
const [storedValue, setStoredValue] = useState(() => {
if (typeof window === 'undefined') {
return initialValue;
}
try {
const item = window.localStorage.getItem(key);
return item ? JSON.parse(item) : initialValue;
} catch (error) {
console.log(error);
return initialValue;
}
});
const setValue = (value: any) => {
try {
const valueToStore =
value instanceof Function ? value(storedValue) : value;
setStoredValue(valueToStore);
if (typeof window !== 'undefined') {
window.localStorage.setItem(key, JSON.stringify(valueToStore));
}
} catch (error) {
console.log(error);
}
};
return [storedValue, setValue];
}

View File

@@ -1,18 +0,0 @@
import { useState } from 'react';
const useToggle = (defaultValue: boolean = false) => {
const [isShowing, setIsShowing] = useState<boolean>(defaultValue);
const toggle = () => setIsShowing((value) => !value);
const open = () => setIsShowing(true);
const close = () => setIsShowing(false);
return {
isShowing,
toggle,
open,
close,
};
};
export default useToggle;

View File

@@ -1,24 +0,0 @@
import { useEffect, useState } from 'react';
export function useMediaQuery(query: string): boolean {
const [matches, setMatches] = useState<boolean>(false);
const handleMediaChange = () => setMatches(getMediaMatches(query));
useEffect(() => {
const matchMedia = window.matchMedia(query);
handleMediaChange();
matchMedia.addEventListener('change', handleMediaChange);
return () => matchMedia.removeEventListener('change', handleMediaChange);
}, [query]);
return matches;
}
function getMediaMatches(query: string): boolean {
if (typeof window !== 'undefined') {
return window.matchMedia(query).matches;
}
return false;
}

View File

@@ -1,9 +0,0 @@
import { Theme } from '@emotion/react';
import { useMediaQuery } from '~/hooks/viewport/use_media_query';
import { media } from '~/styles/media_queries';
type ScreenTypes = keyof Theme['media'];
const useScreenType = (screen: ScreenTypes) =>
useMediaQuery(`(max-width: ${media[screen]})`);
export default useScreenType;