From 39ff55c297d6d2bc3909323005401798d0036d2e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 12:43:10 +0000 Subject: [PATCH 01/17] feat(web): theme catalog, detail, sources and installed themes (spec 043) Co-Authored-By: Claude Opus 5.5 Signed-off-by: Claude --- i18n/locales/en/app.json | 544 ++++++++++++++++++ web/src/components/AppLayout.tsx | 3 + web/src/components/ThemePreviewBanner.tsx | 114 ++++ .../components/themes/InstalledThemesCard.tsx | 109 ++++ web/src/components/themes/ThemeCard.tsx | 131 +++++ .../components/themes/ThemePreviewPanel.tsx | 55 ++ .../components/themes/ThemeSourceDialog.tsx | 304 ++++++++++ web/src/components/themes/formatWith.ts | 12 + web/src/components/themes/messages.ts | 157 +++++ web/src/components/themes/useThemeActions.ts | 84 +++ web/src/components/ui/SettingsNav.tsx | 27 +- web/src/lib/endpoints.ts | 62 ++ web/src/lib/enforceUnauthenticatedTheme.ts | 1 + web/src/lib/theme-export.ts | 68 ++- web/src/lib/themePermissions.ts | 3 + .../lib/useThemePreferences.installed.test.ts | 217 +++++++ web/src/lib/useThemePreferences.ts | 146 ++++- web/src/lib/useThemePreview.test.ts | 168 ++++++ web/src/lib/useThemePreview.ts | 102 ++++ web/src/router/tree.tsx | 31 + web/src/routes/AdminSettings.tsx | 9 +- web/src/routes/McpTokens.tsx | 2 + web/src/routes/ProfileSftp.tsx | 8 +- web/src/routes/ThemeCatalog.test.tsx | 279 +++++++++ web/src/routes/ThemeCatalog.tsx | 307 ++++++++++ web/src/routes/ThemeDetail.test.tsx | 201 +++++++ web/src/routes/ThemeDetail.tsx | 309 ++++++++++ .../routes/ThemeSettings.installed.test.tsx | 88 +++ web/src/routes/ThemeSettings.tsx | 160 +++++- web/src/routes/ThemeSettings.update.test.tsx | 93 +++ web/src/routes/ThemeSources.test.tsx | 121 ++++ web/src/routes/ThemeSources.tsx | 286 +++++++++ web/src/types.ts | 178 +++++- 33 files changed, 4345 insertions(+), 34 deletions(-) create mode 100644 web/src/components/ThemePreviewBanner.tsx create mode 100644 web/src/components/themes/InstalledThemesCard.tsx create mode 100644 web/src/components/themes/ThemeCard.tsx create mode 100644 web/src/components/themes/ThemePreviewPanel.tsx create mode 100644 web/src/components/themes/ThemeSourceDialog.tsx create mode 100644 web/src/components/themes/formatWith.ts create mode 100644 web/src/components/themes/messages.ts create mode 100644 web/src/components/themes/useThemeActions.ts create mode 100644 web/src/lib/themePermissions.ts create mode 100644 web/src/lib/useThemePreferences.installed.test.ts create mode 100644 web/src/lib/useThemePreview.test.ts create mode 100644 web/src/lib/useThemePreview.ts create mode 100644 web/src/routes/ThemeCatalog.test.tsx create mode 100644 web/src/routes/ThemeCatalog.tsx create mode 100644 web/src/routes/ThemeDetail.test.tsx create mode 100644 web/src/routes/ThemeDetail.tsx create mode 100644 web/src/routes/ThemeSettings.installed.test.tsx create mode 100644 web/src/routes/ThemeSettings.update.test.tsx create mode 100644 web/src/routes/ThemeSources.test.tsx create mode 100644 web/src/routes/ThemeSources.tsx diff --git a/i18n/locales/en/app.json b/i18n/locales/en/app.json index 983253300..4bcd6bb1e 100644 --- a/i18n/locales/en/app.json +++ b/i18n/locales/en/app.json @@ -4583,6 +4583,166 @@ "defaultMessage": "Your SFTP password", "description": "SFTP shown-once dialog: heading" }, + "web.components.themes.installed_themes_card.badge_installed": { + "defaultMessage": "Installed", + "description": "Settings theme: badge on an installed theme that is up to date" + }, + "web.components.themes.installed_themes_card.badge_source_removed": { + "defaultMessage": "Source removed", + "description": "Settings theme: badge on an installed theme whose source was removed" + }, + "web.components.themes.installed_themes_card.badge_update": { + "defaultMessage": "Update available", + "description": "Settings theme: badge on an installed theme with a newer version" + }, + "web.components.themes.installed_themes_card.browse": { + "defaultMessage": "Browse themes", + "description": "Settings theme: button linking to the theme catalog" + }, + "web.components.themes.installed_themes_card.installed_count": { + "defaultMessage": "{count, plural, one {# theme installed} other {# themes installed}}", + "description": "Settings theme: summary of installed themes" + }, + "web.components.themes.installed_themes_card.remove": { + "defaultMessage": "Remove", + "description": "Settings theme: button that removes an installed theme" + }, + "web.components.themes.installed_themes_card.remove_confirm": { + "defaultMessage": "Remove theme", + "description": "Settings theme: destructive confirm button for removing an installed theme" + }, + "web.components.themes.installed_themes_card.remove_text": { + "defaultMessage": "The theme is removed from your account. You can install it again from the catalog.", + "description": "Settings theme: confirm dialog text for removing an installed theme" + }, + "web.components.themes.installed_themes_card.remove_title": { + "defaultMessage": "Remove “{name}”?", + "description": "Settings theme: confirm dialog title for removing an installed theme" + }, + "web.components.themes.installed_themes_card.removed_count": { + "defaultMessage": "{count, plural, one {# source removed} other {# sources removed}}", + "description": "Settings theme: summary of installed themes whose source was removed" + }, + "web.components.themes.installed_themes_card.retention": { + "defaultMessage": "Installed themes are saved to your account only. Other users keep the theme they chose.", + "description": "Settings theme: note that installed themes are per user" + }, + "web.components.themes.installed_themes_card.selected_removed": { + "defaultMessage": "{name} was removed, you are back on Modern Pink", + "description": "Settings theme: one-time notice after the selected installed theme was removed; name is the theme display name" + }, + "web.components.themes.installed_themes_card.source_removed_caption": { + "defaultMessage": "Source removed · v{version}", + "description": "Settings theme: caption of an installed theme whose source was removed; version is the installed version" + }, + "web.components.themes.installed_themes_card.subtitle": { + "defaultMessage": "Themes installed for your account. Update or remove them here.", + "description": "Settings theme: subtitle under the installed themes heading" + }, + "web.components.themes.installed_themes_card.title": { + "defaultMessage": "Installed themes", + "description": "Settings theme: heading of the installed themes card" + }, + "web.components.themes.installed_themes_card.update": { + "defaultMessage": "Update", + "description": "Settings theme: button that updates an installed theme" + }, + "web.components.themes.installed_themes_card.update_count": { + "defaultMessage": "{count, plural, one {# update available} other {# updates available}}", + "description": "Settings theme: summary of installed themes with an update" + }, + "web.components.themes.installed_themes_card.update_line": { + "defaultMessage": "Update available: v{from} to v{to}", + "description": "Settings theme: line shown under an installed theme with an update" + }, + "web.components.themes.theme_card.badge_installed": { + "defaultMessage": "Installed", + "description": "Theme badge: the theme is installed and up to date" + }, + "web.components.themes.theme_card.badge_invalid": { + "defaultMessage": "Invalid", + "description": "Theme badge: the theme package failed validation" + }, + "web.components.themes.theme_card.badge_low_contrast": { + "defaultMessage": "Low contrast", + "description": "Theme badge: the theme fails the contrast check" + }, + "web.components.themes.theme_card.badge_source_removed": { + "defaultMessage": "Source removed", + "description": "Theme badge: the theme source was removed; the installed copy is kept" + }, + "web.components.themes.theme_card.badge_unverified": { + "defaultMessage": "Not verified", + "description": "Theme badge: the theme package signature is not verified" + }, + "web.components.themes.theme_card.badge_update": { + "defaultMessage": "Update available", + "description": "Theme badge: a newer version of the installed theme exists" + }, + "web.components.themes.theme_card.by_author": { + "defaultMessage": "by {author} · v{version}", + "description": "Theme card: mono meta line with the author and version" + }, + "web.components.themes.theme_card.dark_only": { + "defaultMessage": "Dark only", + "description": "Theme preview placeholder: the theme has only a dark mode" + }, + "web.components.themes.theme_card.install": { + "defaultMessage": "Install", + "description": "Theme card and detail: button that installs the theme for the user" + }, + "web.components.themes.theme_card.light_only": { + "defaultMessage": "Light only", + "description": "Theme preview placeholder: the theme has only a light mode" + }, + "web.components.themes.theme_card.mode_dark": { + "defaultMessage": "Dark", + "description": "Theme mode label: dark mode" + }, + "web.components.themes.theme_card.mode_light": { + "defaultMessage": "Light", + "description": "Theme mode label: light mode" + }, + "web.components.themes.theme_card.preview": { + "defaultMessage": "Preview", + "description": "Theme card and detail: button that previews the theme in place" + }, + "web.components.themes.theme_card.remove": { + "defaultMessage": "Remove", + "description": "Theme card and detail: button that removes an installed theme" + }, + "web.components.themes.theme_card.removed_placeholder": { + "defaultMessage": "Removed {name}", + "description": "Theme preview placeholder for an installed theme whose source was removed; name is the theme name" + }, + "web.components.themes.theme_card.unverified_source": { + "defaultMessage": "Signature not verified", + "description": "Theme card: source line when the package signature is not verified" + }, + "web.components.themes.theme_card.update": { + "defaultMessage": "Update", + "description": "Theme card and detail: button that updates an installed theme" + }, + "web.components.themes.theme_card.update_version": { + "defaultMessage": "v{from} → v{to}", + "description": "Theme card: version change shown when an update is available" + }, + "web.components.themes.theme_card.verified_source": { + "defaultMessage": "Signature verified", + "description": "Theme card: source line when the package signature is verified" + }, + "web.components.themes.theme_preview_banner.exit": { + "defaultMessage": "Exit preview", + "description": "Preview banner: button that ends the preview and restores the saved theme" + }, + "web.components.themes.theme_preview_banner.keep": { + "defaultMessage": "Keep", + "description": "Preview banner: button that installs and selects the previewed theme" + }, + "web.components.themes.theme_preview_banner.previewing": { + "defaultMessage": "Previewing {name}", + "description": "Preview banner: text naming the theme being previewed" + }, "web.components.ui.admin.edit_user_dialog.cancel": { "defaultMessage": "Cancel", "description": "Edit user dialog: button that closes the dialog without saving; keep it short" @@ -5319,6 +5479,10 @@ "defaultMessage": "Theme", "description": "Settings nav: label of the Theme settings page" }, + "web.components.ui.settings_nav.theme_sources": { + "defaultMessage": "Theme sources", + "description": "Settings nav: label of the Theme sources settings page (admins with themes:manage)" + }, "web.components.ui.settings_nav.updates": { "defaultMessage": "Updates", "description": "Settings nav: label of the Updates settings section" @@ -5515,6 +5679,14 @@ "defaultMessage": "invalid theme export: preferences.customCss exceeds the maximum length of {max} characters", "description": "Theme import error: the imported custom CSS is longer than the limit; {max} is the maximum number of characters" }, + "web.lib.theme_export.installed_fallback": { + "defaultMessage": "This export used the installed theme {name} {version} from {source}, which is not installed here. Modern Pink is used instead.", + "description": "Theme import notice: the exported installed theme is missing on this instance, so Modern Pink is applied; {name} is the theme name, {version} its version, {source} the theme source name" + }, + "web.lib.theme_export.installed_object": { + "defaultMessage": "invalid theme export: preferences.installed must be an object with source, name and version strings", + "description": "Theme import error: an installed theme export lacks its source, name or version" + }, "web.lib.theme_export.missing_field": { "defaultMessage": "invalid theme export: missing required field \"{field}\"", "description": "Theme import error: a required field is missing; {field} is the field path, such as preferences.presetId" @@ -12279,6 +12451,122 @@ "defaultMessage": "You need permission to change this server's settings.", "description": "Settings tab: footer text shown to users who can view but not change this server's settings" }, + "web.routes.theme_catalog.all_sources": { + "defaultMessage": "All sources", + "description": "Theme catalog: source filter option that shows every source" + }, + "web.routes.theme_catalog.all_tags": { + "defaultMessage": "All tags", + "description": "Theme catalog: tag filter option that clears the tag filter" + }, + "web.routes.theme_catalog.clear_filters": { + "defaultMessage": "Clear filters", + "description": "Theme catalog: button that resets the search, tag and source filters" + }, + "web.routes.theme_catalog.description": { + "defaultMessage": "Browse themes from your sources, preview them, and install them for your account.", + "description": "Theme catalog page: intro text under the heading" + }, + "web.routes.theme_catalog.empty_text": { + "defaultMessage": "Themes come from theme sources. Enable a source to browse themes. Administrators can manage sources in Theme sources.", + "description": "Theme catalog empty state: explanation text" + }, + "web.routes.theme_catalog.empty_title": { + "defaultMessage": "No theme sources enabled", + "description": "Theme catalog empty state: title when no source is enabled" + }, + "web.routes.theme_catalog.go_to_sources": { + "defaultMessage": "Go to Theme sources", + "description": "Theme catalog empty state: button linking to the theme sources page (admins only)" + }, + "web.routes.theme_catalog.no_results_text": { + "defaultMessage": "Try a different search term, another tag, or all sources.", + "description": "Theme catalog: empty state text when filters hide every theme" + }, + "web.routes.theme_catalog.no_results_title": { + "defaultMessage": "No themes match your filters", + "description": "Theme catalog: empty state title when filters hide every theme" + }, + "web.routes.theme_catalog.search_themes": { + "defaultMessage": "Search themes…", + "description": "Theme catalog: placeholder of the search input" + }, + "web.routes.theme_catalog.source_unreachable": { + "defaultMessage": "Source {name} could not be refreshed: {error}. Showing the last synced themes.", + "description": "Theme catalog: warning per source whose last refresh failed; name is the source name, error the last error" + }, + "web.routes.theme_catalog.title": { + "defaultMessage": "Theme catalog", + "description": "Theme catalog page: page heading" + }, + "web.routes.theme_detail.author": { + "defaultMessage": "Author", + "description": "Theme detail page: label of the author field" + }, + "web.routes.theme_detail.back_to_catalog": { + "defaultMessage": "Back to catalog", + "description": "Theme detail page: link back to the theme catalog" + }, + "web.routes.theme_detail.changelog_title": { + "defaultMessage": "Changelog", + "description": "Theme detail page: heading of the changelog card" + }, + "web.routes.theme_detail.description": { + "defaultMessage": "Preview a theme, then install it for your account.", + "description": "Theme detail page: intro text under the heading" + }, + "web.routes.theme_detail.description_title": { + "defaultMessage": "Description", + "description": "Theme detail page: heading of the description card" + }, + "web.routes.theme_detail.homepage": { + "defaultMessage": "Homepage", + "description": "Theme detail page: label of the homepage link" + }, + "web.routes.theme_detail.install_unavailable": { + "defaultMessage": "Install is unavailable: this theme has {count, plural, one {# problem} other {# problems}}. Ask the author to fix them and refresh the source.", + "description": "Theme detail page: helper text under the disabled Install button for an invalid theme" + }, + "web.routes.theme_detail.license": { + "defaultMessage": "License", + "description": "Theme detail page: label of the license field" + }, + "web.routes.theme_detail.preview_dark": { + "defaultMessage": "Dark", + "description": "Theme detail page: label of the dark preview panel" + }, + "web.routes.theme_detail.preview_light": { + "defaultMessage": "Light", + "description": "Theme detail page: label of the light preview panel" + }, + "web.routes.theme_detail.problems_found": { + "defaultMessage": "{count, plural, one {# problem found} other {# problems found}}", + "description": "Theme detail page: danger notice title for an invalid theme" + }, + "web.routes.theme_detail.problems_notice": { + "defaultMessage": "{name} cannot be installed until its author fixes these.", + "description": "Theme detail page: danger notice text for an invalid theme; name is the theme display name" + }, + "web.routes.theme_detail.problems_title": { + "defaultMessage": "Problems", + "description": "Theme detail page: heading of the problems card" + }, + "web.routes.theme_detail.title": { + "defaultMessage": "Theme details", + "description": "Theme detail page: page heading" + }, + "web.routes.theme_detail.update_from": { + "defaultMessage": "Update from {from} to {to}", + "description": "Theme detail page: helper text shown next to Update" + }, + "web.routes.theme_detail.version": { + "defaultMessage": "Version", + "description": "Theme detail page: label of the version field" + }, + "web.routes.theme_detail.version_installed": { + "defaultMessage": "{version} (installed {installed})", + "description": "Theme detail page: version value when an older version is installed" + }, "web.routes.theme_settings.a_stylesheet_layered_on_top_of_the": { "defaultMessage": "A stylesheet layered on top of the active base theme.", "description": "Theme settings: subtitle under the custom CSS overlay title: a stylesheet layered on top of the active base theme" @@ -12631,6 +12919,262 @@ "defaultMessage": "Your saved accent and surface", "description": "Theme settings: caption under the colour preview, naming the accent and surface colors you saved" }, + "web.routes.theme_sources.add_description": { + "defaultMessage": "Where the API discovers and pulls theme packages from.", + "description": "Theme sources dialog: text under the title when adding a source" + }, + "web.routes.theme_sources.add_source": { + "defaultMessage": "Add source", + "description": "Theme sources page: button that opens the add source dialog" + }, + "web.routes.theme_sources.add_title": { + "defaultMessage": "Add theme source", + "description": "Theme sources dialog: title when adding a source" + }, + "web.routes.theme_sources.admin_description": { + "defaultMessage": "Platform-wide configuration for this Gameplane instance.", + "description": "Theme sources page: intro text under the heading" + }, + "web.routes.theme_sources.admin_title": { + "defaultMessage": "Admin settings", + "description": "Theme sources page: page heading" + }, + "web.routes.theme_sources.builtin": { + "defaultMessage": "Built-in", + "description": "Theme sources table: badge on the built-in official source" + }, + "web.routes.theme_sources.cancel": { + "defaultMessage": "Cancel", + "description": "Theme sources dialog: button that closes the dialog without saving" + }, + "web.routes.theme_sources.card_description": { + "defaultMessage": "OCI registries, git repositories, HTTP indexes, and local folders the API pulls theme packages from. Installed copies stay with each user when a source is removed.", + "description": "Theme sources page: explanation under the sources card heading" + }, + "web.routes.theme_sources.card_title": { + "defaultMessage": "Theme sources", + "description": "Theme sources page: heading of the sources card" + }, + "web.routes.theme_sources.col_actions": { + "defaultMessage": "Actions", + "description": "Theme sources table: column header for the row action buttons" + }, + "web.routes.theme_sources.col_enabled": { + "defaultMessage": "On", + "description": "Theme sources table: column header for the enabled switch" + }, + "web.routes.theme_sources.col_last_sync": { + "defaultMessage": "Last sync", + "description": "Theme sources table: column header for the last sync time" + }, + "web.routes.theme_sources.col_name": { + "defaultMessage": "Name", + "description": "Theme sources table: column header for the source name" + }, + "web.routes.theme_sources.col_status": { + "defaultMessage": "Status", + "description": "Theme sources table: column header for the sync status" + }, + "web.routes.theme_sources.col_themes": { + "defaultMessage": "Themes", + "description": "Theme sources table: column header for the number of themes" + }, + "web.routes.theme_sources.col_type": { + "defaultMessage": "Type", + "description": "Theme sources table: column header for the source type" + }, + "web.routes.theme_sources.delete_action": { + "defaultMessage": "Delete", + "description": "Theme sources table: icon button label that deletes a source" + }, + "web.routes.theme_sources.delete_confirm": { + "defaultMessage": "Delete source", + "description": "Theme sources: destructive confirm button for deleting a source" + }, + "web.routes.theme_sources.delete_text": { + "defaultMessage": "The source and its catalog entries are removed. Installed copies stay with each user.", + "description": "Theme sources: confirm dialog text for deleting a source" + }, + "web.routes.theme_sources.delete_title": { + "defaultMessage": "Delete source “{name}”?", + "description": "Theme sources: confirm dialog title for deleting a source; name is the source name" + }, + "web.routes.theme_sources.edit_action": { + "defaultMessage": "Edit", + "description": "Theme sources table: icon button label that edits a source" + }, + "web.routes.theme_sources.edit_description": { + "defaultMessage": "Change how the API reaches and verifies this source. The type cannot be changed.", + "description": "Theme sources dialog: text under the title when editing a source" + }, + "web.routes.theme_sources.edit_title": { + "defaultMessage": "Edit theme source", + "description": "Theme sources dialog: title when editing a source" + }, + "web.routes.theme_sources.field_allow": { + "defaultMessage": "Allow list", + "description": "Theme sources dialog: label of the theme name filter field" + }, + "web.routes.theme_sources.field_git_url": { + "defaultMessage": "Repository URL", + "description": "Theme sources dialog: label of the git repository URL field" + }, + "web.routes.theme_sources.field_http_url": { + "defaultMessage": "Index URL", + "description": "Theme sources dialog: label of the HTTP index URL field" + }, + "web.routes.theme_sources.field_identity": { + "defaultMessage": "Cosign identity", + "description": "Theme sources dialog: label of the keyless identity field" + }, + "web.routes.theme_sources.field_insecure": { + "defaultMessage": "Allow plain HTTP (local registries only)", + "description": "Theme sources dialog: switch label for plain HTTP registries" + }, + "web.routes.theme_sources.field_interval": { + "defaultMessage": "Refresh interval", + "description": "Theme sources dialog: label of the refresh interval field" + }, + "web.routes.theme_sources.field_issuer": { + "defaultMessage": "Cosign issuer", + "description": "Theme sources dialog: label of the keyless issuer field" + }, + "web.routes.theme_sources.field_local_path": { + "defaultMessage": "Folder path", + "description": "Theme sources dialog: label of the local folder path field" + }, + "web.routes.theme_sources.field_name": { + "defaultMessage": "Name", + "description": "Theme sources dialog: label of the source name field" + }, + "web.routes.theme_sources.field_path": { + "defaultMessage": "Path in repository", + "description": "Theme sources dialog: label of the optional path inside a git repository field" + }, + "web.routes.theme_sources.field_public_key": { + "defaultMessage": "Public key (PEM)", + "description": "Theme sources dialog: label of the cosign public key field" + }, + "web.routes.theme_sources.field_ref": { + "defaultMessage": "Git ref", + "description": "Theme sources dialog: label of the optional git branch or tag field" + }, + "web.routes.theme_sources.field_registry_url": { + "defaultMessage": "Registry URL", + "description": "Theme sources dialog: label of the OCI registry URL field" + }, + "web.routes.theme_sources.field_required": { + "defaultMessage": "Fill in the required fields.", + "description": "Theme sources dialog: validation error when a required field is empty" + }, + "web.routes.theme_sources.field_themes": { + "defaultMessage": "Themes", + "description": "Theme sources dialog: label of the OCI theme names field" + }, + "web.routes.theme_sources.field_type": { + "defaultMessage": "Type", + "description": "Theme sources dialog: label of the source type select" + }, + "web.routes.theme_sources.field_verify": { + "defaultMessage": "Signature verification", + "description": "Theme sources dialog: label of the signature verification select" + }, + "web.routes.theme_sources.footer": { + "defaultMessage": "The official source is built in. It can be disabled but not deleted.", + "description": "Theme sources page: info line under the table about the built-in source" + }, + "web.routes.theme_sources.hint_allow": { + "defaultMessage": "Optional theme name filter, exact names or globs, comma-separated.", + "description": "Theme sources dialog: hint under the allow list field" + }, + "web.routes.theme_sources.hint_identity": { + "defaultMessage": "Signer identity to match, exact or regexp.", + "description": "Theme sources dialog: hint under the identity field" + }, + "web.routes.theme_sources.hint_interval": { + "defaultMessage": "How often the catalog re-indexes. Defaults to 1h.", + "description": "Theme sources dialog: hint under the refresh interval field" + }, + "web.routes.theme_sources.hint_issuer": { + "defaultMessage": "OIDC issuer that signed the packages.", + "description": "Theme sources dialog: hint under the issuer field" + }, + "web.routes.theme_sources.hint_name": { + "defaultMessage": "DNS label identifying this source.", + "description": "Theme sources dialog: hint under the name field" + }, + "web.routes.theme_sources.hint_public_key": { + "defaultMessage": "Paste the PEM public key that signed the packages.", + "description": "Theme sources dialog: hint under the public key field" + }, + "web.routes.theme_sources.hint_themes": { + "defaultMessage": "Comma-separated theme names (registries can't be enumerated).", + "description": "Theme sources dialog: hint under the OCI theme names field" + }, + "web.routes.theme_sources.hint_verify": { + "defaultMessage": "Require a valid cosign signature on every theme package from this source.", + "description": "Theme sources dialog: hint under the signature verification select" + }, + "web.routes.theme_sources.interval_invalid": { + "defaultMessage": "Use a duration such as 30m or 1h, at least 5m.", + "description": "Theme sources dialog: validation error for the refresh interval" + }, + "web.routes.theme_sources.refresh_action": { + "defaultMessage": "Refresh", + "description": "Theme sources table: icon button label that refreshes a source now" + }, + "web.routes.theme_sources.status_failed": { + "defaultMessage": "Sync failed: {error}", + "description": "Theme sources table: status of a source whose last sync failed; error is the last error" + }, + "web.routes.theme_sources.status_never": { + "defaultMessage": "Never synced", + "description": "Theme sources table: status of a source that has not synced yet" + }, + "web.routes.theme_sources.status_synced": { + "defaultMessage": "Synced", + "description": "Theme sources table: status of a source that synced successfully" + }, + "web.routes.theme_sources.submit_add": { + "defaultMessage": "Add source", + "description": "Theme sources dialog: submit button when adding a source" + }, + "web.routes.theme_sources.submit_save": { + "defaultMessage": "Save changes", + "description": "Theme sources dialog: submit button when editing a source" + }, + "web.routes.theme_sources.type_git": { + "defaultMessage": "Git repository", + "description": "Theme sources dialog: source type option for a git repository" + }, + "web.routes.theme_sources.type_http": { + "defaultMessage": "HTTP index", + "description": "Theme sources dialog: source type option for an HTTP index" + }, + "web.routes.theme_sources.type_local": { + "defaultMessage": "Local folder", + "description": "Theme sources dialog: source type option for a local folder" + }, + "web.routes.theme_sources.type_oci": { + "defaultMessage": "OCI registry", + "description": "Theme sources dialog: source type option for an OCI registry" + }, + "web.routes.theme_sources.verify_key": { + "defaultMessage": "Public key", + "description": "Theme sources dialog: signature verification option for a public key" + }, + "web.routes.theme_sources.verify_keyless": { + "defaultMessage": "Keyless (issuer + identity)", + "description": "Theme sources dialog: signature verification option for keyless signing" + }, + "web.routes.theme_sources.verify_none": { + "defaultMessage": "None", + "description": "Theme sources dialog: signature verification option for no verification" + }, + "web.routes.themes.preview_unavailable_safe_mode": { + "defaultMessage": "Previews are unavailable in safe mode.", + "description": "Theme pages: error shown when a preview is requested while safe mode is active, which suspends installed themes" + }, "web.routes.users.account_is_oidc_managed": { "defaultMessage": "Account is OIDC-managed", "description": "Users: tooltip explaining that an OIDC account's password is managed elsewhere" diff --git a/web/src/components/AppLayout.tsx b/web/src/components/AppLayout.tsx index 8b3c0d769..bb7c5b212 100644 --- a/web/src/components/AppLayout.tsx +++ b/web/src/components/AppLayout.tsx @@ -35,6 +35,7 @@ import { useThemePreferences, } from "@/lib/useThemePreferences"; import { SafeModeBanner } from "@/components/ui/SafeModeBanner"; +import { ThemePreviewBanner } from "@/components/ThemePreviewBanner"; import { TelemetryNotice } from "@/components/ui/TelemetryNotice"; import { useOptionalIntl } from "@/lib/i18n/format"; @@ -216,6 +217,8 @@ export function AppLayout() { return ( <> + {/* Theme preview banner (spec 043): shown only while a theme is previewed. */} + {/* Safe-mode banner: sticky at the top of the viewport so it stays reachable while recovering from broken custom CSS. Dismiss only hides it — safe mode remains active for the session. */} diff --git a/web/src/components/ThemePreviewBanner.tsx b/web/src/components/ThemePreviewBanner.tsx new file mode 100644 index 000000000..1062a7eb4 --- /dev/null +++ b/web/src/components/ThemePreviewBanner.tsx @@ -0,0 +1,114 @@ +import { useEffect, useState } from "react"; +import { useLocation } from "@tanstack/react-router"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import type { MessageDescriptor } from "react-intl"; +import { Eye } from "lucide-react"; +import { APIError } from "@/lib/api"; +import { Themes, Users } from "@/lib/endpoints"; +import { useOptionalIntl } from "@/lib/i18n/format"; +import { + DEFAULT_THEME_PREFERENCES, + readThemePreferences, +} from "@/lib/useThemePreferences"; +import { + dropThemePreview, + exitThemePreview, + isThemePagePath, + useThemePreview, + type ThemePreviewTheme, +} from "@/lib/useThemePreview"; +import { themePreviewBannerMessages } from "@/components/themes/messages"; + +// Keep saves the previewed theme: install and select it when it is not +// installed yet, otherwise select the installed copy. Either way the server +// copy is refetched and becomes the applied theme. +async function keepTheme(theme: ThemePreviewTheme): Promise { + if (theme.installedId === null) { + await Themes.install({ catalogId: theme.catalogId, select: true }); + return; + } + const prefs = readThemePreferences() ?? DEFAULT_THEME_PREFERENCES; + await Users.updatePreferences({ + themeType: "installed", + presetId: prefs.presetId, + appearanceMode: prefs.appearanceMode, + customCssEnabled: prefs.customCssEnabled, + installedThemeId: theme.installedId, + }); +} + +/** + * Preview banner (design: "Theme preview — banner"). Mounted at the top of the + * app shell. It shows while a theme is previewed, and the preview ends on + * Exit, on leaving the theme pages, or on unmount. Nothing is written until Keep. + */ +export function ThemePreviewBanner() { + const intl = useOptionalIntl(); + const location = useLocation(); + const { preview } = useThemePreview(); + const queryClient = useQueryClient(); + const [error, setError] = useState(null); + + // Restore the saved theme when the user leaves the theme pages, and on unmount. + useEffect(() => { + if (preview !== null && !isThemePagePath(location.pathname)) exitThemePreview(); + }, [preview, location.pathname]); + useEffect(() => () => exitThemePreview(), []); + + const keep = useMutation({ + mutationFn: keepTheme, + onSuccess: () => { + setError(null); + dropThemePreview(); + void queryClient.invalidateQueries({ queryKey: ["me"] }); + void queryClient.invalidateQueries({ queryKey: ["installed-themes"] }); + void queryClient.invalidateQueries({ queryKey: ["theme-catalog"] }); + }, + onError: (err: unknown) => { + setError(err instanceof APIError ? err.body || err.message : err instanceof Error ? err.message : String(err)); + }, + }); + + if (preview === null) return null; + const previewDescriptor: MessageDescriptor = themePreviewBannerMessages.previewing; + const previewValues: Record = { name: preview.displayName }; + + return ( +
+
+
+
+ + +
+
+ ); +} diff --git a/web/src/components/themes/InstalledThemesCard.tsx b/web/src/components/themes/InstalledThemesCard.tsx new file mode 100644 index 000000000..a45a4afe2 --- /dev/null +++ b/web/src/components/themes/InstalledThemesCard.tsx @@ -0,0 +1,109 @@ +// Installed themes card on the Theme settings page (spec 043, T038, design +// 385085606-1). Lists the themes the signed-in user installed from the +// catalog, with Update and Remove actions. Rendered only when the user has +// at least one installed theme; the parent owns the mutations and dialogs. +import { Button, Card, Chip } from "@heroui/react"; +import { Link } from "@tanstack/react-router"; +import { Search } from "lucide-react"; +import { useOptionalIntl } from "@/lib/i18n/format"; +import type { InstalledTheme } from "@/types"; +import { formatThemeMessage, installedThemesMessages as M } from "./messages"; + +export interface InstalledThemesCardProps { + installed: InstalledTheme[]; + busy: boolean; + onUpdate: (theme: InstalledTheme) => void; + onRemove: (theme: InstalledTheme) => void; +} + +export function InstalledThemesCard({ installed, busy, onUpdate, onRemove }: InstalledThemesCardProps) { + const intl = useOptionalIntl(); + const updates = installed.filter((t) => t.updateAvailable && !t.sourceRemoved).length; + const removed = installed.filter((t) => t.sourceRemoved).length; + + return ( + + +
{intl.formatMessage(M.title)}
+
+ {intl.formatMessage({ id: "web.components.themes.installed_themes_card.subtitle", defaultMessage: "Themes installed for your account. Update or remove them here.", description: "Settings theme: subtitle under the installed themes heading" })} +
+
+ +
+
+ {[ + formatThemeMessage(intl, M.installedCount, { count: String(installed.length) }), + updates > 0 ? formatThemeMessage(intl, M.updateCount, { count: String(updates) }) : null, + removed > 0 ? formatThemeMessage(intl, M.removedCount, { count: String(removed) }) : null, + ] + .filter((part): part is string => part !== null) + .join(" · ")} +
+ + + +
+ +
    + {installed.map((theme) => ( +
  • +
    +
    + {theme.displayName || theme.name} + {theme.sourceRemoved ? ( + + {intl.formatMessage({ id: "web.components.themes.installed_themes_card.badge_source_removed", defaultMessage: "Source removed", description: "Settings theme: badge on an installed theme whose source was removed" })} + + ) : theme.updateAvailable ? ( + + {intl.formatMessage({ id: "web.components.themes.installed_themes_card.badge_update", defaultMessage: "Update available", description: "Settings theme: badge on an installed theme with a newer version" })} + + ) : ( + + {intl.formatMessage({ id: "web.components.themes.installed_themes_card.badge_installed", defaultMessage: "Installed", description: "Settings theme: badge on an installed theme that is up to date" })} + + )} +
    +
    + {theme.sourceRemoved + ? formatThemeMessage(intl, M.sourceRemovedCaption, { version: String(theme.version) }) + : `v${theme.version} · ${theme.modes.map((m) => (m === "dark" ? "Dark" : "Light")).join(", ")}`} +
    +
    +
    + {theme.updateAvailable && !theme.sourceRemoved ? ( + + ) : null} + +
    +
  • + ))} +
+
+
+ ); +} diff --git a/web/src/components/themes/ThemeCard.tsx b/web/src/components/themes/ThemeCard.tsx new file mode 100644 index 000000000..c1a51916a --- /dev/null +++ b/web/src/components/themes/ThemeCard.tsx @@ -0,0 +1,131 @@ +// Catalog grid tile for one theme (spec 043, T029). The primary action follows +// the state: Update when a newer version exists, Remove when installed, Install +// otherwise. Invalid themes show no Preview and a disabled Install. +import { Link } from "@tanstack/react-router"; +import { Button, Card, CardContent, CardFooter, CardHeader, Chip } from "@heroui/react"; +import { ShieldCheck, TriangleAlert } from "lucide-react"; +import type { ThemeCatalogItem } from "@/types"; +import { useOptionalIntl } from "@/lib/i18n/format"; +import { formatWith } from "@/components/themes/formatWith"; +import { cn } from "@/lib/utils"; +import { themeCardMessages } from "@/components/themes/messages"; +import { ThemePreviewPanel } from "@/components/themes/ThemePreviewPanel"; + +interface StatusBadge { + color: "success" | "warning" | "danger"; + message: (typeof themeCardMessages)[keyof typeof themeCardMessages]; +} + +// One badge per theme, in priority order (the design shows a single chip). +function statusBadge(item: ThemeCatalogItem): StatusBadge | null { + if (item.status === "invalid") return { color: "danger", message: themeCardMessages.badgeInvalid }; + if (item.updateAvailable) return { color: "warning", message: themeCardMessages.badgeUpdate }; + if (item.installed) return { color: "success", message: themeCardMessages.badgeInstalled }; + if (item.lowContrast) return { color: "warning", message: themeCardMessages.badgeLowContrast }; + if (item.status === "unverified") return { color: "warning", message: themeCardMessages.badgeUnverified }; + return null; +} + +export function ThemeStatusBadge({ item }: { item: ThemeCatalogItem }) { + const intl = useOptionalIntl(); + const badge = statusBadge(item); + if (!badge) return null; + return ( + + {intl.formatMessage(badge.message)} + + ); +} + +export interface ThemeCardProps { + item: ThemeCatalogItem; + busy?: boolean; + onPreview: (item: ThemeCatalogItem) => void; + onInstall: (item: ThemeCatalogItem) => void; + onUpdate: (item: ThemeCatalogItem) => void; + onRemove: (item: ThemeCatalogItem) => void; +} + +export function ThemeCard({ item, busy = false, onPreview, onInstall, onUpdate, onRemove }: ThemeCardProps) { + const intl = useOptionalIntl(); + const invalid = item.status === "invalid"; + const unverified = item.status === "unverified"; + + const versionText = + item.updateAvailable && item.installed + ? formatWith(intl, themeCardMessages.updateVersion, { from: item.installed.version, to: item.version }) + : item.version; + + const modeLabels = + item.modes.length === 1 + ? [intl.formatMessage(item.modes[0] === "dark" ? themeCardMessages.darkOnly : themeCardMessages.lightOnly)] + : item.modes.map((m) => intl.formatMessage(m === "dark" ? themeCardMessages.modeDark : themeCardMessages.modeLight)); + + const SourceIcon = unverified ? TriangleAlert : ShieldCheck; + const sourceTitle = intl.formatMessage(unverified ? themeCardMessages.unverifiedSource : themeCardMessages.verifiedSource); + + return ( + + +
+ + +
+
+ + {item.displayName} + + +
+

+ {formatWith(intl, themeCardMessages.byAuthor, { author: item.author, version: versionText })} +

+
+ +

{item.description}

+
+ {modeLabels.map((label) => ( + {label} + ))} +
+ + +
+ + {invalid ? null : ( + + )} + {item.updateAvailable ? ( + + ) : item.installed ? ( + + ) : ( + + )} + +
+ ); +} diff --git a/web/src/components/themes/ThemePreviewPanel.tsx b/web/src/components/themes/ThemePreviewPanel.tsx new file mode 100644 index 000000000..304fa86ec --- /dev/null +++ b/web/src/components/themes/ThemePreviewPanel.tsx @@ -0,0 +1,55 @@ +// One preview image of a catalog theme (light or dark). The image comes from +// the API preview endpoint and is sent with the session cookie, so no fetch is +// needed. A theme without the requested mode, or an image that fails to load, +// shows the dashed placeholder from the design ("Dark only" / "Light only"). +import { useState } from "react"; +import { Moon } from "lucide-react"; +import { Themes } from "@/lib/endpoints"; +import type { ThemeMode } from "@/types"; +import { useOptionalIntl } from "@/lib/i18n/format"; +import { cn } from "@/lib/utils"; +import { themeCardMessages } from "@/components/themes/messages"; + +export interface ThemePreviewPanelProps { + themeId: number; + mode: ThemeMode; + /** The modes the theme ships; a single-mode theme names its only mode in the placeholder. */ + modes: readonly ThemeMode[]; + className?: string; +} + +export function ThemePreviewPanel({ themeId, mode, modes, className }: ThemePreviewPanelProps) { + const intl = useOptionalIntl(); + const [failed, setFailed] = useState(false); + const missing = !modes.includes(mode); + + if (missing || failed) { + const onlyLabel = + modes.length === 1 + ? intl.formatMessage(modes[0] === "dark" ? themeCardMessages.darkOnly : themeCardMessages.lightOnly) + : null; + return ( +
+
+ ); + } + + return ( + setFailed(true)} + className={cn("aspect-[16/10] w-full rounded-md border border-border object-cover", className)} + data-testid="theme-preview" + /> + ); +} diff --git a/web/src/components/themes/ThemeSourceDialog.tsx b/web/src/components/themes/ThemeSourceDialog.tsx new file mode 100644 index 000000000..75f312829 --- /dev/null +++ b/web/src/components/themes/ThemeSourceDialog.tsx @@ -0,0 +1,304 @@ +// Add / edit dialog for a theme source (spec 043, T049, designs 906199366-709 +// and -1485). The type cannot change on edit. Pull secret is not offered: the +// API refuses credentials (OD-5). Field validation is minimal and client-side; +// the server's plain-English 422 message is shown inline. +import { useState, type ReactNode } from "react"; +import { + Button, + Description, + Input, + Label, + ListBox, + ListBoxItem, + Modal, + ModalBackdrop, + ModalBody, + ModalContainer, + ModalDialog, + ModalFooter, + ModalHeader, + ModalHeading, + Select, + Switch, + TextArea, +} from "@heroui/react"; +import { Loader2 } from "lucide-react"; +import type { MessageDescriptor } from "react-intl"; +import { useOptionalIntl } from "@/lib/i18n/format"; +import type { ThemeSource, ThemeSourceInput, ThemeSourceType, ThemeSourceVerify } from "@/types"; +import { themeSourcesMessages as M } from "./messages"; + +type VerifyMode = "none" | "key" | "keyless"; + +interface FormState { + name: string; + type: ThemeSourceType; + ociUrl: string; + ociThemes: string; + ociInsecure: boolean; + verify: VerifyMode; + publicKey: string; + issuer: string; + identity: string; + allow: string; + interval: string; + gitUrl: string; + gitRef: string; + gitPath: string; + httpUrl: string; + localPath: string; +} + +const TYPE_OPTIONS: Array<{ value: ThemeSourceType; label: MessageDescriptor }> = [ + { value: "oci", label: M.typeOci }, + { value: "git", label: M.typeGit }, + { value: "http", label: M.typeHttp }, + { value: "local", label: M.typeLocal }, +]; + +const VERIFY_OPTIONS: Array<{ value: VerifyMode; label: MessageDescriptor }> = [ + { value: "none", label: M.verifyNone }, + { value: "key", label: M.verifyKey }, + { value: "keyless", label: M.verifyKeyless }, +]; + +// The API stores refreshInterval in seconds (minimum 300). +const MIN_INTERVAL_SECONDS = 300; + +export function intervalToText(seconds: number): string { + return seconds % 3600 === 0 ? `${seconds / 3600}h` : `${seconds / 60}m`; +} + +export function parseInterval(text: string): number | null { + const m = /^(\d+)([mh])$/.exec(text.trim()); + if (!m) return null; + const seconds = Number(m[1]) * (m[2] === "h" ? 3600 : 60); + return seconds >= MIN_INTERVAL_SECONDS ? seconds : null; +} + +export function splitList(text: string): string[] { + return text.split(",").map((s) => s.trim()).filter((s) => s !== ""); +} + +function initialForm(source: ThemeSource | null): FormState { + const verify = source?.verify; + const mode: VerifyMode = verify?.keyless ? "keyless" : verify?.key ? "key" : "none"; + return { + name: source?.name ?? "", + type: source?.type ?? "oci", + ociUrl: source?.spec.oci?.url ?? "", + ociThemes: (source?.spec.oci?.themes ?? []).join(", "), + ociInsecure: source?.spec.oci?.insecure ?? false, + verify: mode, + publicKey: verify?.key ?? "", + issuer: verify?.keyless?.issuer ?? "", + identity: verify?.keyless?.identity ?? "", + allow: (source?.spec.allow ?? []).join(", "), + interval: intervalToText(source?.refreshInterval ?? 3600), + gitUrl: source?.spec.git?.url ?? "", + gitRef: source?.spec.git?.ref ?? "", + gitPath: source?.spec.git?.path ?? "", + httpUrl: source?.spec.http?.url ?? "", + localPath: source?.spec.local?.path ?? "", + }; +} + +// requiredFilled reports whether the fields the chosen type needs are present. +function requiredFilled(f: FormState, editing: boolean): boolean { + if (!editing && f.name.trim() === "") return false; + if (parseInterval(f.interval) === null) return false; + switch (f.type) { + case "oci": + if (f.ociUrl.trim() === "" || splitList(f.ociThemes).length === 0) return false; + if (f.verify === "key") return f.publicKey.trim() !== ""; + if (f.verify === "keyless") return f.issuer.trim() !== "" && f.identity.trim() !== ""; + return true; + case "git": + return f.gitUrl.trim() !== ""; + case "http": + return f.httpUrl.trim() !== ""; + case "local": + return f.localPath.trim() !== ""; + } +} + +// buildInput maps the form onto the API body. Callers check requiredFilled first. +export function buildInput(f: FormState, editing: ThemeSource | null): ThemeSourceInput { + const interval = parseInterval(f.interval) ?? MIN_INTERVAL_SECONDS; + const allow = splitList(f.allow); + let verify: ThemeSourceVerify | null = null; + let spec: ThemeSourceInput["spec"]; + switch (f.type) { + case "oci": + if (f.verify === "key") verify = { key: f.publicKey.trim() }; + if (f.verify === "keyless") verify = { keyless: { issuer: f.issuer.trim(), identity: f.identity.trim() } }; + spec = { oci: { url: f.ociUrl.trim(), themes: splitList(f.ociThemes), insecure: f.ociInsecure } }; + break; + case "git": { + const ref = f.gitRef.trim(); + const path = f.gitPath.trim(); + spec = { git: { url: f.gitUrl.trim(), ...(ref ? { ref } : {}), ...(path ? { path } : {}) } }; + break; + } + case "http": + spec = { http: { url: f.httpUrl.trim() } }; + break; + case "local": + spec = { local: { path: f.localPath.trim() } }; + break; + } + return { + name: editing ? editing.name : f.name.trim(), + type: f.type, + spec: allow.length > 0 ? { ...spec, allow } : spec, + verify, + refreshInterval: interval, + enabled: editing ? editing.enabled : true, + }; +} + +export interface ThemeSourceDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + /** null adds a source; a source edits it (name and type are fixed). */ + source: ThemeSource | null; + busy: boolean; + error: string | null; + onSubmit: (input: ThemeSourceInput) => void; +} + +export function ThemeSourceDialog({ open, onOpenChange, source, busy, error, onSubmit }: ThemeSourceDialogProps) { + // The dialog body remounts per open (the parent keys it), so the form + // starts from the current source each time it opens. + if (!open) return null; + return ; +} + +function ThemeSourceForm({ onOpenChange, source, busy, error, onSubmit }: Omit) { + const intl = useOptionalIntl(); + const editing = source !== null; + const [f, setF] = useState(() => initialForm(source)); + const [touched, setTouched] = useState(false); + const set = (patch: Partial) => setF((cur) => ({ ...cur, ...patch })); + const filled = requiredFilled(f, editing); + const label = (d: MessageDescriptor) => intl.formatMessage(d); + + const submit = () => { + setTouched(true); + if (!filled || busy) return; + onSubmit(buildInput(f, source)); + }; + + const field = (id: string, text: MessageDescriptor, input: ReactNode, hint?: MessageDescriptor) => ( +
+ + {input} + {hint ? {label(hint)} : null} +
+ ); + + return ( + + + + + + {label(editing ? M.editTitle : M.addTitle)} +

{label(editing ? M.editDescription : M.addDescription)}

+
+ + {!editing && field("ts-name", M.fieldName, set({ name: e.target.value.toLowerCase() })} placeholder="community" />, M.hintName)} + +
+ +
+ + {f.type === "oci" && ( + <> + {field("ts-oci-url", M.fieldRegistryUrl, set({ ociUrl: e.target.value })} placeholder="ghcr.io/gameplane/themes" />)} + {field("ts-oci-themes", M.fieldThemes, set({ ociThemes: e.target.value })} placeholder="aurora-night, paper-light" />, M.hintThemes)} + set({ ociInsecure: v })} aria-label={label(M.fieldInsecure)}> + + {label(M.fieldInsecure)} + + + + + +
+ + {label(M.hintVerify)} +
+ {f.verify === "key" && field("ts-public-key", M.fieldPublicKey,