Skip to content
Snippets Groups Projects
Commit a46e9a02 authored by Aaron Dötsch's avatar Aaron Dötsch
Browse files

update

parent eeb0641a
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,7 @@ export class MrX { ...@@ -33,7 +33,7 @@ export class MrX {
m.entries = (data.entries as any[] || []) m.entries = (data.entries as any[] || [])
.map(e => MrXEntry.parse(e)) .map(e => MrXEntry.parse(e))
.filter(e=>!!e) .filter(e=>!!e)
.sort((a,b)=>a.time.getTime()-b.time.getTime()); .sort((a,b)=>b.time.getTime()-a.time.getTime());
return m; return m;
} }
static async getById(id: number): Promise<MrX|undefined> { static async getById(id: number): Promise<MrX|undefined> {
......
...@@ -13,10 +13,11 @@ export async function GET(event){ ...@@ -13,10 +13,11 @@ export async function GET(event){
if(!mrX) error(404, 'Mr. X not found'); if(!mrX) error(404, 'Mr. X not found');
const images = await getImages<never>(path.join('mrx', String(id))); const images = await getImages<never>(path.join('mrx', String(id)));
const now = new Date(); const now = new Date();
const firstFutureEntryIndex = mrX.entries.findLastIndex(e => e.time <= now) + 1; const lastFutureEntryIndex = mrX.entries.findLastIndex(e => e.time > now);
// TODO maybe add next entry time? // TODO maybe add next entry time?
const entries = mrX.entries.slice(0, firstFutureEntryIndex).map(e => ({ const entries = mrX.entries.slice(lastFutureEntryIndex + 1).map(e => ({
...e, ...e,
time: e.time.toISOString(),
image: e.image ? images.find(i => i.identifier === e.image) : undefined, image: e.image ? images.find(i => i.identifier === e.image) : undefined,
})); }));
return new Response(JSON.stringify({ mrX: { ...mrX, entries } } satisfies MrXData)); return new Response(JSON.stringify({ mrX: { ...mrX, entries } } satisfies MrXData));
......
...@@ -27,7 +27,7 @@ export const actions = { ...@@ -27,7 +27,7 @@ export const actions = {
const mrX = await MrX.getById(Number(event.params.id)); const mrX = await MrX.getById(Number(event.params.id));
if(!mrX) error(404, 'Mr. X not found'); if(!mrX) error(404, 'Mr. X not found');
const data = await event.request.formData(); const data = await event.request.formData();
const datetime = data.get('datetime'); const datetime = data.get('time');
const text = data.get('text'); const text = data.get('text');
const image = data.get('image'); const image = data.get('image');
if(!datetime || typeof datetime !== 'string') error(400, 'Invalid datetime'); if(!datetime || typeof datetime !== 'string') error(400, 'Invalid datetime');
......
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
<H1>{data.mrX.name}</H1> <H1>{data.mrX.name}</H1>
<div class="w-full flex flex-col items-center gap-3"> <div class="w-full flex flex-col items-center gap-3">
{#each data.mrX.entries as entry (entry.id)}
<Entry {entry} />
{/each}
<Card class="w-full max-w-2xl"> <Card class="w-full max-w-2xl">
<form method="post" action="?/new" enctype="multipart/form-data" use:enhance={({formData})=>{ <form method="post" action="?/new" enctype="multipart/form-data" use:enhance={({formData, formElement})=>{
const datetime = new Date(formData.get("datetime") as string); const datetime = new Date(formData.get("time") as string);
formData.set("datetime", datetime.toISOString()); // Convert to ISO string to add timezone information formData.set("time", datetime.toISOString()); // Convert to ISO string to add timezone information
return ()=>invalidateAll(); return ()=>{
formElement.reset();
invalidateAll();
};
}}> }}>
<Input name="time" type="datetime-local" class="mb-2" required /> <Input name="time" type="datetime-local" class="mb-2" required />
<Textarea name="text" class="mb-2" /> <Textarea name="text" class="mb-2" />
...@@ -32,4 +32,7 @@ ...@@ -32,4 +32,7 @@
<Button type="submit" class="w-full">Erstellen</Button> <Button type="submit" class="w-full">Erstellen</Button>
</form> </form>
</Card> </Card>
{#each data.mrX.entries as entry (entry.id)}
<Entry {entry} />
{/each}
</div> </div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment