From 1c0b107188602835cf33c06957df59083d09f00e Mon Sep 17 00:00:00 2001 From: Dominic Zimmer Date: Mon, 12 May 2025 00:02:02 +0200 Subject: [PATCH] Migrate to new date format --- .env.production | 1 + data/file.json | 26 +++++++++++++ server/file.json => data/old.json | 0 src/App.css | 3 ++ src/App.tsx | 32 ++++++++-------- src/api.ts | 62 ++++++++----------------------- src/types.ts | 31 +++++++++++----- 7 files changed, 83 insertions(+), 72 deletions(-) create mode 100644 .env.production create mode 100644 data/file.json rename server/file.json => data/old.json (100%) diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..eeb4579 --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +REACT_APP_API_URL=https://shulneffapi.leafbla.de diff --git a/data/file.json b/data/file.json new file mode 100644 index 0000000..100c3b1 --- /dev/null +++ b/data/file.json @@ -0,0 +1,26 @@ +{ + "entries": { + "20250511": { + "items": [ + { + "variant": "allergy", + "date": "2025-05-11 23:57:10" + }, + { + "variant": "eats", + "item": "Nix gesse", + "date": "2025-05-11 23:57:13" + }, + { + "variant": "eats", + "item": "Manchmal was gesse", + "date": "2025-05-11 23:57:18" + }, + { + "variant": "allergy", + "date": "2025-05-11 23:57:26" + } + ] + } + } +} \ No newline at end of file diff --git a/server/file.json b/data/old.json similarity index 100% rename from server/file.json rename to data/old.json diff --git a/src/App.css b/src/App.css index 151f128..b1e421e 100644 --- a/src/App.css +++ b/src/App.css @@ -33,6 +33,9 @@ h1,h2,h3 { flex-direction: column; gap: 10px; } +.entry-table td { + min-width: 40px; +} .entry-table .reacts { background-color: #DDEB9D; } diff --git a/src/App.tsx b/src/App.tsx index 288cf57..cc177b3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,12 +1,11 @@ import React, { JSX, useEffect, useState } from 'react'; import './App.css'; -import { addEntry, APIEndPoint, ensureToday, getAPI, getToday, removeEntry } from './api'; -import { ItemType, Store, StoreEntry } from './types'; +import { addEntry, APIEndPoint, getAPI, removeEntry } from './api'; +import { ItemType, Store, WithoutDate } from './types'; import dayjs from 'dayjs'; const defaultStore: Store = { - index: [], - version: 0, + version: 1, entries: {}, }; @@ -18,7 +17,7 @@ export const App : React.FC = () => { useEffect(() => { const f = async () => { const st = await API.read(); - setStore(ensureToday(st)); + setStore(st); }; f(); }, [API]); @@ -27,15 +26,16 @@ export const App : React.FC = () => { const formSubmit = async () => { - const newst = addEntry(store, {variant: "eats", date: new Date().toString(), item: input} ); - console.log("newstore is", newst); - API.write(JSON.stringify(store)).then(async () => { - setTimeout(async () => { - const fromserver = await API.read(); - setStore({...fromserver} ); - setInput(""); - }, 150); - }) + const entry : WithoutDate = {variant: "eats", item: input}; + const newStore = addEntry(store, entry); + console.log("newstore is", newStore); + API.write(JSON.stringify(store)).then(async () => { + setTimeout(async () => { + const fromserver = await API.read(); + setStore({...fromserver} ); + setInput(""); + }, 150); + }) }; const [input, setInput] = useState(""); @@ -71,7 +71,7 @@ export const App : React.FC = () => {