Initial commit: Complete NodeJS-native setup

- Migrated from Python pre-commit to NodeJS-native solution
- Reorganized documentation structure
- Set up Husky + lint-staged for efficient pre-commit hooks
- Fixed Dockerfile healthcheck issue
- Added comprehensive documentation index
This commit is contained in:
William Valentin
2025-09-06 01:42:48 -07:00
commit e48adbcb00
159 changed files with 24405 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
// FIX: This file was empty. Added a standard implementation for the useLocalStorage hook.
import { useState, useEffect, Dispatch, SetStateAction } from 'react';
function getStoredValue<T>(key: string, defaultValue: T): T {
if (typeof window === 'undefined') {
return defaultValue;
}
const saved = localStorage.getItem(key);
try {
return saved ? JSON.parse(saved) : defaultValue;
} catch (e) {
return defaultValue;
}
}
export function useLocalStorage<T>(
key: string,
defaultValue: T
): [T, Dispatch<SetStateAction<T>>] {
const [value, setValue] = useState<T>(() =>
getStoredValue(key, defaultValue)
);
useEffect(() => {
localStorage.setItem(key, JSON.stringify(value));
}, [key, value]);
return [value, setValue];
}
+50
View File
@@ -0,0 +1,50 @@
import { useState, useEffect } from 'react';
const useSettings = () => {
const [settings, setSettings] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
const fetchSettings = async () => {
try {
const response = await fetch('/api/settings');
const data = await response.json();
setSettings(data);
} catch (err) {
setError(err);
} finally {
setLoading(false);
}
};
fetchSettings();
}, []);
const updateSettings = async newSettings => {
try {
const response = await fetch('/api/settings', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(newSettings),
});
const data = await response.json();
setSettings(data);
return data;
} catch (err) {
setError(err);
throw err;
}
};
return {
settings,
loading,
error,
updateSettings,
};
};
export default useSettings;
+43
View File
@@ -0,0 +1,43 @@
import { useEffect, useMemo } from 'react';
import { useLocalStorage } from './useLocalStorage';
type Theme = 'light' | 'dark' | 'system';
export function useTheme() {
const [theme, setTheme] = useLocalStorage<Theme>('theme', 'system');
const systemTheme = useMemo(() => {
if (typeof window !== 'undefined' && window.matchMedia) {
return window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light';
}
return 'light';
}, []);
const applyTheme = () => {
const themeToApply = theme === 'system' ? systemTheme : theme;
const root = window.document.documentElement;
root.classList.remove('light', 'dark');
root.classList.add(themeToApply);
};
useEffect(() => {
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
const handleChange = () => {
if (theme === 'system') {
applyTheme();
}
};
mediaQuery.addEventListener('change', handleChange);
return () => mediaQuery.removeEventListener('change', handleChange);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [theme]);
useEffect(() => {
applyTheme();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [theme, systemTheme]);
return { theme, setTheme };
}
+31
View File
@@ -0,0 +1,31 @@
import { useState, useEffect } from 'react';
const useUserData = () => {
const [userData, setUserData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
const fetchUserData = async () => {
try {
const response = await fetch('/api/user/profile');
const data = await response.json();
setUserData(data);
} catch (err) {
setError(err);
} finally {
setLoading(false);
}
};
fetchUserData();
}, []);
return {
userData,
loading,
error,
};
};
export default useUserData;