Skip to content

Commit dc9e5e7

Browse files
authored
fix: display saved command immediately without app restart (anomalyco#11) (anomalyco#262)
After saving a command, directly update the local state instead of relying on loadCommands() which depends on the SDK's cached list. The SDK doesn't see newly written command files until app restart. Also add scroll-to-center and highlight animation (2s pulsing indigo border) to help users locate the newly saved command in the list.
1 parent d2968fb commit dc9e5e7

5 files changed

Lines changed: 112 additions & 3 deletions

File tree

‎packages/app/src/app/app.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,8 @@ export default function App() {
863863
openRunModal,
864864
confirmRunModal,
865865
closeRunModal,
866+
justSavedCommand,
867+
clearJustSavedCommand,
866868
} = commandState;
867869

868870
const commandRegistry = createCommandRegistry();
@@ -2566,6 +2568,8 @@ export default function App() {
25662568
openCommandModal,
25672569
runCommand: openRunModal,
25682570
deleteCommand,
2571+
justSavedCommand: justSavedCommand(),
2572+
clearJustSavedCommand,
25692573
refreshSkills: (options?: { force?: boolean }) => refreshSkills(options).catch(() => undefined),
25702574
refreshPlugins: (scopeOverride?: PluginScope) =>
25712575
refreshPlugins(scopeOverride).catch(() => undefined),

‎packages/app/src/app/command-state.ts‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ export function createCommandState(options: {
5555
const [runModalCommand, setRunModalCommand] = createSignal<WorkspaceCommand | null>(null);
5656
const [runModalDetails, setRunModalDetails] = createSignal("");
5757

58+
// Track the just-saved command for scroll-to and highlight animation
59+
const [justSavedCommand, setJustSavedCommand] = createSignal<{ name: string; scope: string } | null>(null);
60+
5861
const workspaceCommands = createMemo(() => commands().filter((c) => c.scope === "workspace"));
5962
const globalCommands = createMemo(() => commands().filter((c) => c.scope === "global"));
6063
const otherCommands = createMemo(() => commands().filter((c) => c.scope === "unknown"));
@@ -127,7 +130,37 @@ export function createCommandState(options: {
127130
template: draft.template,
128131
},
129132
});
130-
await loadCommands({ workspaceRoot, quiet: true });
133+
134+
// Directly add/update the command in local state since the SDK's
135+
// command list won't reflect the new file until app restart
136+
const newCommand: WorkspaceCommand = {
137+
name: safeName,
138+
description: draft.description || undefined,
139+
template: draft.template,
140+
scope: draft.scope,
141+
};
142+
143+
setCommands((current) => {
144+
// Check if command already exists (update case)
145+
const existingIndex = current.findIndex(
146+
(c) => c.name === safeName && c.scope === draft.scope
147+
);
148+
149+
let updated: WorkspaceCommand[];
150+
if (existingIndex >= 0) {
151+
// Update existing command
152+
updated = [...current];
153+
updated[existingIndex] = newCommand;
154+
} else {
155+
// Add new command
156+
updated = [...current, newCommand];
157+
}
158+
159+
// Keep sorted alphabetically
160+
return updated.sort((a, b) => a.name.localeCompare(b.name));
161+
});
162+
163+
setJustSavedCommand({ name: safeName, scope: draft.scope });
131164
setCommandModalOpen(false);
132165
} catch (e) {
133166
const message = e instanceof Error ? e.message : safeStringify(e);
@@ -310,6 +343,10 @@ export function createCommandState(options: {
310343
setRunModalCommand(null);
311344
}
312345

346+
function clearJustSavedCommand() {
347+
setJustSavedCommand(null);
348+
}
349+
313350
return {
314351
commands,
315352
setCommands,
@@ -340,5 +377,7 @@ export function createCommandState(options: {
340377
openRunModal,
341378
confirmRunModal,
342379
closeRunModal,
380+
justSavedCommand,
381+
clearJustSavedCommand,
343382
};
344383
}

‎packages/app/src/app/index.css‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ body {
4343
animation: soft-pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
4444
}
4545

46+
/* Highlight animation for just-saved command */
47+
@keyframes command-highlight {
48+
0% {
49+
box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.6);
50+
border-color: rgba(99, 102, 241, 0.8);
51+
}
52+
50% {
53+
box-shadow: 0 0 0 8px rgba(99, 102, 241, 0);
54+
border-color: rgba(99, 102, 241, 0.4);
55+
}
56+
100% {
57+
box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
58+
border-color: rgba(255, 255, 255, 0.08);
59+
}
60+
}
61+
62+
.command-just-saved {
63+
animation: command-highlight 2s ease-out;
64+
border-color: rgba(99, 102, 241, 0.8);
65+
}
66+
4667

4768
:root {
4869
color-scheme: light;

‎packages/app/src/app/pages/commands.tsx‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { For, Show } from "solid-js";
1+
import { createEffect, For, on, Show } from "solid-js";
22

33
import type { WorkspaceCommand } from "../types";
44
import { t, currentLocale } from "../../i18n";
@@ -19,13 +19,51 @@ export type CommandsViewProps = {
1919
resetCommandDraft?: (scope?: "workspace" | "global") => void;
2020
runCommand: (command: WorkspaceCommand) => void;
2121
deleteCommand: (command: WorkspaceCommand) => void;
22+
justSavedCommand?: { name: string; scope: string } | null;
23+
clearJustSavedCommand?: () => void;
2224
};
2325

2426
const commandNeedsDetails = (command: WorkspaceCommand) => /\$(ARGUMENTS|\d+)/i.test(command.template);
2527

2628
export default function CommandsView(props: CommandsViewProps) {
2729
const translate = (key: string) => t(key, currentLocale());
2830

31+
// Map to store refs for command cards: "scope:name" -> HTMLElement
32+
const commandRefs = new Map<string, HTMLElement>();
33+
34+
// Effect to scroll to and highlight the just-saved command
35+
createEffect(
36+
on(
37+
() => props.justSavedCommand,
38+
(saved) => {
39+
if (!saved) return;
40+
41+
// Use requestAnimationFrame to ensure DOM is updated
42+
requestAnimationFrame(() => {
43+
const key = `${saved.scope}:${saved.name}`;
44+
const element = commandRefs.get(key);
45+
46+
if (element) {
47+
// Smooth scroll to center the element
48+
element.scrollIntoView({ behavior: "smooth", block: "center" });
49+
50+
// Add highlight animation class
51+
element.classList.add("command-just-saved");
52+
53+
// Remove the class and clear state after animation completes
54+
setTimeout(() => {
55+
element.classList.remove("command-just-saved");
56+
props.clearJustSavedCommand?.();
57+
}, 2000);
58+
} else {
59+
// Element not found, just clear the state
60+
props.clearJustSavedCommand?.();
61+
}
62+
});
63+
},
64+
),
65+
);
66+
2967
const openNewCommand = () => {
3068
const reset = props.resetCommandDraft;
3169
if (reset) {
@@ -43,7 +81,10 @@ export default function CommandsView(props: CommandsViewProps) {
4381
props.workspaceCommands.length || props.globalCommands.length || props.otherCommands.length;
4482

4583
const renderCommand = (command: WorkspaceCommand, tone: string) => (
46-
<div class="bg-gray-2/30 border border-gray-6/50 rounded-2xl p-5 flex items-start justify-between gap-4">
84+
<div
85+
ref={(el) => commandRefs.set(`${command.scope}:${command.name}`, el)}
86+
class="bg-gray-2/30 border border-gray-6/50 rounded-2xl p-5 flex items-start justify-between gap-4 transition-all duration-300"
87+
>
4788
<div class="min-w-0">
4889
<div class="flex items-center gap-2">
4990
<Terminal size={16} class={tone} />

‎packages/app/src/app/pages/dashboard.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ export type DashboardViewProps = {
8686
resetCommandDraft?: (scope?: "workspace" | "global") => void;
8787
runCommand: (command: WorkspaceCommand) => void;
8888
deleteCommand: (command: WorkspaceCommand) => void;
89+
justSavedCommand?: { name: string; scope: string } | null;
90+
clearJustSavedCommand?: () => void;
8991
refreshSkills: (options?: { force?: boolean }) => void;
9092
refreshPlugins: (scopeOverride?: PluginScope) => void;
9193
refreshMcpServers: () => void;
@@ -707,6 +709,8 @@ export default function DashboardView(props: DashboardViewProps) {
707709
resetCommandDraft={props.resetCommandDraft}
708710
runCommand={props.runCommand}
709711
deleteCommand={props.deleteCommand}
712+
justSavedCommand={props.justSavedCommand}
713+
clearJustSavedCommand={props.clearJustSavedCommand}
710714
/>
711715
</Match>
712716

0 commit comments

Comments
 (0)