mirror of
https://github.com/pupperpowell/bibdle.git
synced 2026-04-05 17:33:31 -04:00
added single day history button
This commit is contained in:
@@ -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"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user