Skip to content

Commit

Permalink
Initialize prompts earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrttn committed Feb 25, 2024
1 parent c39a70f commit 64cb9f1
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,6 @@ export default function Ask() {
if (!response.body) return;

const contentType = response.headers.get("content-type");
const tempId = crypto.randomUUID();

startTransition(() => {
setSelectedPromptId(tempId);
setPrompts((prev) => [
{
id: tempId,
prompt,
answer: "",
},
...prev,
]);
});

if (contentType?.startsWith("application/json")) {
const json = await response.json();
Expand Down Expand Up @@ -108,7 +95,7 @@ export default function Ask() {
}

startTransition(() => {
updatePrompts(tempId, { id: data.conversationId });
updatePrompts(selectedPromptId!, { id: data.conversationId });
setSelectedPromptId(data.conversationId);
});

Expand Down Expand Up @@ -157,11 +144,28 @@ export default function Ask() {
title="Ask"
icon={Icon.SpeechBubble}
onAction={async () => {
if (prompt === "") return;

showToast({
title: "Asking Markprompt…",
style: Toast.Style.Animated,
});
mutate();

startTransition(() => {
const tempId = crypto.randomUUID();

setSelectedPromptId(tempId);
setPrompts((prev) => [
{
id: tempId,
prompt,
answer: "",
},
...prev,
]);

mutate();
});
}}
/>
</ActionPanel>
Expand Down

0 comments on commit 64cb9f1

Please sign in to comment.