JacobLinCool Codex commited on
Commit
41ae6a8
·
verified ·
1 Parent(s): 67e347f

feat: show export download feedback

Browse files

Co-authored-by: Codex <noreply@openai.com>

Files changed (1) hide show
  1. static/app.js +42 -16
static/app.js CHANGED
@@ -23,6 +23,8 @@ const exportChapterButton = document.querySelector("#export-chapter");
23
  const resetButton = document.querySelector("#reset-session");
24
 
25
  const SESSION_STORAGE_KEY = "hackathon-advisor-session-v1";
 
 
26
 
27
  let session = {};
28
  let clientPromise = Client.connect(window.location.origin);
@@ -58,13 +60,9 @@ exportButton.addEventListener("click", () => {
58
  exportArtifact(currentArtifact);
59
  });
60
 
61
- exportNotesButton.addEventListener("click", async () => {
62
- await exportNotes();
63
- });
64
 
65
- exportChapterButton.addEventListener("click", async () => {
66
- await exportChapter();
67
- });
68
 
69
  resetButton.addEventListener("click", () => {
70
  clearSavedSession();
@@ -660,21 +658,49 @@ function syncCurrentIdeaTargets() {
660
  }
661
 
662
  async function exportNotes() {
663
- const client = await clientPromise;
664
- const result = await client.predict("/field_notes", {
665
- session_json: JSON.stringify(session),
 
 
 
 
666
  });
667
- const data = Array.isArray(result.data) ? result.data[0] : result.data;
668
- downloadText("hackathon-advisor-field-notes.md", String(data || ""), "text/markdown;charset=utf-8");
669
  }
670
 
671
  async function exportChapter() {
672
- const client = await clientPromise;
673
- const result = await client.predict("/chapter", {
674
- session_json: JSON.stringify(session),
 
 
 
 
675
  });
676
- const data = Array.isArray(result.data) ? result.data[0] : result.data;
677
- downloadText("hackathon-advisor-chapter.md", String(data || ""), "text/markdown;charset=utf-8");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
678
  }
679
 
680
  function exportArtifact(artifact) {
 
23
  const resetButton = document.querySelector("#reset-session");
24
 
25
  const SESSION_STORAGE_KEY = "hackathon-advisor-session-v1";
26
+ const FIELD_NOTES_FILENAME = "hackathon-advisor-field-notes.md";
27
+ const CHAPTER_FILENAME = "hackathon-advisor-chapter.md";
28
 
29
  let session = {};
30
  let clientPromise = Client.connect(window.location.origin);
 
60
  exportArtifact(currentArtifact);
61
  });
62
 
63
+ exportNotesButton.addEventListener("click", () => exportNotes());
 
 
64
 
65
+ exportChapterButton.addEventListener("click", () => exportChapter());
 
 
66
 
67
  resetButton.addEventListener("click", () => {
68
  clearSavedSession();
 
658
  }
659
 
660
  async function exportNotes() {
661
+ await exportMarkdown({
662
+ endpoint: "/field_notes",
663
+ filename: FIELD_NOTES_FILENAME,
664
+ button: exportNotesButton,
665
+ busyLabel: "Notes...",
666
+ pendingLabel: "Writing notes.",
667
+ successLabel: "Notes saved",
668
  });
 
 
669
  }
670
 
671
  async function exportChapter() {
672
+ await exportMarkdown({
673
+ endpoint: "/chapter",
674
+ filename: CHAPTER_FILENAME,
675
+ button: exportChapterButton,
676
+ busyLabel: "Chapter...",
677
+ pendingLabel: "Writing chapter.",
678
+ successLabel: "Chapter saved",
679
  });
680
+ }
681
+
682
+ async function exportMarkdown({ endpoint, filename, button, busyLabel, pendingLabel, successLabel }) {
683
+ if (!button || button.disabled) return;
684
+ const idleLabel = button.textContent;
685
+ button.disabled = true;
686
+ button.textContent = busyLabel;
687
+ corrections.textContent = pendingLabel;
688
+ try {
689
+ const client = await clientPromise;
690
+ const result = await client.predict(endpoint, {
691
+ session_json: JSON.stringify(session),
692
+ });
693
+ const data = Array.isArray(result.data) ? result.data[0] : result.data;
694
+ const text = String(data || "");
695
+ if (!text.trim()) throw new Error("empty export");
696
+ downloadText(filename, text, "text/markdown;charset=utf-8");
697
+ corrections.textContent = `${successLabel}: ${filename}`;
698
+ } catch (error) {
699
+ corrections.textContent = `Export failed: ${error.message}`;
700
+ } finally {
701
+ button.textContent = idleLabel;
702
+ setCommandDisabled(false);
703
+ }
704
  }
705
 
706
  function exportArtifact(artifact) {