JasonGross commited on
Commit
a79229d
·
1 Parent(s): ecff993

Improve formatting

Browse files
app/static/script.js CHANGED
@@ -106,11 +106,29 @@ document.addEventListener('DOMContentLoaded', () => {
106
  viewCountSpan.style.display = 'none'; // Always hide when mouse leaves
107
  });
108
 
 
109
  li.addEventListener('click', () => {
110
- promptInput.value = essay.prompt;
111
- promptInput.dispatchEvent(new Event('input'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  promptForm.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
113
  });
 
114
 
115
  essaysList.appendChild(li);
116
  console.log(`Appended item ${index + 1} to the list.`);
@@ -154,6 +172,17 @@ document.addEventListener('DOMContentLoaded', () => {
154
 
155
  if (!prompt) return; // Do nothing if prompt is empty
156
 
 
 
 
 
 
 
 
 
 
 
 
157
  // Close any existing EventSource connection
158
  if (eventSource) {
159
  eventSource.close();
@@ -328,7 +357,35 @@ document.addEventListener('DOMContentLoaded', () => {
328
  });
329
  });
330
 
331
- // --- Initial Load ---
332
- fetchEssays(); // Load essays on page load with default sort
333
- promptInput.dispatchEvent(new Event('input')); // Initialize char count
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
334
  });
 
106
  viewCountSpan.style.display = 'none'; // Always hide when mouse leaves
107
  });
108
 
109
+ // --- Modified Click Listener ---
110
  li.addEventListener('click', () => {
111
+ const clickedPrompt = essay.prompt;
112
+ console.log("Essay clicked:", clickedPrompt);
113
+
114
+ // Update URL without reload
115
+ try {
116
+ const url = new URL(window.location);
117
+ url.searchParams.set('prompt', clickedPrompt); // Set/update the prompt parameter
118
+ // Use pushState to change URL without full page load
119
+ history.pushState({ prompt: clickedPrompt }, '', url.toString());
120
+ console.log("URL updated to:", url.toString());
121
+ } catch (e) {
122
+ console.error("Error updating URL:", e);
123
+ // Fallback or simply proceed without URL change if needed
124
+ }
125
+
126
+ // Set the input value and simulate submission (existing logic)
127
+ promptInput.value = clickedPrompt;
128
+ promptInput.dispatchEvent(new Event('input')); // Update char count
129
  promptForm.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
130
  });
131
+ // ----------------------------- //
132
 
133
  essaysList.appendChild(li);
134
  console.log(`Appended item ${index + 1} to the list.`);
 
172
 
173
  if (!prompt) return; // Do nothing if prompt is empty
174
 
175
+ // --- Update URL with the submitted prompt ---
176
+ try {
177
+ const url = new URL(window.location);
178
+ url.searchParams.set('prompt', prompt);
179
+ history.pushState({ prompt: prompt }, '', url.toString());
180
+ console.log("URL updated on submit to:", url.toString());
181
+ } catch (e) {
182
+ console.error("Error updating URL on submit:", e);
183
+ }
184
+ // ------------------------------------------ //
185
+
186
  // Close any existing EventSource connection
187
  if (eventSource) {
188
  eventSource.close();
 
357
  });
358
  });
359
 
360
+ // --- Initial Load Logic ---
361
+ function initializePage() {
362
+ console.log("Initializing page...");
363
+ // Check for URL parameters on initial load
364
+ const urlParams = new URLSearchParams(window.location.search);
365
+ const promptFromUrl = urlParams.get('prompt');
366
+
367
+ if (promptFromUrl) {
368
+ console.log("Found prompt in URL:", promptFromUrl);
369
+ // Prefill the input box
370
+ promptInput.value = decodeURIComponent(promptFromUrl); // Decode just in case
371
+ // Update character count
372
+ promptInput.dispatchEvent(new Event('input'));
373
+ // Automatically trigger form submission
374
+ // Use a small timeout to ensure the DOM is fully ready and rendering isn't blocked
375
+ setTimeout(() => {
376
+ console.log("Submitting prompt from URL...");
377
+ promptForm.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
378
+ }, 100); // 100ms delay, adjust if needed
379
+ } else {
380
+ console.log("No prompt found in URL, loading default essays.");
381
+ // Fetch essays as normal if no prompt in URL
382
+ fetchEssays();
383
+ }
384
+
385
+ // Initialize char count display regardless
386
+ promptInput.dispatchEvent(new Event('input'));
387
+ }
388
+
389
+ // Run initialization logic
390
+ initializePage();
391
  });
app/static/style.css CHANGED
@@ -8,6 +8,7 @@
8
  font-variant: small-caps;
9
  font-weight: bold;
10
  /* Optional: make it bolder */
 
11
  }
12
 
13
  /* Example: Style for the active sort button */
@@ -32,6 +33,9 @@
32
  /* orange-400 */
33
  /* padding-left: 1rem; */
34
  /* margin-top: 0.5rem; */
 
 
 
35
  }
36
 
37
  /* Ensure loading indicator is centered or styled appropriately if used more prominently */
 
8
  font-variant: small-caps;
9
  font-weight: bold;
10
  /* Optional: make it bolder */
11
+ font-size: medium;
12
  }
13
 
14
  /* Example: Style for the active sort button */
 
33
  /* orange-400 */
34
  /* padding-left: 1rem; */
35
  /* margin-top: 0.5rem; */
36
+ font-family: Verdana, Geneva, sans-serif;
37
+ /* Set font for essay body */
38
+ font-size: small;
39
  }
40
 
41
  /* Ensure loading indicator is centered or styled appropriately if used more prominently */
app/templates/index.html CHANGED
@@ -24,7 +24,7 @@
24
  <body class="bg-white text-gray-800 font-sans antialiased">
25
  <div class="container mx-auto px-4 py-8 max-w-3xl">
26
 
27
- <header class="mb-8">
28
  <h1 class="text-3xl font-semibold text-gray-900">Ask Paul Graham</h1>
29
  </header>
30
 
@@ -56,7 +56,7 @@
56
  </section>
57
 
58
  <section id="response-section" class="mb-8 min-h-[100px]">
59
- <h2 class="text-xl font-semibold text-gray-800 mb-2">Essay:</h2>
60
  <div id="loading-indicator" class="hidden text-gray-500">Generating...</div>
61
  <div id="error-message" class="hidden text-red-600 bg-red-100 border border-red-300 p-3 rounded-md"></div>
62
  <div id="response-output" class="prose prose-sm sm:prose lg:prose-lg xl:prose-xl max-w-none text-gray-700 leading-relaxed">
 
24
  <body class="bg-white text-gray-800 font-sans antialiased">
25
  <div class="container mx-auto px-4 py-8 max-w-3xl">
26
 
27
+ <header class="mb-8 hidden">
28
  <h1 class="text-3xl font-semibold text-gray-900">Ask Paul Graham</h1>
29
  </header>
30
 
 
56
  </section>
57
 
58
  <section id="response-section" class="mb-8 min-h-[100px]">
59
+ <h2 class="text-xl font-semibold text-gray-800 mb-2"></h2>
60
  <div id="loading-indicator" class="hidden text-gray-500">Generating...</div>
61
  <div id="error-message" class="hidden text-red-600 bg-red-100 border border-red-300 p-3 rounded-md"></div>
62
  <div id="response-output" class="prose prose-sm sm:prose lg:prose-lg xl:prose-xl max-w-none text-gray-700 leading-relaxed">