feat: add collection

This commit is contained in:
2025-07-31 15:41:15 +08:00
parent 1e5b12f531
commit 08c70a0b52
38 changed files with 1079 additions and 418 deletions

View File

@@ -0,0 +1,24 @@
export class Debounce {
private timer: number | null = null;
private readonly delay: number;
constructor(delay: number) {
this.delay = delay;
}
run(callback: () => void) {
if (this.timer) {
clearTimeout(this.timer);
}
this.timer = setTimeout(() => {
callback();
}, this.delay);
}
cancel() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
}

View File

@@ -0,0 +1,19 @@
import { createContext, useContext } from "react";
function t(data: any, language: string) {
return (key: string) => {
return data[language]?.["translation"]?.[key] || key;
};
}
export const i18nContext = createContext<any>({});
export function useTranslation() {
const data = useContext(i18nContext);
const userLang = navigator.language;
console.log("Using language:", userLang);
return {
t: t(data, userLang),
};
}