mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 23:15:36 +00:00
refactor: remove all legacy files
+ comment/delete things that haven't yet migrated to mantine
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { useContext } from 'react';
|
||||
import { DarkThemeContext } from '~/contexts/dark_theme_context';
|
||||
|
||||
const useDarkTheme = () => useContext(DarkThemeContext);
|
||||
export default useDarkTheme;
|
||||
@@ -1,5 +0,0 @@
|
||||
import { useContext } from 'react';
|
||||
import FavoritesContext from '~/contexts/favorites_context';
|
||||
|
||||
const useFavorites = () => useContext(FavoritesContext);
|
||||
export default useFavorites;
|
||||
@@ -1,5 +0,0 @@
|
||||
import { useContext } from 'react';
|
||||
import GlobalHotkeysContext from '~/contexts/global_hotkeys_context';
|
||||
|
||||
const useGlobalHotkeys = () => useContext(GlobalHotkeysContext);
|
||||
export default useGlobalHotkeys;
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user