From: PhiTux Date: Wed, 8 Jan 2025 21:25:33 +0000 (+0100) Subject: changed structure to simplify and for read/write X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=b378e35bafa057dcf8ec6a2dfa75d8ea1a090bbe;p=DailyTxT.git changed structure to simplify and for read/write --- diff --git a/backend/server/routers/logs.py b/backend/server/routers/logs.py index a58b4ee..1088bf2 100644 --- a/backend/server/routers/logs.py +++ b/backend/server/routers/logs.py @@ -200,4 +200,23 @@ async def getMarkedDays(month: str, year: str, cookie = Depends(users.isLoggedIn if "files" in dayLog.keys() and len(dayLog["files"]) > 0: days_with_files.append(dayLog["day"]) - return {"days_with_logs": days_with_logs, "days_with_files": days_with_files} \ No newline at end of file + return {"days_with_logs": days_with_logs, "days_with_files": days_with_files} + + +@router.get("/loadMonthForReading") +async def loadMonthForReading(month: int, year: int, cookie = Depends(users.isLoggedIn)): + content:dict = fileHandling.getDay(cookie["user_id"], year, month) + if "days" not in content.keys(): + return [] + + days = [] + enc_key = security.get_enc_key(cookie["user_id"], cookie["derived_key"]) + for dayLog in content["days"]: + if "text" in dayLog.keys(): + days.append({"day": dayLog["day"], + "text": security.decrypt_text(dayLog["text"], enc_key), + "date_written": security.decrypt_text(dayLog["date_written"], enc_key)}) + + days.sort(key=lambda x: x["day"]) + + return days \ No newline at end of file diff --git a/frontend/src/lib/APIurl.js b/frontend/src/lib/APIurl.js new file mode 100644 index 0000000..10ee618 --- /dev/null +++ b/frontend/src/lib/APIurl.js @@ -0,0 +1,5 @@ +import { dev } from '$app/environment'; + +export let API_URL = dev + ? `${window.location.origin.replace(/:5173.*$/gm, '')}:8000` + : window.location.pathname.replace(/\/+$/, ''); \ No newline at end of file diff --git a/frontend/src/routes/Datepicker.svelte b/frontend/src/lib/Datepicker.svelte similarity index 92% rename from frontend/src/routes/Datepicker.svelte rename to frontend/src/lib/Datepicker.svelte index f48645b..6069a97 100644 --- a/frontend/src/routes/Datepicker.svelte +++ b/frontend/src/lib/Datepicker.svelte @@ -4,10 +4,6 @@ import { fly } from 'svelte/transition'; let days = $state([]); - let markedDays = { - '2024-12-25': { type: 'background', color: '#28a745' }, // green instead of red - '2024-12-31': { type: 'dot', color: '#28a745' } // green instead of blue - }; let animationDirection = $state(1); // swipe the dates left or right @@ -15,7 +11,7 @@ let lastYear = $cal.currentYear; $effect(() => { - if ($cal && ($cal.currentMonth !== lastMonth || $cal.currentYear !== lastYear)) { + if ($cal.currentMonth !== lastMonth || $cal.currentYear !== lastYear) { // set animation direction animationDirection = $cal.currentMonth > lastMonth ? 1 : -1; if ($cal.currentYear > lastYear) { @@ -25,6 +21,7 @@ } days = updateCalendar(); + lastMonth = $cal.currentMonth; lastYear = $cal.currentYear; } @@ -49,7 +46,7 @@ const dayKey = `${year}-${(month + 1).toString().padStart(2, '0')}-${i .toString() .padStart(2, '0')}`; - tempDays.push({ date: new Date(Date.UTC(year, month, i)), mark: markedDays[dayKey] }); + tempDays.push(new Date(Date.UTC(year, month, i))); } return tempDays; @@ -148,12 +145,12 @@ in:fly={{ y: 100, duration: 200 }} out:fly={{ y: -100, duration: 200 }} class="day - {$cal.daysWithLogs.includes(day.date.getDate()) ? 'mark-background' : ''} - {day.mark?.type === 'dot' ? 'mark-dot' : ''} - {$selectedDate.toDateString() === day.date.toDateString() ? 'selected' : ''}" - onclick={() => onDateClick(day.date)} + {$cal.daysWithLogs.includes(day.getDate()) ? 'mark-background' : ''} + {$cal.daysWithFiles.includes(day.getDate()) ? 'mark-dot' : ''} + {$selectedDate.toDateString() === day.toDateString() ? 'selected' : ''}" + onclick={() => onDateClick(day)} > - {day.date.getDate()} + {day.getDate()} {:else}
diff --git a/frontend/src/routes/Sidenav.svelte b/frontend/src/lib/Sidenav.svelte similarity index 100% rename from frontend/src/routes/Sidenav.svelte rename to frontend/src/lib/Sidenav.svelte diff --git a/frontend/src/lib/datepickerLogic.svelte b/frontend/src/lib/datepickerLogic.svelte new file mode 100644 index 0000000..70b64be --- /dev/null +++ b/frontend/src/lib/datepickerLogic.svelte @@ -0,0 +1,48 @@ + diff --git a/frontend/src/lib/settingsStore.js b/frontend/src/lib/settingsStore.js index 4386938..1b75a2f 100644 --- a/frontend/src/lib/settingsStore.js +++ b/frontend/src/lib/settingsStore.js @@ -1,3 +1,3 @@ import {writable} from 'svelte/store'; -export const readingMode = writable(true); \ No newline at end of file +export const readingMode = writable(false); \ No newline at end of file diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte index 642d5e0..3671ff9 100644 --- a/frontend/src/routes/+layout.svelte +++ b/frontend/src/routes/+layout.svelte @@ -1,7 +1,7 @@ + @@ -317,42 +307,55 @@ - -
- -
-
-
- {$selectedDate.toLocaleDateString('locale', { weekday: 'long' })}
- {$selectedDate.toLocaleDateString('locale', { - day: '2-digit', - month: '2-digit', - year: 'numeric' - })} + {#if !$readingMode} + +
+ +
+
+
+ {$selectedDate.toLocaleDateString('locale', { weekday: 'long' })}
+ {$selectedDate.toLocaleDateString('locale', { + day: '2-digit', + month: '2-digit', + year: 'numeric' + })} +
+
+
Geschrieben am:
+ {logDateWritten} +
+
history
+
delete
-
-
Geschrieben am:
- {logDateWritten} -
-
history
-
delete
-
- -
-
-
+
+
+
+
+ {$selectedDate}
+ {lastSelectedDate}
- {$selectedDate}
- {lastSelectedDate}
-
- + + {:else} +
+ {#each readingData as log} +
+
{log.day} | {log.date_written}
+
+ {@html log.text} +
+
+ {/each} +
+ {/if}