From: PhiTux Date: Fri, 4 Jul 2025 14:20:54 +0000 (+0200) Subject: added bookmark-feature X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=f8a000f5f7810150c364d4ea19f47ccab95134b9;p=DailyTxT.git added bookmark-feature --- diff --git a/backend/server/routers/logs.py b/backend/server/routers/logs.py index 8b7c0bc..2defafa 100644 --- a/backend/server/routers/logs.py +++ b/backend/server/routers/logs.py @@ -257,18 +257,21 @@ async def searchTag(tag_id: int, cookie = Depends(users.isLoggedIn)): async def getMarkedDays(month: str, year: str, cookie = Depends(users.isLoggedIn)): days_with_logs = [] days_with_files = [] + days_bookmarked = [] content:dict = fileHandling.getMonth(cookie["user_id"], year, int(month)) if "days" not in content.keys(): - return {"days_with_logs": [], "days_with_files": []} + return {"days_with_logs": [], "days_with_files": [], "days_bookmarked": []} for dayLog in content["days"]: if "text" in dayLog.keys(): days_with_logs.append(dayLog["day"]) if "files" in dayLog.keys() and len(dayLog["files"]) > 0: days_with_files.append(dayLog["day"]) + if "bookmarked" in dayLog.keys() and dayLog["bookmarked"]: + days_bookmarked.append(dayLog["day"]) - return {"days_with_logs": days_with_logs, "days_with_files": days_with_files} + return {"days_with_logs": days_with_logs, "days_with_files": days_with_files, "days_bookmarked": days_bookmarked} @router.get("/loadMonthForReading") @@ -605,4 +608,31 @@ async def getHistory(day: int, month: int, year: int, cookie = Depends(users.isL }) return history - return [] \ No newline at end of file + return [] + +@router.get("/bookmarkDay") +async def bookmarkDay(day: int, month: int, year: int, cookie = Depends(users.isLoggedIn)): + content:dict = fileHandling.getMonth(cookie["user_id"], year, month) + + if "days" not in content.keys(): + content["days"] = [] + + day_found = False + bookmarked = True + for dayLog in content["days"]: + if dayLog["day"] == day: + day_found = True + if "bookmarked" in dayLog and dayLog["bookmarked"]: + dayLog["bookmarked"] = False + bookmarked = False + else: + dayLog["bookmarked"] = True + break + + if not day_found: + content["days"].append({"day": day, "bookmarked": True}) + + if not fileHandling.writeMonth(cookie["user_id"], year, month, content): + raise HTTPException(status_code=500, detail="Failed to bookmark day - error writing log") + + return {"success": True, "bookmarked": bookmarked} \ No newline at end of file diff --git a/backend/server/utils/fileHandling.py b/backend/server/utils/fileHandling.py index 954e0b8..608d688 100644 --- a/backend/server/utils/fileHandling.py +++ b/backend/server/utils/fileHandling.py @@ -27,7 +27,7 @@ def getMonth(user_id, year, month): try: f = open(os.path.join(settings.data_path, f"{user_id}/{year}/{month:02d}.json"), "r") except FileNotFoundError: - logger.info(f"{user_id}/{year}/{month:02d}.json - File not found") + logger.debug(f"{user_id}/{year}/{month:02d}.json - File not found") return {} except Exception as e: logger.exception(e) diff --git a/frontend/src/lib/Datepicker.svelte b/frontend/src/lib/Datepicker.svelte index 952ce19..2d510d0 100644 --- a/frontend/src/lib/Datepicker.svelte +++ b/frontend/src/lib/Datepicker.svelte @@ -5,6 +5,8 @@ import * as bootstrap from 'bootstrap'; import { offcanvasIsOpen, sameDate } from '$lib/helpers.js'; + let { bookmarkDay } = $props(); + let days = $state([]); let animationDirection = $state(1); // swipe the dates left or right @@ -178,6 +180,7 @@ class="day {$cal.daysWithLogs.includes(day.day) ? 'mark-background' : ''} {$cal.daysWithFiles.includes(day.day) ? 'mark-dot' : ''} + {$cal.daysBookmarked.includes(day.day) ? 'mark-circle' : ''} {(!$readingDate && sameDate($selectedDate, day)) || sameDate($readingDate, day) ? 'selected' : ''}" onclick={() => onDateClick(day)} > @@ -206,12 +209,47 @@ >
- + +