Initial commit

This commit is contained in:
decolua
2026-01-05 09:58:59 +07:00
commit 3857598de4
159 changed files with 14537 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
// Shared Hooks - Export all
export { useTheme } from "./useTheme";

View File

@@ -0,0 +1,29 @@
"use client";
import { useState, useCallback, useRef } from "react";
/**
* Hook for copy to clipboard with feedback
* @param {number} resetDelay - Time in ms before resetting copied state (default: 2000)
* @returns {{ copied: string|null, copy: (text: string, id?: string) => void }}
*/
export function useCopyToClipboard(resetDelay = 2000) {
const [copied, setCopied] = useState(null);
const timeoutRef = useRef(null);
const copy = useCallback((text, id = "default") => {
navigator.clipboard.writeText(text);
setCopied(id);
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
timeoutRef.current = setTimeout(() => {
setCopied(null);
}, resetDelay);
}, [resetDelay]);
return { copied, copy };
}

View File

@@ -0,0 +1,31 @@
"use client";
import { useEffect } from "react";
import useThemeStore from "@/store/themeStore";
export function useTheme() {
const { theme, setTheme, toggleTheme, initTheme } = useThemeStore();
useEffect(() => {
initTheme();
// Listen for system theme changes
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
const handleChange = () => {
if (theme === "system") {
initTheme();
}
};
mediaQuery.addEventListener("change", handleChange);
return () => mediaQuery.removeEventListener("change", handleChange);
}, [theme, initTheme]);
return {
theme,
setTheme,
toggleTheme,
isDark: theme === "dark" || (theme === "system" && typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches),
};
}