-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Feature: Local storage to track open access book reading history (#11618) #11640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Aayushdev18
wants to merge
18
commits into
internetarchive:master
Choose a base branch
from
Aayushdev18:11618/feature/local-storage-open-access-history
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature: Local storage to track open access book reading history (#11618) #11640
Aayushdev18
wants to merge
18
commits into
internetarchive:master
from
Aayushdev18:11618/feature/local-storage-open-access-history
+671
−314
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When a specific edition is logged in reading logs, fetch availability at the edition level instead of work level. This ensures correct borrow buttons are shown instead of 'Locate' buttons when the logged edition is available. Fixes internetarchive#11329
for more information, see https://pre-commit.ci
Simplify the add_availability_with_edition_preference function by using the safeget helper to extract editions directly, following the pattern from work_search.html. This makes the code more concise and handles both dict and list edition structures gracefully.
for more information, see https://pre-commit.ci
The previous implementation was calling add_availability on editions,
but the template reads availability from work documents. This fix:
- Extracts editions using safeget
- Gets edition-level availability using get_availability('openlibrary_edition')
- Attaches availability to work documents (not editions)
- Falls back to work-level availability when no edition is available
This should fix the 'Locate' button issue by properly setting
availability on work docs that the template expects.
for more information, see https://pre-commit.ci
The link_editions_to_works function sets editions as a list [edition],
but the code was only checking for dict format {'docs': [edition]}.
This fix handles both cases to properly extract editions and get
edition-level availability.
…rnetarchive#11618) - Add ReadingHistory class to track edition IDs in localStorage - Implement bounded queue (100 items) with deduplication - Create /reading-history API endpoint to fetch book data - Add ReadingHistoryCarousel component for My Books page - Track clicks on Borrow/Read buttons with edition ID extraction - Add XSS protection with htmlquote for all user data - Add analytics tracking with data-ol-link-track - Add i18n support for Reading History label - Add unit tests for ReadingHistory class - Handle edge cases: private browsing, quota exceeded, corrupted data
for more information, see https://pre-commit.ci
- Add eslint-disable comments for console statements - Remove unused event parameters - Fix unnecessary escape character in regex - Remove unnecessary console.warn statements
…ps://github.com/Aayushdev18/openlibrary into 11618/feature/local-storage-open-access-history
- Remove unused error parameter in catch block - Replace javascript:; with #reading-history for anchor link
- Remove unused MAX_LIMIT variable that was causing linting error
- Fix incorrect relative import path (was 6 levels up, should be 4 levels up) - Test file is at tests/unit/js/reading-history/ - Source file is at openlibrary/plugins/openlibrary/js/reading-history/
- Fix sorting issue when items added in same millisecond - Ensure each entry gets unique timestamp for proper sorting - Fixes test failures where getEditionIds should return newest first
- Replace **params dict unpacking with explicit keyword arguments - Fixes mypy error: Argument 2 to get_works has incompatible type
for more information, see https://pre-commit.ci
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #11618
feature
Technical
This PR implements local storage tracking for open access and borrowable book reading history. The implementation includes:
Frontend (JavaScript):
ReadingHistoryclass: Manages a bounded queue (100 items) in localStorage with deduplicationReadingHistoryCarouselcomponent: Dynamically renders reading history on My Books pagehtmlquote()data-ol-link-trackattributeswindow._()for translation with English fallbackBackend (Python):
/reading-history: Accepts comma-separated edition IDs and returns work data from Solradd_availability()functionKey Features:
Files Changed:
openlibrary/plugins/openlibrary/js/reading-history/(3 files)tests/unit/js/reading-history/ReadingHistory.test.jsopenlibrary/plugins/openlibrary/api.py(new endpoint)openlibrary/plugins/openlibrary/js/index.js(initialization)openlibrary/templates/account/mybooks.html(carousel container)openlibrary/macros/ReadButton.html(data attributes)openlibrary/templates/book_providers/read_button.html(data attributes)Testing
Manual Testing:
/people/{username}/books(My Books page)Automated Testing:
npm test -- tests/unit/js/reading-history/ReadingHistory.test.jsEdge Cases Tested: