Remove theme and locale from instance settings to eliminate duplication and simplify the codebase. These are user-specific preferences and should only exist in user settings, not instance-wide settings. Backend changes: - Remove theme from InstanceGeneralSetting proto - Remove locale from InstanceCustomProfile proto - Update instance service converters to remove theme/locale handling - Simplify RSS feed to use static locale Frontend changes: - Remove theme/locale from instanceStore state - Create unified initialization flow with clear fallback priority: * Theme: user setting → localStorage → system preference * Locale: user setting → browser language - Add applyUserPreferences() to centralize theme/locale application - Simplify App.tsx by removing redundant state synchronization - Update all components to use new helper functions: * getThemeWithFallback() for theme resolution * getLocaleWithFallback() for locale resolution - Remove theme/locale selectors from instance profile dialog Theme utilities refactor: - Organize code into clear sections with JSDoc comments - Extract localStorage operations into getStoredTheme/setStoredTheme helpers - Split DOM manipulation into focused functions - Improve type safety with Theme and ResolvedTheme types - Reduce code duplication and improve maintainability 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
88 lines
3.4 KiB
TypeScript
88 lines
3.4 KiB
TypeScript
import { observer } from "mobx-react-lite";
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
|
import i18n from "@/i18n";
|
|
import { userStore } from "@/store";
|
|
import { Visibility } from "@/types/proto/api/v1/memo_service";
|
|
import { UserSetting_GeneralSetting } from "@/types/proto/api/v1/user_service";
|
|
import { useTranslate } from "@/utils/i18n";
|
|
import { convertVisibilityFromString, convertVisibilityToString } from "@/utils/memo";
|
|
import { loadTheme } from "@/utils/theme";
|
|
import LocaleSelect from "../LocaleSelect";
|
|
import ThemeSelect from "../ThemeSelect";
|
|
import VisibilityIcon from "../VisibilityIcon";
|
|
import SettingGroup from "./SettingGroup";
|
|
import SettingRow from "./SettingRow";
|
|
import SettingSection from "./SettingSection";
|
|
import WebhookSection from "./WebhookSection";
|
|
|
|
const PreferencesSection = observer(() => {
|
|
const t = useTranslate();
|
|
const generalSetting = userStore.state.userGeneralSetting;
|
|
|
|
const handleLocaleSelectChange = async (locale: Locale) => {
|
|
// Apply locale immediately for instant UI feedback
|
|
i18n.changeLanguage(locale);
|
|
// Persist to user settings
|
|
await userStore.updateUserGeneralSetting({ locale }, ["locale"]);
|
|
};
|
|
|
|
const handleDefaultMemoVisibilityChanged = async (value: string) => {
|
|
await userStore.updateUserGeneralSetting({ memoVisibility: value }, ["memoVisibility"]);
|
|
};
|
|
|
|
const handleThemeChange = async (theme: string) => {
|
|
// Apply theme immediately for instant UI feedback
|
|
loadTheme(theme);
|
|
// Persist to user settings
|
|
await userStore.updateUserGeneralSetting({ theme }, ["theme"]);
|
|
};
|
|
|
|
// Provide default values if setting is not loaded yet
|
|
const setting: UserSetting_GeneralSetting = generalSetting || {
|
|
locale: "en",
|
|
memoVisibility: "PRIVATE",
|
|
theme: "system",
|
|
};
|
|
|
|
return (
|
|
<SettingSection>
|
|
<SettingGroup title={t("common.basic")}>
|
|
<SettingRow label={t("common.language")}>
|
|
<LocaleSelect value={setting.locale} onChange={handleLocaleSelectChange} />
|
|
</SettingRow>
|
|
|
|
<SettingRow label={t("setting.preference-section.theme")}>
|
|
<ThemeSelect value={setting.theme} onValueChange={handleThemeChange} />
|
|
</SettingRow>
|
|
</SettingGroup>
|
|
|
|
<SettingGroup title={t("setting.preference")} showSeparator>
|
|
<SettingRow label={t("setting.preference-section.default-memo-visibility")}>
|
|
<Select value={setting.memoVisibility} onValueChange={handleDefaultMemoVisibilityChanged}>
|
|
<SelectTrigger className="min-w-fit">
|
|
<div className="flex items-center gap-2">
|
|
<VisibilityIcon visibility={convertVisibilityFromString(setting.memoVisibility)} />
|
|
<SelectValue />
|
|
</div>
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{[Visibility.PRIVATE, Visibility.PROTECTED, Visibility.PUBLIC]
|
|
.map((v) => convertVisibilityToString(v))
|
|
.map((item) => (
|
|
<SelectItem key={item} value={item} className="whitespace-nowrap">
|
|
{t(`memo.visibility.${item.toLowerCase() as Lowercase<typeof item>}`)}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</SettingRow>
|
|
</SettingGroup>
|
|
|
|
<SettingGroup showSeparator>
|
|
<WebhookSection />
|
|
</SettingGroup>
|
|
</SettingSection>
|
|
);
|
|
});
|
|
|
|
export default PreferencesSection;
|