added single day history button

This commit is contained in:
George Powell
2026-02-26 15:04:34 -05:00
parent e550965086
commit a188be167b
2 changed files with 13 additions and 5 deletions

View File

@@ -6,14 +6,14 @@
let seeding = $state(false); let seeding = $state(false);
async function seedHistory() { async function seedHistory(days: number = 10) {
if (!browser || !anonymousId || seeding) return; if (!browser || !anonymousId || seeding) return;
seeding = true; seeding = true;
try { try {
const response = await fetch("/api/dev/seed-history", { const response = await fetch("/api/dev/seed-history", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ anonymousId }) body: JSON.stringify({ anonymousId, days })
}); });
const result = await response.json(); const result = await response.json();
alert( alert(
@@ -113,7 +113,15 @@
<Button <Button
variant="secondary" variant="secondary"
onclick={seedHistory} onclick={() => seedHistory(1)}
disabled={seeding}
class="w-full py-4 md:py-2"
>
{seeding ? "Seeding..." : "Add 1 Day of History"}
</Button>
<Button
variant="secondary"
onclick={() => seedHistory(10)}
disabled={seeding} disabled={seeding}
class="w-full py-4 md:py-2" class="w-full py-4 md:py-2"
> >

View File

@@ -19,7 +19,7 @@ export const POST: RequestHandler = async ({ request }) => {
} }
try { try {
const { anonymousId } = await request.json(); const { anonymousId, days = 10 } = await request.json();
if (!anonymousId || typeof anonymousId !== 'string') { if (!anonymousId || typeof anonymousId !== 'string') {
return json({ error: 'anonymousId required' }, { status: 400 }); return json({ error: 'anonymousId required' }, { status: 400 });
@@ -29,7 +29,7 @@ export const POST: RequestHandler = async ({ request }) => {
const inserted: string[] = []; const inserted: string[] = [];
const skipped: string[] = []; const skipped: string[] = [];
for (let i = 1; i <= 10; i++) { for (let i = 1; i <= days; i++) {
const d = new Date(today); const d = new Date(today);
d.setDate(d.getDate() - i); d.setDate(d.getDate() - i);
const date = d.toLocaleDateString('en-CA'); // YYYY-MM-DD const date = d.toLocaleDateString('en-CA'); // YYYY-MM-DD