A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(app): add the themes settings tab shell and state
Hampus47cc4fe8fa3d
diff --git a/fluxer_app/src/features/theme_settings/ThemesTab.module.css b/fluxer_app/src/features/theme_settings/ThemesTab.module.cssnew file mode 100644index 000000000..13489702a--- /dev/null+++ b/fluxer_app/src/features/theme_settings/ThemesTab.module.css@@ -0,0 +1,183 @@+/* SPDX-License-Identifier: AGPL-3.0-or-later */++.stack {+ display: flex;+ flex-direction: column;+ gap: var(--spacing-3);+}++.fieldLabel {+ margin: 0;+ font-weight: 500;+ font-size: 0.875rem;+ line-height: 1.25rem;+ color: var(--text-primary);+}++.note {+ margin: 0;+ font-size: 0.875rem;+ line-height: 1.25rem;+ color: var(--text-primary-muted);+}++.list {+ display: flex;+ flex-direction: column;+}++.row {+ display: flex;+ align-items: center;+ gap: var(--spacing-4);+ min-height: 3.5rem;+ padding: var(--spacing-3) 0;+ border-top: 0.0625rem solid var(--background-modifier-accent);+}++.row:first-child {+ border-top: none;+}++.rowText {+ display: flex;+ flex: 1 1 auto;+ flex-direction: column;+ gap: 0.125rem;+ min-width: 0;+}++.rowLabel {+ overflow: hidden;+ font-weight: 500;+ font-size: 0.875rem;+ line-height: 1.25rem;+ color: var(--text-primary);+ text-overflow: ellipsis;+ white-space: nowrap;+}++.rowDescription {+ font-size: 0.875rem;+ line-height: 1.25rem;+ color: var(--text-primary-muted);+ overflow-wrap: anywhere;+}++.rowMeta {+ overflow: hidden;+ font-family: var(--font-mono, ui-monospace, monospace);+ font-size: 0.75rem;+ line-height: 1rem;+ color: var(--text-tertiary);+ text-overflow: ellipsis;+ white-space: nowrap;+}++.rowWarning {+ display: flex;+ align-items: flex-start;+ gap: var(--spacing-1);+ font-size: 0.8125rem;+ line-height: 1.125rem;+ color: var(--status-warning);+ overflow-wrap: anywhere;+}++.rowWarningIcon {+ flex: 0 0 auto;+ margin-top: 0.125rem;+}++.rowControls {+ display: flex;+ flex: 0 0 auto;+ align-items: center;+ gap: var(--spacing-2);+}++.iconButton {+ display: inline-flex;+ align-items: center;+ justify-content: center;+ width: 2rem;+ height: 2rem;+ padding: 0;+ border: none;+ border-radius: var(--radius-md);+ background: transparent;+ color: var(--text-primary-muted);+ cursor: pointer;+ transition:+ color var(--transition-fast),+ background-color var(--transition-fast);+}++.iconButton:hover,+.iconButton[data-context-menu-open='true'] {+ color: var(--text-primary);+ background-color: var(--background-modifier-hover);+}++.iconButtonDanger:hover {+ color: var(--status-danger);+}++.searchInput {+ max-width: 22rem;+}++.empty {+ display: flex;+ flex-direction: column;+ gap: var(--spacing-1);+ padding: var(--spacing-4) 0;+}++.emptyTitle {+ margin: 0;+ font-weight: 500;+ font-size: 0.875rem;+ line-height: 1.25rem;+ color: var(--text-primary);+}++.notice {+ margin: 0;+ padding-inline-start: 1.25rem;+ font-size: 0.8125rem;+ line-height: 1.25rem;+ color: var(--text-primary-muted);+}++.subsectionTitle {+ margin: 0;+ font-size: 0.9375rem;+ font-weight: 600;+ line-height: 1.3;+ color: var(--text-primary);+}++.subsectionHeader {+ display: flex;+ align-items: center;+ gap: var(--spacing-2);+ min-height: 2rem;+}++.subsectionActions {+ margin-inline-start: auto;+}++.groupCount {+ margin-left: var(--spacing-2);+ font-size: 0.8125rem;+ font-weight: 400;+ font-variant-numeric: tabular-nums;+ color: var(--text-tertiary);+}++.changedCount {+ font-size: 0.875rem;+ color: var(--text-primary-muted);+}diff --git a/fluxer_app/src/features/theme_settings/ThemesTab.tsx b/fluxer_app/src/features/theme_settings/ThemesTab.tsxnew file mode 100644index 000000000..19b9f23b5--- /dev/null+++ b/fluxer_app/src/features/theme_settings/ThemesTab.tsx@@ -0,0 +1,54 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {SettingsTabContainer, SettingsTabContent} from '@app/features/app/components/dialogs/shared/SettingsTabLayout';+import AccountThemeMode from '@app/features/theme/state/AccountThemeMode';+import ThemeLibrary from '@app/features/theme/state/ThemeLibrary';+import {AssetsSection} from '@app/features/theme_settings/components/AssetsSection';+import {BaseThemeSection} from '@app/features/theme_settings/components/BaseThemeSection';+import {ColorsAndFontsSection} from '@app/features/theme_settings/components/ColorsAndFontsSection';+import {DesktopWindowSection} from '@app/features/theme_settings/components/DesktopWindowSection';+import {QuickCssSection} from '@app/features/theme_settings/components/QuickCssSection';+import {ShareAndBackUpSection} from '@app/features/theme_settings/components/ShareAndBackUpSection';+import {ThisAccountSection} from '@app/features/theme_settings/components/ThisAccountSection';+import {YourThemesSection} from '@app/features/theme_settings/components/YourThemesSection';+import {isDesktop} from '@app/features/ui/utils/NativeUtils';+import inlineStyles from '@app/features/user/components/modals/tabs/TabInline.module.css';+import {observer} from 'mobx-react-lite';+import type React from 'react';+import {useEffect} from 'react';++const ThemesSections: React.FC = observer(() => {+ useEffect(() => {+ void ThemeLibrary.init();+ }, []);+ return (+ <>+ {AccountThemeMode.canUseDesktopTheme ? (+ <ThisAccountSection data-flx="theme-settings.themes-tab.themes-sections.this-account-section" />+ ) : null}+ <BaseThemeSection data-flx="theme-settings.themes-tab.themes-sections.base-theme-section" />+ <YourThemesSection data-flx="theme-settings.themes-tab.themes-sections.your-themes-section" />+ <ColorsAndFontsSection data-flx="theme-settings.themes-tab.themes-sections.colors-and-fonts-section" />+ <AssetsSection data-flx="theme-settings.themes-tab.themes-sections.assets-section" />+ {isDesktop() ? (+ <DesktopWindowSection data-flx="theme-settings.themes-tab.themes-sections.desktop-window-section" />+ ) : null}+ <ShareAndBackUpSection data-flx="theme-settings.themes-tab.themes-sections.share-and-back-up-section" />+ <QuickCssSection data-flx="theme-settings.themes-tab.themes-sections.quick-css-section" />+ </>+ );+});++export const ThemesTab: React.FC = observer(() => (+ <SettingsTabContainer data-flx="theme-settings.themes-tab.settings-tab-container">+ <SettingsTabContent data-flx="theme-settings.themes-tab.settings-tab-content">+ <ThemesSections data-flx="theme-settings.themes-tab.themes-sections" />+ </SettingsTabContent>+ </SettingsTabContainer>+));++export const ThemesInlineContent: React.FC = observer(() => (+ <div className={inlineStyles.container} data-flx="theme-settings.themes-tab.themes-inline-content.div">+ <ThemesSections data-flx="theme-settings.themes-tab.themes-inline-content.themes-sections" />+ </div>+));diff --git a/fluxer_app/src/features/theme_settings/hooks/useCurrentAccountLabels.ts b/fluxer_app/src/features/theme_settings/hooks/useCurrentAccountLabels.tsnew file mode 100644index 000000000..eb7cfe735--- /dev/null+++ b/fluxer_app/src/features/theme_settings/hooks/useCurrentAccountLabels.ts@@ -0,0 +1,14 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {getAccountDisplayLabels, resolveAccountInstanceLabel} from '@app/features/auth/AccountDisplayUtils';+import Accounts from '@app/features/auth/state/Accounts';+import Users from '@app/features/user/state/Users';++export function useCurrentAccountLabels(): {username: string; instanceName: string} {+ const account = Accounts.currentAccount;+ const labels = account == null ? null : getAccountDisplayLabels(account);+ return {+ username: labels?.available ? labels.usernameLabel : (Users.currentUser?.username ?? ''),+ instanceName: (account == null ? null : resolveAccountInstanceLabel(account)) ?? '',+ };+}diff --git a/fluxer_app/src/features/theme_settings/state/ThemeSettingsState.ts b/fluxer_app/src/features/theme_settings/state/ThemeSettingsState.tsnew file mode 100644index 000000000..8ece8ed80--- /dev/null+++ b/fluxer_app/src/features/theme_settings/state/ThemeSettingsState.ts@@ -0,0 +1,113 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import AppStorage from '@app/features/platform/state/PersistentStorage';+import {makeAutoObservable} from 'mobx';++const EXPANDED_GROUPS_STORAGE_KEY = 'ThemeStudio:expandedGroups';++export const QUICK_CSS_EDITOR_FILE = 'quick-css';++function readStoredExpandedGroups(): Array<string> {+ try {+ const raw = AppStorage.getItem(EXPANDED_GROUPS_STORAGE_KEY);+ if (raw === null) return [];+ const parsed: unknown = JSON.parse(raw);+ if (Array.isArray(parsed) && parsed.every((value) => typeof value === 'string')) {+ return parsed;+ }+ } catch {}+ return [];+}++class ThemeSettingsState {+ librarySearch = '';+ tokenSearch = '';+ expandedGroups: ReadonlySet<string> = new Set(readStoredExpandedGroups());+ editorOpen = false;+ editorGeneration = 0;+ editorFile: string = QUICK_CSS_EDITOR_FILE;+ editorDirty = false;+ missingReferences: ReadonlyArray<string> = [];+ editorWindow: Window | null = null;+ editorFileRequestHandler: ((file: string) => void) | null = null;++ constructor() {+ makeAutoObservable(this, {editorWindow: false, editorFileRequestHandler: false}, {autoBind: true});+ }++ setLibrarySearch(value: string): void {+ this.librarySearch = value;+ }++ setTokenSearch(value: string): void {+ this.tokenSearch = value;+ }++ isGroupExpanded(groupId: string): boolean {+ return this.expandedGroups.has(groupId);+ }++ setGroupExpanded(groupId: string, expanded: boolean): void {+ const next = new Set(this.expandedGroups);+ if (expanded) {+ next.add(groupId);+ } else {+ next.delete(groupId);+ }+ this.expandedGroups = next;+ try {+ AppStorage.setItem(EXPANDED_GROUPS_STORAGE_KEY, JSON.stringify([...next]));+ } catch {}+ }++ openEditor(file: string): void {+ if (this.editorOpen) {+ this.requestEditorFile(file);+ return;+ }+ this.editorFile = file;+ this.editorDirty = false;+ this.editorGeneration += 1;+ this.editorOpen = true;+ }++ requestEditorFile(file: string): void {+ if (file === this.editorFile) return;+ if (this.editorFileRequestHandler) {+ this.editorFileRequestHandler(file);+ return;+ }+ this.setEditorFile(file);+ }++ setEditorFile(file: string): void {+ this.editorFile = file;+ this.editorDirty = false;+ }++ setEditorFileRequestHandler(handler: ((file: string) => void) | null): void {+ this.editorFileRequestHandler = handler;+ }++ setEditorDirty(dirty: boolean): void {+ this.editorDirty = dirty;+ }++ setEditorWindow(editorWindow: Window | null): void {+ this.editorWindow = editorWindow;+ }++ closeEditor(generation: number): void {+ if (generation !== this.editorGeneration) return;+ this.editorOpen = false;+ this.editorWindow = null;+ this.editorFile = QUICK_CSS_EDITOR_FILE;+ this.editorDirty = false;+ }++ setMissingReferences(references: ReadonlyArray<string>): void {+ this.missingReferences = references;+ }+}++export default new ThemeSettingsState();diff --git a/fluxer_app/src/features/theme_settings/utils/ThemeDefaultVariables.ts b/fluxer_app/src/features/theme_settings/utils/ThemeDefaultVariables.tsnew file mode 100644index 000000000..15674ab9c--- /dev/null+++ b/fluxer_app/src/features/theme_settings/utils/ThemeDefaultVariables.ts@@ -0,0 +1,17 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {+ THEME_DARK_DEFAULT_VARIABLE_VALUES,+ THEME_LIGHT_DEFAULT_VARIABLE_VALUES,+} from '@app/features/theme/variables/ThemeVariableManifest';+import {ThemeTypes} from '@fluxer/constants/src/UserConstants';++export type ThemeBaseKind = 'dark' | 'light';++export function getThemeBaseKind(effectiveTheme: string): ThemeBaseKind {+ return effectiveTheme === ThemeTypes.LIGHT ? 'light' : 'dark';+}++export function getThemeDefaultVariables(baseTheme: ThemeBaseKind): Readonly<Record<string, string>> {+ return baseTheme === 'light' ? THEME_LIGHT_DEFAULT_VARIABLE_VALUES : THEME_DARK_DEFAULT_VARIABLE_VALUES;+}diff --git a/fluxer_app/src/features/theme_studio/utils/ThemeStudioErrorModalUtils.ts b/fluxer_app/src/features/theme_settings/utils/ThemeSettingsErrorModal.tssimilarity index 53%rename from fluxer_app/src/features/theme_studio/utils/ThemeStudioErrorModalUtils.tsrename to fluxer_app/src/features/theme_settings/utils/ThemeSettingsErrorModal.tsindex 023e8c02a..55e6137aa 100644--- a/fluxer_app/src/features/theme_studio/utils/ThemeStudioErrorModalUtils.ts+++ b/fluxer_app/src/features/theme_settings/utils/ThemeSettingsErrorModal.ts@@ -3,9 +3,15 @@import {showGenericErrorModal} from '@app/features/app/components/alerts/GenericErrorModalCommands';import {SOMETHING_WENT_WRONG_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';import type {I18n} from '@lingui/core';+import {msg} from '@lingui/core/macro';import type {ReactNode} from 'react';-export function showThemeStudioErrorModal(i18n: I18n, message: ReactNode | (() => ReactNode), dataFlx: string): void {+export const WE_COULDN_T_SAVE_THAT_THEME_DESCRIPTOR = msg({+ message: "We couldn't save that theme.",+ comment: 'Error message after saving a theme failed in Settings > Themes or the quick CSS editor window.',+});++export function showThemeSettingsErrorModal(i18n: I18n, message: ReactNode | (() => ReactNode), dataFlx: string): void {showGenericErrorModal({title: () => i18n._(SOMETHING_WENT_WRONG_DESCRIPTOR),message,diff --git a/fluxer_app/src/features/theme_settings/utils/ThemeSettingsMessageDescriptors.ts b/fluxer_app/src/features/theme_settings/utils/ThemeSettingsMessageDescriptors.tsnew file mode 100644index 000000000..fc153435a--- /dev/null+++ b/fluxer_app/src/features/theme_settings/utils/ThemeSettingsMessageDescriptors.ts@@ -0,0 +1,36 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {msg} from '@lingui/core/macro';++export const OPEN_QUICK_CSS_EDITOR_DESCRIPTOR = msg({+ message: 'Open quick CSS editor',+ comment:+ 'Button in Settings > Themes that opens the quick CSS editor in its own window. Also the settings search entry and the keyboard shortcut action for it. Keep short, sentence case.',+});+export const USE_DESKTOP_APP_THEME_DESCRIPTOR = msg({+ message: 'Use the desktop app theme for this account',+ comment:+ 'Switch label in Settings > Themes on the desktop app, also used as its settings search entry. When on, the account uses the theme shared by every account in the desktop app.',+});+export const SYNC_CUSTOM_CSS_ACROSS_DEVICES_DESCRIPTOR = msg({+ message: 'Sync custom CSS across devices',+ comment: 'Switch label in Settings > Themes, also used as its settings search entry.',+});+export const EXPORT_LIBRARY_DESCRIPTOR = msg({+ message: 'Export library',+ comment:+ 'Row title and button in Settings > Themes that saves every theme and asset to one file, also used as its settings search entry.',+});+export const IMPORT_LIBRARY_DESCRIPTOR = msg({+ message: 'Import library',+ comment:+ 'Row title and button in Settings > Themes that adds themes and assets from a library file, also used as its settings search entry.',+});+export const THEME_SAVED_DESCRIPTOR = msg({+ message: 'Theme saved.',+ comment: 'Toast after saving a theme in Settings > Themes or the quick CSS editor window.',+});+export const TRY_A_DIFFERENT_NAME_OR_CLEAR_THE_SEARCH_DESCRIPTOR = msg({+ message: 'Try a different name or clear the search.',+ comment: 'Empty search result description in Settings > Themes.',+});