A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(app): manage saved themes from the themes tab
Hampus0a33a734311b
diff --git a/fluxer_app/src/features/theme_settings/components/ThemeDetailsModal.tsx b/fluxer_app/src/features/theme_settings/components/ThemeDetailsModal.tsxnew file mode 100644index 000000000..4726b2d63--- /dev/null+++ b/fluxer_app/src/features/theme_settings/components/ThemeDetailsModal.tsx@@ -0,0 +1,179 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import * as Modal from '@app/features/app/components/dialogs/Modal';+import {CANCEL_DESCRIPTOR, DESCRIPTION_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';+import ThemeLibrary, {getThemeLabel} from '@app/features/theme/state/ThemeLibrary';+import {upsertThemeCssHeader} from '@app/features/theme/utils/ThemeCssUtils';+import styles from '@app/features/theme_settings/ThemesTab.module.css';+import {getLinkedThemeFileLine, isLinkedThemeReadOnly} from '@app/features/theme_settings/utils/LinkedThemeFile';+import {+ showThemeSettingsErrorModal,+ WE_COULDN_T_SAVE_THAT_THEME_DESCRIPTOR,+} from '@app/features/theme_settings/utils/ThemeSettingsErrorModal';+import {THEME_SAVED_DESCRIPTOR} from '@app/features/theme_settings/utils/ThemeSettingsMessageDescriptors';+import {Button} from '@app/features/ui/button/Button';+import * as ModalCommands from '@app/features/ui/commands/ModalCommands';+import * as ToastCommands from '@app/features/ui/commands/ToastCommands';+import {Input} from '@app/features/ui/components/form/FormInput';+import {parseTagInput} from '@app/features/user/components/modals/tabs/appearance_tab/theme/ThemeUtils';+import {msg} from '@lingui/core/macro';+import {Trans, useLingui} from '@lingui/react/macro';+import {observer} from 'mobx-react-lite';+import {useState} from 'react';++const EDIT_THEME_DESCRIPTOR = msg({+ message: 'Edit {themeName}',+ comment:+ 'Title of the modal in Settings > Themes for changing the name, author, version, tags and description of a theme.',+});+const NAME_DESCRIPTOR = msg({+ message: 'Name',+ comment: 'Field label in the theme details modal in Settings > Themes.',+});+const AUTHOR_DESCRIPTOR = msg({+ message: 'Author',+ comment: 'Field label in the theme details modal in Settings > Themes.',+});+const VERSION_DESCRIPTOR = msg({+ message: 'Version',+ comment: 'Field label in the theme details modal in Settings > Themes.',+});+const TAGS_DESCRIPTOR = msg({+ message: 'Tags',+ comment: 'Field label in the theme details modal in Settings > Themes.',+});+const COMMA_SEPARATED_DESCRIPTOR = msg({+ message: 'comma, separated',+ comment: 'Placeholder for the tags field in the theme details modal. Shows that tags are separated by commas.',+});++interface ThemeDetailsModalProps {+ themeId: string;+}++export const ThemeDetailsModal = observer(function ThemeDetailsModal({themeId}: ThemeDetailsModalProps) {+ const {i18n} = useLingui();+ const theme = ThemeLibrary.themes.find((candidate) => candidate.id === themeId) ?? null;+ const [name, setName] = useState(theme?.name ?? '');+ const [author, setAuthor] = useState(theme?.author ?? '');+ const [version, setVersion] = useState(theme?.version ?? '');+ const [tags, setTags] = useState(theme?.tags.join(', ') ?? '');+ const [description, setDescription] = useState(theme?.description ?? '');+ const [saving, setSaving] = useState(false);+ if (!theme) {+ return null;+ }+ const readOnly = isLinkedThemeReadOnly(theme);+ const linkedLine = getLinkedThemeFileLine(i18n, theme);+ const handleSave = () => {+ const metadata = {+ name: name.trim() || theme.name,+ description,+ author,+ version,+ tags: parseTagInput(tags),+ };+ setSaving(true);+ void ThemeLibrary.updateThemeDetails(theme.id, {...metadata, css: upsertThemeCssHeader(theme.css, metadata)})+ .then(() => {+ ToastCommands.success(i18n._(THEME_SAVED_DESCRIPTOR));+ ModalCommands.pop();+ })+ .catch(() =>+ showThemeSettingsErrorModal(+ i18n,+ () => i18n._(WE_COULDN_T_SAVE_THAT_THEME_DESCRIPTOR),+ 'theme-settings.theme-details-modal.save-error-modal',+ ),+ )+ .finally(() => setSaving(false));+ };+ const handleUnlink = () => {+ void ThemeLibrary.unlinkTheme(theme.id);+ };+ return (+ <Modal.Root size="small" centered data-flx="theme-settings.theme-details-modal.modal-root">+ <Modal.Header+ title={i18n._(EDIT_THEME_DESCRIPTOR, {themeName: getThemeLabel(theme)})}+ data-flx="theme-settings.theme-details-modal.modal-header"+ />+ <Modal.Content data-flx="theme-settings.theme-details-modal.modal-content">+ <Modal.ContentLayout data-flx="theme-settings.theme-details-modal.modal-content-layout">+ {linkedLine ? (+ <div className={styles.stack} data-flx="theme-settings.theme-details-modal.stack">+ <p className={styles.note} data-flx="theme-settings.theme-details-modal.note">+ {linkedLine}+ </p>+ <div data-flx="theme-settings.theme-details-modal.div">+ <Button+ variant="secondary"+ small+ onClick={handleUnlink}+ data-flx="theme-settings.theme-details-modal.button.unlink"+ >+ <Trans comment="Button that stops a theme following its CSS file on disk and turns it back into an editable copy.">+ Unlink+ </Trans>+ </Button>+ </div>+ </div>+ ) : null}+ <Modal.InputGroup data-flx="theme-settings.theme-details-modal.modal-input-group">+ <Input+ label={i18n._(NAME_DESCRIPTOR)}+ value={name}+ readOnly={readOnly}+ onChange={(event) => setName(event.target.value)}+ data-flx="theme-settings.theme-details-modal.input.set-name"+ />+ <Input+ label={i18n._(AUTHOR_DESCRIPTOR)}+ value={author}+ readOnly={readOnly}+ onChange={(event) => setAuthor(event.target.value)}+ data-flx="theme-settings.theme-details-modal.input.set-author"+ />+ <Input+ label={i18n._(VERSION_DESCRIPTOR)}+ value={version}+ readOnly={readOnly}+ onChange={(event) => setVersion(event.target.value)}+ data-flx="theme-settings.theme-details-modal.input.set-version"+ />+ <Input+ label={i18n._(TAGS_DESCRIPTOR)}+ value={tags}+ placeholder={i18n._(COMMA_SEPARATED_DESCRIPTOR)}+ readOnly={readOnly}+ onChange={(event) => setTags(event.target.value)}+ data-flx="theme-settings.theme-details-modal.input.set-tags"+ />+ <Input+ label={i18n._(DESCRIPTION_DESCRIPTOR)}+ value={description}+ readOnly={readOnly}+ onChange={(event) => setDescription(event.target.value)}+ data-flx="theme-settings.theme-details-modal.input.set-description"+ />+ </Modal.InputGroup>+ </Modal.ContentLayout>+ </Modal.Content>+ {readOnly ? (+ <Modal.DismissFooter data-flx="theme-settings.theme-details-modal.modal-dismiss-footer" />+ ) : (+ <Modal.Footer data-flx="theme-settings.theme-details-modal.modal-footer">+ <Button+ variant="secondary"+ onClick={ModalCommands.pop}+ data-flx="theme-settings.theme-details-modal.button.pop"+ >+ {i18n._(CANCEL_DESCRIPTOR)}+ </Button>+ <Button onClick={handleSave} submitting={saving} data-flx="theme-settings.theme-details-modal.button.save">+ <Trans>Save</Trans>+ </Button>+ </Modal.Footer>+ )}+ </Modal.Root>+ );+});diff --git a/fluxer_app/src/features/theme_settings/components/YourThemesSection.tsx b/fluxer_app/src/features/theme_settings/components/YourThemesSection.tsxnew file mode 100644index 000000000..5061f766d--- /dev/null+++ b/fluxer_app/src/features/theme_settings/components/YourThemesSection.tsx@@ -0,0 +1,524 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {ConfirmModal} from '@app/features/app/components/dialogs/ConfirmModal';+import {SettingsSection} from '@app/features/app/components/dialogs/shared/SettingsSection';+import {CANCEL_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';+import {downloadTextFile} from '@app/features/platform/utils/DownloadFile';+import * as ThemeProfileCommands from '@app/features/theme/commands/ThemeProfileCommands';+import {remFromPx} from '@app/features/theme/layout/RemFromPx';+import ThemeEditTarget from '@app/features/theme/state/ThemeEditTarget';+import ThemeLibrary, {getThemeLabel, type ThemeLibraryTheme} from '@app/features/theme/state/ThemeLibrary';+import * as ThemeSettingsCommands from '@app/features/theme_settings/commands/ThemeSettingsCommands';+import {ThemeDetailsModal} from '@app/features/theme_settings/components/ThemeDetailsModal';+import ThemeSettingsState from '@app/features/theme_settings/state/ThemeSettingsState';+import styles from '@app/features/theme_settings/ThemesTab.module.css';+import {+ getLinkedThemeFileProblem,+ isLinkedThemeReadOnly,+ LINKED_FILE_DESCRIPTOR,+} from '@app/features/theme_settings/utils/LinkedThemeFile';+import {TRY_A_DIFFERENT_NAME_OR_CLEAR_THE_SEARCH_DESCRIPTOR} from '@app/features/theme_settings/utils/ThemeSettingsMessageDescriptors';+import {MoreOptionsVerticalIcon} from '@app/features/ui/action_menu/ContextMenuIcons';+import {MenuGroup} from '@app/features/ui/action_menu/MenuGroup';+import {MenuItem} from '@app/features/ui/action_menu/MenuItem';+import {Button} from '@app/features/ui/button/Button';+import * as ContextMenuCommands from '@app/features/ui/commands/ContextMenuCommands';+import * as ModalCommands from '@app/features/ui/commands/ModalCommands';+import {modal} from '@app/features/ui/commands/ModalCommands';+import * as ToastCommands from '@app/features/ui/commands/ToastCommands';+import {Input} from '@app/features/ui/components/form/FormInput';+import {Switch} from '@app/features/ui/components/form/FormSwitch';+import FocusRing from '@app/features/ui/focus_ring/FocusRing';+import {getElectronAPI, isDesktop} from '@app/features/ui/utils/NativeUtils';+import {createThemeExportFileName} from '@app/features/user/components/modals/tabs/appearance_tab/theme/ThemeUtils';+import {YOUR_THEMES_SECTION_DESCRIPTOR} from '@app/features/user/components/settings_utils/section_registry/ThemesSections';+import {msg} from '@lingui/core/macro';+import {Trans, useLingui} from '@lingui/react/macro';+import {+ ArrowDownIcon,+ ArrowUpIcon,+ CopyIcon,+ DownloadSimpleIcon,+ FileCssIcon,+ FolderOpenIcon,+ LinkBreakIcon,+ LinkSimpleIcon,+ MagnifyingGlassIcon,+ PencilSimpleIcon,+ TrashIcon,+ WarningCircleIcon,+} from '@phosphor-icons/react';+import {observer} from 'mobx-react-lite';+import type React from 'react';+import {useMemo, useRef} from 'react';++const YOUR_THEMES_DESCRIPTION_DESCRIPTOR = msg({+ message:+ 'Themes you import from CSS files. The ones you turn on are added on top of the base theme in the order shown.',+ comment: 'Description of the "Your themes" section in Settings > Themes.',+});+const SEARCH_THEMES_DESCRIPTOR = msg({+ message: 'Search themes…',+ comment: 'Placeholder for the search field in the "Your themes" section in Settings > Themes.',+});+const NO_THEMES_SAVED_YET_DESCRIPTOR = msg({+ message: 'No themes saved yet.',+ comment: 'Empty state in the "Your themes" section in Settings > Themes.',+});+const IMPORT_A_CSS_FILE_TO_GET_STARTED_DESCRIPTOR = msg({+ message: 'Import a .css file to get started, or write your own CSS in quick CSS.',+ comment: 'Empty state in the "Your themes" section in Settings > Themes. Quick CSS is custom CSS the user writes.',+});+const NO_THEMES_MATCH_YOUR_SEARCH_DESCRIPTOR = msg({+ message: 'No themes match your search.',+ comment: 'Empty search result in the "Your themes" section in Settings > Themes.',+});+const ENABLE_DESCRIPTOR = msg({+ message: 'Enable {themeName}',+ comment: 'Accessible label for the switch that enables a saved theme file.',+});+const OPTIONS_FOR_THEME_DESCRIPTOR = msg({+ message: 'Options for {themeName}',+ comment: 'Accessible label for the menu button on a theme row in Settings > Themes.',+});+const EDIT_DETAILS_DESCRIPTOR = msg({+ message: 'Edit details',+ comment: 'Menu item on a theme in Settings > Themes that opens a modal to change its name, author, version and tags.',+});+const EDIT_CSS_DESCRIPTOR = msg({+ message: 'Edit CSS',+ comment: 'Menu item on a theme in Settings > Themes that opens its CSS in the quick CSS editor window.',+});+const VIEW_CSS_DESCRIPTOR = msg({+ message: 'View CSS',+ comment:+ 'Menu item on a theme linked to a file in Settings > Themes. Opens its CSS read-only in the quick CSS editor window.',+});+const MOVE_UP_DESCRIPTOR = msg({+ message: 'Move up',+ comment:+ 'Menu item on a turned-on theme in Settings > Themes. Moves the theme up in the list so it applies earlier, and themes below it win when they change the same thing.',+});+const MOVE_DOWN_DESCRIPTOR = msg({+ message: 'Move down',+ comment:+ 'Menu item on a turned-on theme in Settings > Themes. Moves the theme down in the list so it applies later and wins over themes above it.',+});+const LINK_FILE_DESCRIPTOR = msg({+ message: 'Link file',+ comment:+ 'Menu item in Settings > Themes that links an existing theme to a CSS file on disk so saved changes to the file apply live.',+});+const UNLINK_DESCRIPTOR = msg({+ message: 'Unlink',+ comment:+ 'Menu item in Settings > Themes that stops a theme following its CSS file on disk and turns it back into an editable copy.',+});+const EXPORT_DESCRIPTOR = msg({+ message: 'Export',+ comment: 'Menu item in Settings > Themes that downloads a theme as a CSS file.',+});+const DUPLICATE_DESCRIPTOR = msg({+ message: 'Duplicate',+ comment: 'Menu item in Settings > Themes that makes a copy of a theme.',+});+const DELETE_THEME_DESCRIPTOR = msg({+ message: 'Delete theme',+ comment: 'Menu item and confirm button in Settings > Themes that deletes a theme from this device.',+});+const DELETE_THEME_CONFIRM_DESCRIPTOR = msg({+ message: 'Delete theme?',+ comment: 'Confirmation title before deleting a theme in Settings > Themes.',+});+const THIS_REMOVES_FROM_THIS_DEVICE_DESCRIPTOR = msg({+ message: 'This removes "{themeName}" from this device.',+ comment: 'Confirmation text before deleting a saved theme in Settings > Themes.',+});+const IMPORTED_THEME_FILES_DESCRIPTOR = msg({+ message: 'Imported {length, plural, one {# theme file} other {# theme files}}.',+ comment: 'Toast after importing one or more CSS files into the theme library.',+});+const LINKED_THEME_FILES_DESCRIPTOR = msg({+ message:+ 'Linked {length, plural, one {# theme file} other {# theme files}}. Changes you save to them apply right away.',+ comment:+ 'Toast after importing CSS files or a folder on the desktop app. The themes stay linked to the files on disk and update when the file is saved.',+});++const SEARCH_THRESHOLD = 5;++function matchesSearch(theme: ThemeLibraryTheme, query: string): boolean {+ return (+ theme.name.toLowerCase().includes(query) ||+ theme.description.toLowerCase().includes(query) ||+ theme.fileName.toLowerCase().includes(query) ||+ theme.tags.some((tag) => tag.toLowerCase().includes(query))+ );+}++const ThemeRow: React.FC<{theme: ThemeLibraryTheme}> = observer(({theme}) => {+ const {i18n} = useLingui();+ const target = ThemeEditTarget.target;+ const enabledIds = ThemeLibrary.enabledIdsFor(target);+ const enabledIndex = enabledIds.indexOf(theme.id);+ const enabled = enabledIndex >= 0;+ const label = getThemeLabel(theme);+ const problem = getLinkedThemeFileProblem(i18n, theme);+ const canLinkFiles = isDesktop() && Boolean(getElectronAPI()?.pickThemeLinkedFiles);+ const handleDelete = () => {+ ModalCommands.push(+ modal(() => (+ <ConfirmModal+ title={i18n._(DELETE_THEME_CONFIRM_DESCRIPTOR)}+ description={i18n._(THIS_REMOVES_FROM_THIS_DEVICE_DESCRIPTOR, {themeName: label})}+ primaryText={i18n._(DELETE_THEME_DESCRIPTOR)}+ primaryVariant="danger"+ secondaryText={i18n._(CANCEL_DESCRIPTOR)}+ onPrimary={() => {+ void ThemeLibrary.deleteTheme(theme.id);+ }}+ data-flx="theme-settings.your-themes-section.handle-delete.confirm-modal"+ />+ )),+ );+ };+ const openMenu = (event: React.MouseEvent<HTMLButtonElement>) => {+ ContextMenuCommands.openFromElementBottomRight(event, ({onClose}) => {+ const select = (action: () => void) => () => {+ onClose();+ action();+ };+ return (+ <>+ <MenuGroup data-flx="theme-settings.your-themes-section.open-menu.menu-group">+ <MenuItem+ icon={+ <PencilSimpleIcon+ size={remFromPx(16)}+ data-flx="theme-settings.your-themes-section.open-menu.pencil-simple-icon"+ />+ }+ onClick={select(() =>+ ModalCommands.push(+ modal(() => (+ <ThemeDetailsModal+ themeId={theme.id}+ data-flx="theme-settings.your-themes-section.open-menu.theme-details-modal"+ />+ )),+ ),+ )}+ data-flx="theme-settings.your-themes-section.open-menu.menu-item.select"+ >+ {i18n._(EDIT_DETAILS_DESCRIPTOR)}+ </MenuItem>+ {ThemeSettingsCommands.canOpenQuickCssEditor() ? (+ <MenuItem+ icon={+ <FileCssIcon+ size={remFromPx(16)}+ data-flx="theme-settings.your-themes-section.open-menu.file-css-icon"+ />+ }+ onClick={select(() => ThemeSettingsCommands.openQuickCssEditor(theme.id))}+ data-flx="theme-settings.your-themes-section.open-menu.menu-item.select"+ >+ {i18n._(isLinkedThemeReadOnly(theme) ? VIEW_CSS_DESCRIPTOR : EDIT_CSS_DESCRIPTOR)}+ </MenuItem>+ ) : null}+ {enabled && enabledIndex > 0 ? (+ <MenuItem+ icon={+ <ArrowUpIcon+ size={remFromPx(16)}+ data-flx="theme-settings.your-themes-section.open-menu.arrow-up-icon"+ />+ }+ onClick={select(() => {+ void ThemeProfileCommands.moveEnabledTheme(theme.id, -1, target);+ })}+ data-flx="theme-settings.your-themes-section.open-menu.menu-item.move-up"+ >+ {i18n._(MOVE_UP_DESCRIPTOR)}+ </MenuItem>+ ) : null}+ {enabled && enabledIndex < enabledIds.length - 1 ? (+ <MenuItem+ icon={+ <ArrowDownIcon+ size={remFromPx(16)}+ data-flx="theme-settings.your-themes-section.open-menu.arrow-down-icon"+ />+ }+ onClick={select(() => {+ void ThemeProfileCommands.moveEnabledTheme(theme.id, 1, target);+ })}+ data-flx="theme-settings.your-themes-section.open-menu.menu-item.move-down"+ >+ {i18n._(MOVE_DOWN_DESCRIPTOR)}+ </MenuItem>+ ) : null}+ {canLinkFiles && !theme.linkedPath ? (+ <MenuItem+ icon={+ <LinkSimpleIcon+ size={remFromPx(16)}+ data-flx="theme-settings.your-themes-section.open-menu.link-simple-icon"+ />+ }+ onClick={select(() => {+ void ThemeLibrary.linkThemeToDesktopFile(theme.id);+ })}+ data-flx="theme-settings.your-themes-section.open-menu.menu-item.select--2"+ >+ {i18n._(LINK_FILE_DESCRIPTOR)}+ </MenuItem>+ ) : null}+ {theme.linkedPath ? (+ <MenuItem+ icon={+ <LinkBreakIcon+ size={remFromPx(16)}+ data-flx="theme-settings.your-themes-section.open-menu.link-break-icon"+ />+ }+ onClick={select(() => {+ void ThemeLibrary.unlinkTheme(theme.id);+ })}+ data-flx="theme-settings.your-themes-section.open-menu.menu-item.select--3"+ >+ {i18n._(UNLINK_DESCRIPTOR)}+ </MenuItem>+ ) : null}+ <MenuItem+ icon={+ <DownloadSimpleIcon+ size={remFromPx(16)}+ data-flx="theme-settings.your-themes-section.open-menu.download-simple-icon"+ />+ }+ onClick={select(() =>+ downloadTextFile(theme.css, createThemeExportFileName(theme), 'text/css;charset=utf-8'),+ )}+ data-flx="theme-settings.your-themes-section.open-menu.menu-item.select--4"+ >+ {i18n._(EXPORT_DESCRIPTOR)}+ </MenuItem>+ <MenuItem+ icon={<CopyIcon size={remFromPx(16)} data-flx="theme-settings.your-themes-section.open-menu.copy-icon" />}+ onClick={select(() => {+ void ThemeLibrary.duplicateTheme(theme.id);+ })}+ data-flx="theme-settings.your-themes-section.open-menu.menu-item.select--5"+ >+ {i18n._(DUPLICATE_DESCRIPTOR)}+ </MenuItem>+ </MenuGroup>+ <MenuGroup data-flx="theme-settings.your-themes-section.open-menu.menu-group--2">+ <MenuItem+ icon={+ <TrashIcon size={remFromPx(16)} data-flx="theme-settings.your-themes-section.open-menu.trash-icon" />+ }+ danger+ onClick={select(handleDelete)}+ data-flx="theme-settings.your-themes-section.open-menu.menu-item.select--6"+ >+ {i18n._(DELETE_THEME_DESCRIPTOR)}+ </MenuItem>+ </MenuGroup>+ </>+ );+ });+ };+ const rowClass = styles.row;+ const textClass = styles.rowText;+ const labelNode = (+ <span className={styles.rowLabel} data-flx="theme-settings.your-themes-section.theme-row.row-label">+ {label}+ </span>+ );+ const fileNameNode = (+ <span className={styles.rowMeta} data-flx="theme-settings.your-themes-section.theme-row.row-meta">+ {theme.fileName}+ </span>+ );+ let description: React.ReactNode = null;+ if (problem) {+ description = (+ <span className={styles.rowWarning} data-flx="theme-settings.your-themes-section.theme-row.row-warning">+ <WarningCircleIcon+ size={remFromPx(14)}+ weight="bold"+ className={styles.rowWarningIcon}+ aria-hidden+ data-flx="theme-settings.your-themes-section.theme-row.row-warning-icon"+ />+ {problem}+ </span>+ );+ } else if (theme.linkedPath) {+ description = (+ <span className={styles.rowDescription} data-flx="theme-settings.your-themes-section.theme-row.row-description">+ {i18n._(LINKED_FILE_DESCRIPTOR)}+ </span>+ );+ }+ return (+ <div className={rowClass} data-flx="theme-settings.your-themes-section.theme-row.row">+ <div className={textClass} data-flx="theme-settings.your-themes-section.theme-row.row-text">+ {labelNode}+ {fileNameNode}+ {description}+ </div>+ <div className={styles.rowControls} data-flx="theme-settings.your-themes-section.theme-row.row-controls">+ <Switch+ compact+ ariaLabel={i18n._(ENABLE_DESCRIPTOR, {themeName: label})}+ value={enabled}+ onChange={(value) => {+ void ThemeProfileCommands.setThemeEnabled(theme.id, value, target);+ }}+ data-flx="theme-settings.your-themes-section.theme-row.switch"+ />+ <FocusRing offset={-2} data-flx="theme-settings.your-themes-section.theme-row.focus-ring">+ <button+ type="button"+ className={styles.iconButton}+ aria-label={i18n._(OPTIONS_FOR_THEME_DESCRIPTOR, {themeName: label})}+ onClick={openMenu}+ data-flx="theme-settings.your-themes-section.theme-row.icon-button.open-menu"+ >+ <MoreOptionsVerticalIcon+ size={18}+ data-flx="theme-settings.your-themes-section.theme-row.more-options-vertical-icon"+ />+ </button>+ </FocusRing>+ </div>+ </div>+ );+});++export const YourThemesSection: React.FC = observer(() => {+ const {i18n} = useLingui();+ const cssImportRef = useRef<HTMLInputElement | null>(null);+ const themes = ThemeLibrary.themes;+ const searchQuery = ThemeSettingsState.librarySearch.trim().toLowerCase();+ const showSearch = themes.length > SEARCH_THRESHOLD;+ const searching = showSearch && searchQuery.length > 0;+ const enabledIds = ThemeLibrary.enabledIdsFor(ThemeEditTarget.target);+ const visibleThemes = useMemo(() => {+ const matching = searching ? themes.filter((theme) => matchesSearch(theme, searchQuery)) : themes;+ const enabledOrder = new Map(enabledIds.map((id, index) => [id, index]));+ const enabled = matching+ .filter((theme) => enabledOrder.has(theme.id))+ .sort((a, b) => (enabledOrder.get(a.id) ?? 0) - (enabledOrder.get(b.id) ?? 0));+ return [...enabled, ...matching.filter((theme) => !enabledOrder.has(theme.id))];+ }, [themes, searching, searchQuery, enabledIds, ThemeLibrary.revision]);+ const canLinkFiles = isDesktop() && Boolean(getElectronAPI()?.pickThemeLinkedFiles);+ const canImportFolder = isDesktop() && Boolean(getElectronAPI()?.pickThemeLocalFiles);+ const handleImportCss = (event: React.ChangeEvent<HTMLInputElement>) => {+ const files = [...(event.target.files ?? [])];+ event.target.value = '';+ if (files.length === 0) return;+ void ThemeLibrary.importCssFiles(files).then((imported) => {+ ToastCommands.success(i18n._(IMPORTED_THEME_FILES_DESCRIPTOR, {length: imported.length}));+ });+ };+ const handleImportDesktopCss = () => {+ void ThemeLibrary.importDesktopCssFiles().then((imported) => {+ if (imported.length === 0) return;+ ToastCommands.success(i18n._(LINKED_THEME_FILES_DESCRIPTOR, {length: imported.length}));+ });+ };+ const handleImportFolder = () => {+ void ThemeLibrary.importDesktopThemeDirectory().then((imported) => {+ if (imported.length === 0) return;+ const descriptor = imported.some((theme) => theme.linkedPath)+ ? LINKED_THEME_FILES_DESCRIPTOR+ : IMPORTED_THEME_FILES_DESCRIPTOR;+ ToastCommands.success(i18n._(descriptor, {length: imported.length}));+ });+ };+ return (+ <SettingsSection+ id="your-themes"+ title={i18n._(YOUR_THEMES_SECTION_DESCRIPTOR)}+ description={i18n._(YOUR_THEMES_DESCRIPTION_DESCRIPTOR)}+ actions={+ <>+ <Button+ variant="secondary"+ small+ leftIcon={<FileCssIcon size={remFromPx(16)} data-flx="theme-settings.your-themes-section.file-css-icon" />}+ onClick={canLinkFiles ? handleImportDesktopCss : () => cssImportRef.current?.click()}+ data-flx="theme-settings.your-themes-section.button.import-desktop-css"+ >+ <Trans>Import CSS</Trans>+ </Button>+ {canImportFolder ? (+ <Button+ variant="secondary"+ small+ leftIcon={+ <FolderOpenIcon size={remFromPx(16)} data-flx="theme-settings.your-themes-section.folder-open-icon" />+ }+ onClick={handleImportFolder}+ data-flx="theme-settings.your-themes-section.button.import-folder"+ >+ <Trans>Import folder</Trans>+ </Button>+ ) : null}+ <input+ ref={cssImportRef}+ type="file"+ accept=".css,text/css,text/plain"+ multiple+ hidden+ onChange={handleImportCss}+ aria-hidden+ data-flx="theme-settings.your-themes-section.input.import-css.file"+ />+ </>+ }+ data-flx="theme-settings.your-themes-section.your-themes"+ >+ {showSearch ? (+ <Input+ className={styles.searchInput}+ value={ThemeSettingsState.librarySearch}+ onChange={(event) => ThemeSettingsState.setLibrarySearch(event.target.value)}+ placeholder={i18n._(SEARCH_THEMES_DESCRIPTOR)}+ aria-label={i18n._(SEARCH_THEMES_DESCRIPTOR)}+ leftIcon={+ <MagnifyingGlassIcon+ size={remFromPx(16)}+ data-flx="theme-settings.your-themes-section.magnifying-glass-icon"+ />+ }+ data-flx="theme-settings.your-themes-section.search-input.set-library-search"+ />+ ) : null}+ {visibleThemes.length === 0 ? (+ <div className={styles.empty} data-flx="theme-settings.your-themes-section.empty">+ <p className={styles.emptyTitle} data-flx="theme-settings.your-themes-section.empty-title">+ {i18n._(searching ? NO_THEMES_MATCH_YOUR_SEARCH_DESCRIPTOR : NO_THEMES_SAVED_YET_DESCRIPTOR)}+ </p>+ <p className={styles.note} data-flx="theme-settings.your-themes-section.note">+ {i18n._(+ searching+ ? TRY_A_DIFFERENT_NAME_OR_CLEAR_THE_SEARCH_DESCRIPTOR+ : IMPORT_A_CSS_FILE_TO_GET_STARTED_DESCRIPTOR,+ )}+ </p>+ </div>+ ) : (+ <div className={styles.list} data-flx="theme-settings.your-themes-section.list">+ {visibleThemes.map((theme) => (+ <ThemeRow key={theme.id} theme={theme} data-flx="theme-settings.your-themes-section.theme-row" />+ ))}+ </div>+ )}+ </SettingsSection>+ );+});