Skip to content

feat: add localStorage bookmarking system with session-based recently viewed projects#1255

Open
divyanshim27 wants to merge 7 commits into
komalharshita:mainfrom
divyanshim27:feat/bookmarking-recently-viewed
Open

feat: add localStorage bookmarking system with session-based recently viewed projects#1255
divyanshim27 wants to merge 7 commits into
komalharshita:mainfrom
divyanshim27:feat/bookmarking-recently-viewed

Conversation

@divyanshim27

Copy link
Copy Markdown

Summary

Implements the two Advanced-level open issues listed in the README: a client-side
bookmarking system and server-side "recently viewed" tracking. No database changes
required — bookmarks live in localStorage, recently viewed uses Flask's built-in
session.

Closes #1230

What Changed

Bookmarking (client-side, static/script.js)

  • Added BookmarkManager object handling get/add/remove/isBookmarked against localStorage
  • Capped at 10 bookmarks (oldest evicted first — simple LRU)
  • Duplicate-save prevention
  • Wrapped JSON.parse in try/catch to recover gracefully from corrupted/hand-edited localStorage instead of crashing the page
  • Added a bookmark toggle button (#bookmark-btn) to templates/project.html, with aria-pressed state kept in sync for screen readers
  • New /bookmarks route + templates/bookmarks.html rendering all saved projects client-side

Recently Viewed (server-side, routes/main_routes.py)

  • /project/<int:project_id> now records the visit in session["recently_viewed"], capped at the last 5, most-recent-first
  • Fixed a de-dup edge case from the original proposal: re-visiting an already-viewed project now correctly moves it back to the front of the list instead of being ignored
  • New GET /api/recently-viewed endpoint returning full project objects for the session's recently viewed IDs
  • New "Recently Viewed" section on the homepage, populated via fetch("/api/recently-viewed") and hidden when empty

Other

  • Added app.secret_key config (required for Flask sessions) — sourced from SECRET_KEY env var with a dev-only fallback; documented in .env.example
  • README updated with a short description of both features

Files Changed

  • static/script.jsBookmarkManager, bookmark button init, homepage recently-viewed fetch
  • templates/project.html — bookmark button markup
  • templates/bookmarks.html — new
  • templates/index.html — recently-viewed section
  • routes/main_routes.py — session tracking + /api/recently-viewed
  • app.pysecret_key config
  • .env.exampleSECRET_KEY documented
  • static/style.css — minor bookmark button styling
  • tests/test_basic.py — 4 new tests
  • README.md — feature docs

Acceptance Criteria

  • BookmarkManager implemented in static/script.js using localStorage
  • Bookmark toggle button on every project detail page
  • Bookmarked state persists across browser sessions (localStorage, not session-scoped)
  • /bookmarks route and template showing all saved projects
  • Recently viewed tracked server-side via Flask session (last 5 projects)
  • Recently viewed section appears on homepage after first project visit
  • Built-in Flask session used — no database required
  • Backend tests added for recently-viewed logic (see note below on bookmark JS tests)

Testing

Automated (python tests/test_basic.py):

  • test_recently_viewed_tracks_last_five
  • test_recently_viewed_revisit_moves_to_front
  • test_bookmarks_page_loads
  • test_project_detail_404_for_invalid_id

All existing tests still pass.

Manual QA — bookmark add/remove/dedup logic is pure client-side localStorage
state with no server round-trip, so it isn't covered by the Flask test client. This
repo doesn't currently have a JS test runner configured (no Jest/Vitest in
package.json or equivalent), so I verified manually:

  • Save a project → refresh page → button still shows "Saved"
  • Save an 11th project → oldest bookmark evicted
  • Save the same project twice → only 1 entry created
  • Visit /bookmarks with 0 saved → empty state message shown
  • Visit /bookmarks with saved projects → cards render correctly
  • Visit 6 different projects → homepage shows last 5, most recently viewed first
  • Re-visit an already-viewed project → moves to front of recently-viewed list

Open to adding a Jest setup in a follow-up if

- Add BookmarkManager (localStorage) with 10-item cap and duplicate prevention
- Add bookmark toggle button on project detail page
- Add /bookmarks route and template
- Track last 5 recently viewed projects via Flask session
- Add /api/recently-viewed endpoint
- Add homepage recently-viewed section
- Add 4 backend tests; bookmark JS logic covered by manual QA (no JS test runner in repo)

Closes komalharshita#1230
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

@divyanshim27 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant