* Group settings navigation menu Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Revert "Group settings navigation menu" This reverts commit 5983a4e82074b8dab1084af1cadd803ba28ea65d. * Standardize settings layout feedback Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Fix settings save status timer typing Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Retain settings save status Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Report color mode save state Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Match Appearance settings to two-column layout Rebuild Appearance into Color mode & Theme, Localization, and Density & type sections with responsive two-column grids, consistent section headers, page description, and green save status. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Migrate settings pages to SettingsPageLayout and SettingsSection Replace ScrollableOverlay/max-w-3xl shells with the shared settings layout primitives across entity and static settings pages, normalize section headers, and add settings.page.behavior.description locales. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Unify remaining settings pages on shared section chrome Wire Appearance, Projects, and Remote Instances through SettingsSection/SettingsPageLayout so every settings surface shares the same header, divider, and page shell treatment. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Align settings UI with OpenChamber design system kit Apply kit geometry and control specs: 840px content width, 32/48 padding, fixed 260/280 sidebars, radius/spacing tokens, settings select height, stepper dimensions, and shared field/link typography. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Migrate OpenChamberVisualSettings to shared settings primitives Replace ad-hoc radio/checkbox/chip/field layouts with SettingsSection shared chrome for Appearance, Density, Navigation, Chat/behavior, and Privacy while preserving handlers and data-settings-item anchors. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Migrate settings pages to shared field/checkbox/radio primitives Unify Defaults, Notifications, Behavior, Git, Session Retention, Passkeys, OpenCode CLI, Commands, About, Keyboard Shortcuts, and Desktop Network on SettingsFieldRow / SettingsCheckboxRow / SettingsRadioGroup / SettingsChipGroup for consistent grid, spacing, and DRY layout. Also remove the GitPage double SettingsSection wrap around GitHubSettings. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Unify remaining settings pages onto shared field primitives Migrate Agents, Snippets, Skills, Usage, MCP identity rows and selects to SettingsFieldRow/CheckboxRow/ChipGroup and SETTINGS_SELECT_*; align page titles; light-touch Voice/Tunnel/Providers/Plugins without rewriting complex OAuth, permissions, or tunnel flows. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Polish settings section dividers and transport helper text Slightly stronger section borders for clearer group separation, and keep message-stream transport description under the chip control. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Fix settings grid alignment, control heights, and Chat section titles Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Tighten settings grid: flat Chat 2x2 and full-width stacked selects Message options use a flat two-column grid so row headers share a baseline. Stacked selects fill their column; field-row selects keep a fixed sm:w-56 width. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Align mixed settings controls to shared FieldRow/CheckboxRow grid Separate FieldRows from CheckboxRows with SettingsInset, move enum radios into ControlGroups, and convert misplaced StackedFields to full-width FieldRows so left edges no longer clash. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Translate Behavior response-style preset labels for es and pl Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Group settings nav into categories and improve icons/order Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Fix settings layout: fewer hrs, shared control widths, chat transport section Remove SettingsInset top borders, align App install/Density controls to full cluster width, give Message Stream Transport its own Chat section, and fold Sessions Small Model into the first section to cut extra dividers. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Align Voice and MCP settings labels with shared heading classes Swap form field labels to SETTINGS_FIELD_LABEL_CLASS and use SettingsGroupTitle for MCP control-group headings (manual auth fallback, request headers). Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Differentiate settings heading levels by context Page titles are larger and quieter than section titles; group and field labels use dedicated shared classes so hierarchy is consistent across settings surfaces without ad-hoc typography mixes. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Use shared settings title classes in SettingsView home Wire home and unavailable headings through the shared L1/L2 class constants so they stay aligned with SettingsPageLayout. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Keep settings number steppers from stretching +/- buttons Density & type NumberInputs no longer flex-grow across the row, and NumberInput locks minus/plus to fixed width so the plus side cannot inflate when the control is placed in a full-width cluster. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Place spacing and input-bar offset on their own row Density & type now lays out as font families, then font sizes, then Spacing Density / Input Bar Offset on the row below. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Regroup settings nav and improve Voice layout Drop Advanced/Usage/Git nav categories: Voice and About under Interface, Usage under OpenCode, Git under Workspace. Voice provider chips and STT model cards use shared settings primitives with roomier spacing and a two-column model grid. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * Space out chat feature groups in visual settings * Polish settings: save-state wiring, container-query layouts, unified dropdown triggers - Wire shared save indicator into Behavior page saves and git identity CRUD - Convert settings layout primitives and page rows from viewport to container queries so narrow panes stack instead of clipping - Unify custom dropdown triggers (model/agent/provider pickers) and remaining page selects on the settings control size - Bump global radius scale by 1px; align variant input with select size - Migrate stray raw controls (MCP OAuth checkbox, worktree remove button, git identity dialog rows, skills dialog labels) onto shared primitives - Make settings nav items span full sidebar width; trim nav to 240px * Add General settings page, regroup nav, cap control widths, promote chat feature headers * Mobile settings nav: plain background and touch-sized rows * Hide secondary settings descriptions behind clickable info hints * Move quota credentials to Usage, navigation settings to General, rename External Tunnel * Quiet settings save indicator: silent success, delayed spinner, visible errors * Rewrite settings-ui-patterns skill around shared primitives and refactored conventions * Remove settings starter page; open last visited page, defaulting to General * Settings polish: spacing, control sizes, trigger widths, readable model names, device dates * Centralize dropdown trigger chrome, settings nav polish, mobile-only input bar offset * Fix global line-height regression, auto-hide first-section divider, shortcut row spacing * Global line-height 1.45, align scheduled tasks header button with select * Hide editor toolbar and About in VS Code, animate chat render preview outside desktop dialog * Rebuild agent tool permissions on source-of-truth model Edit the agent's own permission map verbatim (inherit vs explicit actions, pattern rules only for pattern-capable keys), save permission-only, drop the server-side non-wildcard re-merge that resurrected deleted rules, and surface session-granted rules as read-only. * Agents model parameters polish: row spacing, variant dropdown, unified widths, dash for unset numbers --------- Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
410 lines
18 KiB
TypeScript
410 lines
18 KiB
TypeScript
import React from 'react';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Textarea } from '@/components/ui/textarea';
|
|
import { toast } from '@/components/ui';
|
|
import {
|
|
fetchMagicPromptOverrides,
|
|
getDefaultMagicPromptTemplate,
|
|
getMagicPromptDefinition,
|
|
resetAllMagicPromptOverrides,
|
|
resetMagicPromptOverride,
|
|
saveMagicPromptOverride,
|
|
type MagicPromptId,
|
|
} from '@/lib/magicPrompts';
|
|
import { useMagicPromptsStore } from '@/stores/useMagicPromptsStore';
|
|
import { useI18n } from '@/lib/i18n';
|
|
import { SettingsPageLayout } from '@/components/sections/shared/SettingsPageLayout';
|
|
import { SettingsSection } from '@/components/sections/shared/SettingsSection';
|
|
import { SettingsInfoHint } from '@/components/sections/shared/SettingsInfoHint';
|
|
|
|
type PromptBlock = {
|
|
id: MagicPromptId;
|
|
titleKey: string;
|
|
};
|
|
|
|
type PromptPageConfig = {
|
|
titleKey: string;
|
|
descriptionKey: string;
|
|
blocks: PromptBlock[];
|
|
};
|
|
|
|
const PROMPT_PAGE_MAP: Record<string, PromptPageConfig> = {
|
|
'git.commit.generate': {
|
|
titleKey: 'settings.magicPrompts.page.group.gitCommitGenerate.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.gitCommitGenerate.description',
|
|
blocks: [
|
|
{ id: 'git.commit.generate.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'git.commit.generate.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'git.pr.generate': {
|
|
titleKey: 'settings.magicPrompts.page.group.gitPrGenerate.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.gitPrGenerate.description',
|
|
blocks: [
|
|
{ id: 'git.pr.generate.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'git.pr.generate.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'github.pr.review': {
|
|
titleKey: 'settings.magicPrompts.page.group.githubPrReview.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.githubPrReview.description',
|
|
blocks: [
|
|
{ id: 'github.pr.review.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'github.pr.review.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'github.issue.review': {
|
|
titleKey: 'settings.magicPrompts.page.group.githubIssueReview.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.githubIssueReview.description',
|
|
blocks: [
|
|
{ id: 'github.issue.review.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'github.issue.review.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'github.pr.checks.review': {
|
|
titleKey: 'settings.magicPrompts.page.group.githubPrFailedChecksReview.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.githubPrFailedChecksReview.description',
|
|
blocks: [
|
|
{ id: 'github.pr.checks.review.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'github.pr.checks.review.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'github.pr.comments.review': {
|
|
titleKey: 'settings.magicPrompts.page.group.githubPrCommentsReview.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.githubPrCommentsReview.description',
|
|
blocks: [
|
|
{ id: 'github.pr.comments.review.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'github.pr.comments.review.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'github.pr.comment.single': {
|
|
titleKey: 'settings.magicPrompts.page.group.githubSinglePrCommentReview.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.githubSinglePrCommentReview.description',
|
|
blocks: [
|
|
{ id: 'github.pr.comment.single.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'github.pr.comment.single.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'git.conflict.resolve': {
|
|
titleKey: 'settings.magicPrompts.page.group.gitConflictResolve.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.gitConflictResolve.description',
|
|
blocks: [
|
|
{ id: 'git.conflict.resolve.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'git.conflict.resolve.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'git.integrate.cherrypick.resolve': {
|
|
titleKey: 'settings.magicPrompts.page.group.gitCherrypickConflictResolve.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.gitCherrypickConflictResolve.description',
|
|
blocks: [
|
|
{ id: 'git.integrate.cherrypick.resolve.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'git.integrate.cherrypick.resolve.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'plan.improve': {
|
|
titleKey: 'settings.magicPrompts.page.group.planImprove.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.planImprove.description',
|
|
blocks: [
|
|
{ id: 'plan.improve.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'plan.improve.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'plan.todo': {
|
|
titleKey: 'settings.magicPrompts.page.group.planTodo.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.planTodo.description',
|
|
blocks: [
|
|
{ id: 'plan.todo.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'plan.todo.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'plan.implement': {
|
|
titleKey: 'settings.magicPrompts.page.group.planImplement.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.planImplement.description',
|
|
blocks: [
|
|
{ id: 'plan.implement.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'plan.implement.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'session.summary': {
|
|
titleKey: 'settings.magicPrompts.page.group.sessionSummary.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.sessionSummary.description',
|
|
blocks: [
|
|
{ id: 'session.summary.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'session.summary.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'session.review': {
|
|
titleKey: 'settings.magicPrompts.page.group.sessionWorkspaceReview.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.sessionWorkspaceReview.description',
|
|
blocks: [
|
|
{ id: 'session.review.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'session.review.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'session.plan': {
|
|
titleKey: 'settings.magicPrompts.page.group.sessionFeaturePlan.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.sessionFeaturePlan.description',
|
|
blocks: [
|
|
{ id: 'session.plan.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'session.plan.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'session.craftGoal': {
|
|
titleKey: 'settings.magicPrompts.page.group.sessionCraftGoal.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.sessionCraftGoal.description',
|
|
blocks: [
|
|
{ id: 'session.craftGoal.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'session.craftGoal.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'session.catchup': {
|
|
titleKey: 'settings.magicPrompts.page.group.sessionCatchUp.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.sessionCatchUp.description',
|
|
blocks: [
|
|
{ id: 'session.catchup.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'session.catchup.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'session.debug': {
|
|
titleKey: 'settings.magicPrompts.page.group.sessionDebug.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.sessionDebug.description',
|
|
blocks: [
|
|
{ id: 'session.debug.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'session.debug.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'session.weigh': {
|
|
titleKey: 'settings.magicPrompts.page.group.sessionWeigh.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.sessionWeigh.description',
|
|
blocks: [
|
|
{ id: 'session.weigh.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'session.weigh.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'session.explore': {
|
|
titleKey: 'settings.magicPrompts.page.group.sessionExplore.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.sessionExplore.description',
|
|
blocks: [
|
|
{ id: 'session.explore.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'session.explore.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
'session.fusion': {
|
|
titleKey: 'settings.magicPrompts.page.group.sessionFusion.title',
|
|
descriptionKey: 'settings.magicPrompts.page.group.sessionFusion.description',
|
|
blocks: [
|
|
{ id: 'session.fusion.visible', titleKey: 'settings.magicPrompts.page.block.visiblePrompt' },
|
|
{ id: 'session.fusion.instructions', titleKey: 'settings.magicPrompts.page.block.instructions' },
|
|
],
|
|
},
|
|
};
|
|
|
|
const hasOwn = (input: Record<string, string>, key: string) => Object.prototype.hasOwnProperty.call(input, key);
|
|
const isVisiblePromptId = (id: MagicPromptId): boolean => id.endsWith('.visible');
|
|
|
|
export const MagicPromptsPage: React.FC = () => {
|
|
const { t } = useI18n();
|
|
const tUnsafe = React.useCallback((key: string) => t(key as Parameters<typeof t>[0]), [t]);
|
|
const selectedPromptId = useMagicPromptsStore((state) => state.selectedPromptId);
|
|
const [loading, setLoading] = React.useState(true);
|
|
const [overrides, setOverrides] = React.useState<Record<string, string>>({});
|
|
const [drafts, setDrafts] = React.useState<Record<string, string>>({});
|
|
const [savingIds, setSavingIds] = React.useState<Record<string, boolean>>({});
|
|
const [resettingIds, setResettingIds] = React.useState<Record<string, boolean>>({});
|
|
const [resettingAll, setResettingAll] = React.useState(false);
|
|
|
|
React.useEffect(() => {
|
|
let active = true;
|
|
const load = async () => {
|
|
setLoading(true);
|
|
try {
|
|
const nextOverrides = await fetchMagicPromptOverrides();
|
|
if (!active) return;
|
|
setOverrides(nextOverrides);
|
|
} catch (error) {
|
|
console.warn('Failed to load magic prompts:', error);
|
|
toast.error(t('settings.magicPrompts.page.toast.loadFailed'));
|
|
} finally {
|
|
if (active) {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
};
|
|
void load();
|
|
return () => {
|
|
active = false;
|
|
};
|
|
}, [t]);
|
|
|
|
const pageConfig = PROMPT_PAGE_MAP[selectedPromptId] ?? PROMPT_PAGE_MAP['git.commit.generate'];
|
|
const getBaseline = React.useCallback((id: MagicPromptId) => {
|
|
return hasOwn(overrides, id) ? overrides[id] : getDefaultMagicPromptTemplate(id);
|
|
}, [overrides]);
|
|
|
|
const getDraft = React.useCallback((id: MagicPromptId) => {
|
|
return drafts[id] ?? getBaseline(id);
|
|
}, [drafts, getBaseline]);
|
|
|
|
const setDraft = React.useCallback((id: MagicPromptId, value: string) => {
|
|
setDrafts((current) => {
|
|
if (current[id] === value) {
|
|
return current;
|
|
}
|
|
return { ...current, [id]: value };
|
|
});
|
|
}, []);
|
|
|
|
const savePrompt = React.useCallback(async (id: MagicPromptId) => {
|
|
const value = getDraft(id);
|
|
if (isVisiblePromptId(id) && value.trim().length === 0) {
|
|
toast.error(t('settings.magicPrompts.page.toast.visiblePromptRequired'));
|
|
return;
|
|
}
|
|
setSavingIds((current) => ({ ...current, [id]: true }));
|
|
try {
|
|
const payload = value === getDefaultMagicPromptTemplate(id)
|
|
? await resetMagicPromptOverride(id)
|
|
: await saveMagicPromptOverride(id, value);
|
|
setOverrides(payload.overrides);
|
|
toast.success(t('settings.magicPrompts.page.toast.saved'));
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
toast.error(t('settings.magicPrompts.page.toast.saveFailed'), { description: message });
|
|
} finally {
|
|
setSavingIds((current) => ({ ...current, [id]: false }));
|
|
}
|
|
}, [getDraft, t]);
|
|
|
|
const resetPrompt = React.useCallback(async (id: MagicPromptId) => {
|
|
setResettingIds((current) => ({ ...current, [id]: true }));
|
|
try {
|
|
const payload = await resetMagicPromptOverride(id);
|
|
setOverrides(payload.overrides);
|
|
setDrafts((current) => ({
|
|
...current,
|
|
[id]: getDefaultMagicPromptTemplate(id),
|
|
}));
|
|
toast.success(t('settings.magicPrompts.page.toast.resetSuccess'));
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
toast.error(t('settings.magicPrompts.page.toast.resetFailed'), { description: message });
|
|
} finally {
|
|
setResettingIds((current) => ({ ...current, [id]: false }));
|
|
}
|
|
}, [t]);
|
|
|
|
const handleResetAll = React.useCallback(async () => {
|
|
setResettingAll(true);
|
|
try {
|
|
const payload = await resetAllMagicPromptOverrides();
|
|
setOverrides(payload.overrides);
|
|
setDrafts({});
|
|
toast.success(t('settings.magicPrompts.page.toast.resetAllSuccess'));
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
toast.error(t('settings.magicPrompts.page.toast.resetAllFailed'), { description: message });
|
|
} finally {
|
|
setResettingAll(false);
|
|
}
|
|
}, [t]);
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="py-6 px-6 flex items-center gap-2 text-muted-foreground">
|
|
<span className="inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse" aria-label={t('settings.magicPrompts.page.loading.aria')} />
|
|
<span className="typography-ui">{t('settings.magicPrompts.page.loading.text')}</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<SettingsPageLayout
|
|
title={tUnsafe(pageConfig.titleKey)}
|
|
titleAccessory={(
|
|
<SettingsInfoHint contentClassName="max-w-xs">{tUnsafe(pageConfig.descriptionKey)}</SettingsInfoHint>
|
|
)}
|
|
headerEnd={(
|
|
<Button
|
|
data-settings-item="magic-prompts.reset-overrides"
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => {
|
|
void handleResetAll();
|
|
}}
|
|
disabled={resettingAll || Object.keys(overrides).length === 0}
|
|
>
|
|
{resettingAll ? t('settings.magicPrompts.page.actions.resetting') : t('settings.magicPrompts.page.actions.resetAllOverrides')}
|
|
</Button>
|
|
)}
|
|
showSaveStatus={false}
|
|
>
|
|
{pageConfig.blocks.map((block, index) => {
|
|
const definition = getMagicPromptDefinition(block.id);
|
|
const baseline = getBaseline(block.id);
|
|
const draft = getDraft(block.id);
|
|
const isOverridden = hasOwn(overrides, block.id);
|
|
const isDirty = draft !== baseline;
|
|
const isInvalidEmptyVisiblePrompt = isVisiblePromptId(block.id) && draft.trim().length === 0;
|
|
const saving = savingIds[block.id] === true;
|
|
const resetting = resettingIds[block.id] === true;
|
|
|
|
return (
|
|
<SettingsSection
|
|
key={block.id}
|
|
title={tUnsafe(block.titleKey)}
|
|
info={definition.description}
|
|
description={
|
|
definition.placeholders && definition.placeholders.length > 0
|
|
? `${t('settings.magicPrompts.page.placeholdersLabel')} ${definition.placeholders.map((item) => `{{${item.key}}}`).join(', ')}`
|
|
: undefined
|
|
}
|
|
divider={index > 0}
|
|
settingsItem={isVisiblePromptId(block.id) ? 'magic-prompts.visible-prompt' : 'magic-prompts.instructions'}
|
|
contentClassName="space-y-3"
|
|
>
|
|
<Textarea
|
|
value={draft}
|
|
onChange={(event) => setDraft(block.id, event.target.value)}
|
|
className="min-h-[220px] font-mono text-sm"
|
|
/>
|
|
{isInvalidEmptyVisiblePrompt && (
|
|
<div className="typography-micro text-[var(--status-error)]">{t('settings.magicPrompts.page.validation.visiblePromptRequired')}</div>
|
|
)}
|
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
<span className="typography-micro text-muted-foreground">
|
|
{isDirty
|
|
? t('settings.magicPrompts.page.status.unsavedChanges')
|
|
: isOverridden
|
|
? t('settings.magicPrompts.page.status.usingSavedOverride')
|
|
: t('settings.magicPrompts.page.status.usingBuiltinDefault')}
|
|
</span>
|
|
<div className="flex items-center gap-2">
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => {
|
|
void resetPrompt(block.id);
|
|
}}
|
|
disabled={!isOverridden || saving || resetting}
|
|
>
|
|
{resetting ? t('settings.magicPrompts.page.actions.resetting') : t('settings.magicPrompts.page.actions.resetToDefault')}
|
|
</Button>
|
|
<Button
|
|
size="sm"
|
|
onClick={() => {
|
|
void savePrompt(block.id);
|
|
}}
|
|
disabled={!isDirty || saving || resetting || isInvalidEmptyVisiblePrompt}
|
|
>
|
|
{saving ? t('settings.common.actions.saving') : t('settings.magicPrompts.page.actions.save')}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</SettingsSection>
|
|
);
|
|
})}
|
|
</SettingsPageLayout>
|
|
);
|
|
};
|