From: PhiTux Date: Mon, 16 Jun 2025 16:44:44 +0000 (+0200) Subject: added 'a look back'-feature; Refactored date-handling X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=fcf5288ed86975fb82deaa700aebfb35c22820bf;p=DailyTxT.git added 'a look back'-feature; Refactored date-handling --- diff --git a/backend/server/routers/logs.py b/backend/server/routers/logs.py index 24904d3..1b522ce 100644 --- a/backend/server/routers/logs.py +++ b/backend/server/routers/logs.py @@ -17,15 +17,17 @@ router = APIRouter() class Log(BaseModel): - date: str + day: int + month: int + year: int text: str date_written: str @router.post("/saveLog") async def saveLog(log: Log, cookie = Depends(users.isLoggedIn)): - year = datetime.datetime.fromisoformat(log.date).year - month = datetime.datetime.fromisoformat(log.date).month - day = datetime.datetime.fromisoformat(log.date).day + year = log.year + month = log.month + day = log.day content:dict = fileHandling.getMonth(cookie["user_id"], year, month) @@ -77,12 +79,8 @@ async def saveLog(log: Log, cookie = Depends(users.isLoggedIn)): @router.get("/getLog") -async def getLog(date: str, cookie = Depends(users.isLoggedIn)): +async def getLog(day: int, month: int, year: int, cookie = Depends(users.isLoggedIn)): - year = datetime.datetime.fromisoformat(date).year - month = datetime.datetime.fromisoformat(date).month - day = datetime.datetime.fromisoformat(date).day - content:dict = fileHandling.getMonth(cookie["user_id"], year, month) dummy = {"text": "", "date_written": "", "files": [], "tags": []} @@ -555,4 +553,34 @@ async def saveTemplates(templates: Templates, cookie = Depends(users.isLoggedIn) if not fileHandling.writeTemplates(cookie["user_id"], content): raise HTTPException(status_code=500, detail="Failed to write templates - error writing templates") else: - return {"success": True} \ No newline at end of file + return {"success": True} + +""" class OnThisDay(BaseModel): + day: int + month: int + year: int + years: list[int] """ + +@router.get("/getOnThisDay") +async def getOnThisDay(day: int, month: int, year: int, last_years: str, cookie = Depends(users.isLoggedIn)): + enc_key = security.get_enc_key(cookie["user_id"], cookie["derived_key"]) + + results = [] + + old_years = [year - int(y) for y in last_years.split(",") if y.isdigit()] + + for old_year in old_years: + content:dict = fileHandling.getMonth(cookie["user_id"], old_year, month) + + try: + for day_content in content['days']: + if day_content['day'] == day: + text = security.decrypt_text(day_content['text'], enc_key) if 'text' in day_content else '' + if text == '': + continue + results.append({'years_old': year - old_year, 'day': day, 'month': month, 'year': old_year, 'text': text}) + break + except: + continue + + return results \ No newline at end of file diff --git a/frontend/src/lib/Datepicker.svelte b/frontend/src/lib/Datepicker.svelte index 90d4a7d..952ce19 100644 --- a/frontend/src/lib/Datepicker.svelte +++ b/frontend/src/lib/Datepicker.svelte @@ -3,7 +3,7 @@ import { onMount } from 'svelte'; import { fly } from 'svelte/transition'; import * as bootstrap from 'bootstrap'; - import { offcanvasIsOpen } from '$lib/helpers.js'; + import { offcanvasIsOpen, sameDate } from '$lib/helpers.js'; let days = $state([]); @@ -32,8 +32,8 @@ const updateCalendar = () => { const month = $cal.currentMonth; const year = $cal.currentYear; - const firstDay = new Date(year, month, 1); - const lastDay = new Date(year, month + 1, 0); + const firstDay = new Date(Date.UTC(year, month, 1)); + const lastDay = new Date(Date.UTC(year, month + 1, 0)); let tempDays = []; // monday is first day @@ -45,10 +45,7 @@ } for (let i = 1; i <= lastDay.getDate(); i++) { - const dayKey = `${year}-${(month + 1).toString().padStart(2, '0')}-${i - .toString() - .padStart(2, '0')}`; - tempDays.push(new Date(Date.UTC(year, month, i))); + tempDays.push({ year: year, month: month + 1, day: i }); } return tempDays; @@ -179,15 +176,12 @@ in:fly={{ y: 100, duration: 200 }} out:fly={{ y: -100, duration: 200 }} class="day - {$cal.daysWithLogs.includes(day.getDate()) ? 'mark-background' : ''} - {$cal.daysWithFiles.includes(day.getDate()) ? 'mark-dot' : ''} - {(!$readingDate && $selectedDate.toDateString() === day.toDateString()) || - $readingDate?.toDateString() === day.toDateString() - ? 'selected' - : ''}" + {$cal.daysWithLogs.includes(day.day) ? 'mark-background' : ''} + {$cal.daysWithFiles.includes(day.day) ? 'mark-dot' : ''} + {(!$readingDate && sameDate($selectedDate, day)) || sameDate($readingDate, day) ? 'selected' : ''}" onclick={() => onDateClick(day)} > - {day.getDate()} + {day.day} {:else}
@@ -203,7 +197,11 @@ diff --git a/frontend/src/lib/OnThisDay.svelte b/frontend/src/lib/OnThisDay.svelte new file mode 100644 index 0000000..73b9e73 --- /dev/null +++ b/frontend/src/lib/OnThisDay.svelte @@ -0,0 +1,253 @@ + + + + + + + + + + +
{ + if (event.target === modal) { + closeModal(); + } + }} +> +
+
+ Vor {log?.years_old} Jahren | {new Date( + log?.year, + log?.month - 1, + log?.day + ).toLocaleDateString('locale', { + day: '2-digit', + month: '2-digit', + year: 'numeric' + })} + +
+ + +
+
+ + diff --git a/frontend/src/lib/Sidenav.svelte b/frontend/src/lib/Sidenav.svelte index 1224385..18de685 100644 --- a/frontend/src/lib/Sidenav.svelte +++ b/frontend/src/lib/Sidenav.svelte @@ -8,7 +8,7 @@ import { onMount } from 'svelte'; import * as bootstrap from 'bootstrap'; import Tag from './Tag.svelte'; - import { offcanvasIsOpen } from '$lib/helpers.js'; + import { offcanvasIsOpen, sameDate } from '$lib/helpers.js'; import { API_URL } from '$lib/APIurl.js'; import axios from 'axios'; @@ -317,11 +317,17 @@