- Add local Persian fonts: Vazirmatn, Sahel, Shabnam, Lalezar, IranNastaliq - Configure @font-face in globals.css with all font weights - Set Vazirmatn as primary font, Lalezar for headings, Sahel for alt text - Fix Hero image loading with crossOrigin and error fallback - Fix SmartAdvisor disabled button contrast (WCAG compliance) - Add visible labels for form inputs in SmartAdvisor step 1 - Fix UserDashboard null safety for walletBalance - Fix announcement bar hydration mismatch (loading state guard) - Fix UserDashboard null checks for profile fields - Improve overall frontend robustness and data-loading guards
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
"use client";
|
|
import { create } from "zustand";
|
|
import api from "../services/api";
|
|
|
|
export interface ScientificTerm {
|
|
key: string;
|
|
term: string;
|
|
definition: string;
|
|
wikiId: string;
|
|
}
|
|
|
|
interface SettingsStore {
|
|
texts: Record<string, string>;
|
|
scientificTerms: Record<string, ScientificTerm>;
|
|
isLoading: boolean;
|
|
isInitialized: boolean;
|
|
fetchSettings: () => Promise<void>;
|
|
getText: (key: string, fallback: string) => string;
|
|
}
|
|
|
|
export const useSettingsStore = create<SettingsStore>()((set, get) => ({
|
|
texts: {},
|
|
scientificTerms: {},
|
|
isLoading: false,
|
|
isInitialized: false,
|
|
fetchSettings: async () => {
|
|
set({ isLoading: true });
|
|
try {
|
|
const [textsRes, termsRes] = await Promise.all([
|
|
api.get('/settings/ui-texts'),
|
|
api.get('/settings/scientific-terms'),
|
|
]);
|
|
|
|
const textsObj: Record<string, string> = {};
|
|
if (Array.isArray(textsRes.data)) {
|
|
textsRes.data.forEach((item: { key: string; value: string }) => {
|
|
textsObj[item.key] = item.value;
|
|
});
|
|
}
|
|
|
|
const termsObj: Record<string, ScientificTerm> = {};
|
|
if (Array.isArray(termsRes.data)) {
|
|
termsRes.data.forEach((item: ScientificTerm) => {
|
|
termsObj[item.key] = item;
|
|
});
|
|
}
|
|
|
|
set({ texts: textsObj, scientificTerms: termsObj });
|
|
} catch (error) {
|
|
console.error("Failed to fetch settings/ui-texts:", error);
|
|
} finally {
|
|
set({ isLoading: false, isInitialized: true });
|
|
}
|
|
},
|
|
getText: (key, fallback) => {
|
|
const value = get().texts[key];
|
|
if (value === undefined || value === null) {
|
|
return fallback;
|
|
}
|
|
return value;
|
|
}
|
|
}));
|