Skip to content

Commit

Permalink
Add new notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinMcNeil committed Sep 17, 2024
1 parent d938809 commit 5c52d9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 11 additions & 7 deletions src/extension/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { ExecResult } from '@docker/extension-api-client-types/dist/v0';

const client = createDockerDesktopClient();

const track = (event: string) =>
client.extension.vm?.service?.post('/analytics/track', { event });

class OutputParser {
output: any[] = [];
Expand Down Expand Up @@ -86,7 +84,6 @@ export function App() {
const [showDebug, setShowDebug] = React.useState(false);

useEffect(() => {

try {
pullImagePromise = client.docker.cli.exec("pull", ["vonwig/function_write_files"])
client.docker.cli.exec("pull", ["vonwig/prompts"], {
Expand Down Expand Up @@ -131,7 +128,13 @@ export function App() {
}, [prompts]);

useEffect(() => {
debouncedToastSuccess('OpenAI key saved');
if (openAIKey) {
debouncedToastSuccess('OpenAI key saved');
}
else {
debouncedToastSuccess('OpenAI key deleted');
}

localStorage.setItem('openAIKey', openAIKey || '');
}, [openAIKey]);

Expand Down Expand Up @@ -163,7 +166,7 @@ export function App() {
}, [runOut]);

const startPrompt = async () => {
track('DockerPromptsStartPrompt');
client.desktopUI.toast.success(`Starting Prompt: ${promptInput.includes('local') ? 'LOCAL' : promptInput}`)

await pullImagePromise

Expand Down Expand Up @@ -200,10 +203,11 @@ export function App() {
onError: (err) => {
console.error(err);
runOutput.updateOutput({ method: 'message', params: { debug: err } });
client.desktopUI.toast.error(`Error running prompt: ${promptInput.includes('local') ? 'LOCAL' : promptInput}`)
},
}
});
track('DockerPromptsEndPrompt');
client.desktopUI.toast.success(`Prompt finished ${promptInput.includes('local') ? 'LOCAL' : promptInput}`)
}

const renderPrompt = async () => {
Expand All @@ -218,7 +222,7 @@ export function App() {
<Stack direction="column" spacing={1}>
<OpenAIKey openAIKey={openAIKey || ''} setOpenAIKey={setOpenAIKey} />
<Projects projects={projects} selectedProject={selectedProject} setProjects={setProjects} setSelectedProject={setSelectedProject} />
<Prompts prompts={prompts} selectedPrompt={selectedPrompt} promptInput={promptInput} setPrompts={setPrompts} setSelectedPrompt={setSelectedPrompt} setPromptInput={setPromptInput} track={track} />
<Prompts prompts={prompts} selectedPrompt={selectedPrompt} promptInput={promptInput} setPrompts={setPrompts} setSelectedPrompt={setSelectedPrompt} setPromptInput={setPromptInput} />
<Runner selectedProject={selectedProject} selectedPrompt={selectedPrompt} openAIKey={openAIKey} startPrompt={startPrompt} renderPrompt={renderPrompt} />
<RunOutput runOut={runOut} showDebug={showDebug} setShowDebug={setShowDebug} />
</Stack>
Expand Down
5 changes: 1 addition & 4 deletions src/extension/ui/src/components/Prompts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ type PromptsProps = {
setPrompts: (prompts: string[]) => void;
setSelectedPrompt: (prompt: string) => void;
setPromptInput: (input: string) => void;
track: (event: string) => void;
};

const Prompts: React.FC<PromptsProps> = ({ prompts, selectedPrompt, promptInput, setPrompts, setSelectedPrompt, setPromptInput, track }) => {
const Prompts: React.FC<PromptsProps> = ({ prompts, selectedPrompt, promptInput, setPrompts, setSelectedPrompt, setPromptInput }) => {
const delim = client.host.platform === 'win32' ? '\\' : '/';

return (
Expand All @@ -32,7 +31,6 @@ const Prompts: React.FC<PromptsProps> = ({ prompts, selectedPrompt, promptInput,
<Button onClick={() => {
setPrompts([...prompts, promptInput]);
setPromptInput('');
track('DockerPromptsAddPrompt');
}}>Import prompt</Button>
)}
<Button onClick={() => {
Expand All @@ -44,7 +42,6 @@ const Prompts: React.FC<PromptsProps> = ({ prompts, selectedPrompt, promptInput,
if (result.canceled) {
return;
}
track('DockerPromptsAddLocalPrompt');
setPrompts([...prompts, ...result.filePaths.map(p => `local://${p}`)]);
setSelectedPrompt(`local://${result.filePaths[0]}`);
});
Expand Down

0 comments on commit 5c52d9f

Please sign in to comment.