From ca307c1a323545c7afa217ffe68fd33c5fb72c2b Mon Sep 17 00:00:00 2001 From: Kirstien Kroeger Date: Fri, 26 Jul 2024 11:53:38 -0500 Subject: [PATCH 01/10] sorting/pagination fix for reading history --- code/aspen_app/src/helpers/item.js | 24 ++- .../ReadingHistory/ReadingHistory.js | 143 ++++++++++-------- code/aspen_app/src/translations/defaults.json | 4 +- code/web/release_notes/24.08.00.MD | 1 + 4 files changed, 106 insertions(+), 66 deletions(-) diff --git a/code/aspen_app/src/helpers/item.js b/code/aspen_app/src/helpers/item.js index 4730d3c0de..c1a9332a29 100644 --- a/code/aspen_app/src/helpers/item.js +++ b/code/aspen_app/src/helpers/item.js @@ -85,7 +85,7 @@ export const getAuthor = (author) => { export const getFormat = (format, source = null) => { const { language } = React.useContext(LanguageContext); const { library } = React.useContext(LibrarySystemContext); - if (format !== 'Unknown') { + if (format && format !== 'Unknown') { if (source) { if (source !== 'ils') { if (source === 'interlibrary_loan') { @@ -281,6 +281,28 @@ export const getDueDate = (date) => { return null; }; +export const getDateLastUsed = (date, checkedOut) => { + const { language } = React.useContext(LanguageContext); + if (date && date !== 0) { + const dateLastUsed = moment.unix(date); + let itemLastUsedOn = moment(dateLastUsed).format('MMM D, YYYY'); + if (checkedOut) { + itemLastUsedOn = getTermFromDictionary(language, 'in_use'); + } + return ( + + {getTermFromDictionary(language, 'last_used')}: {itemLastUsedOn} + + ); + } + + return null; +}; + export const willAutoRenew = (props) => { const { language } = React.useContext(LanguageContext); if (props.autoRenew === 1 || props.autoRenew === '1') { diff --git a/code/aspen_app/src/screens/MyAccount/ReadingHistory/ReadingHistory.js b/code/aspen_app/src/screens/MyAccount/ReadingHistory/ReadingHistory.js index 5b401aa916..2b6497985e 100644 --- a/code/aspen_app/src/screens/MyAccount/ReadingHistory/ReadingHistory.js +++ b/code/aspen_app/src/screens/MyAccount/ReadingHistory/ReadingHistory.js @@ -13,7 +13,7 @@ import { loadError } from '../../../components/loadError'; import { loadingSpinner } from '../../../components/loadingSpinner'; import { DisplaySystemMessage } from '../../../components/Notifications'; import { LanguageContext, LibrarySystemContext, SystemMessagesContext, ThemeContext, UserContext } from '../../../context/initialContext'; -import { getAuthor, getCleanTitle, getFormat, getTitle } from '../../../helpers/item'; +import { getAuthor, getCleanTitle, getDateLastUsed, getFormat, getTitle } from '../../../helpers/item'; import { navigateStack } from '../../../helpers/RootNavigator'; import { getTermFromDictionary, getTranslationsWithValues } from '../../../translations/TranslationService'; import { deleteAllReadingHistory, deleteSelectedReadingHistory, fetchReadingHistory, optIntoReadingHistory, optOutOfReadingHistory } from '../../../util/api/user'; @@ -32,7 +32,7 @@ export const MyReadingHistory = () => { const { user, updateUser, readingHistory, updateReadingHistory } = React.useContext(UserContext); const { systemMessages, updateSystemMessages } = React.useContext(SystemMessagesContext); const url = library.baseUrl; - const pageSize = 25; + const pageSize = 20; const systemMessagesForScreen = []; const [paginationLabel, setPaginationLabel] = React.useState('Page 1 of 1'); const { textColor } = React.useContext(ThemeContext); @@ -67,6 +67,8 @@ export const MyReadingHistory = () => { onSettle: (data) => setLoading(false), }); + const state = queryClient.getQueryState(['reading_history']); + useFocusEffect( React.useCallback(() => { if (_.isArray(systemMessages)) { @@ -151,6 +153,15 @@ export const MyReadingHistory = () => { setDeleting(false); }; + const updateSort = async (value) => { + console.log('updateSort: ' + value); + setLoading(true); + setSort(value); + await queryClient.invalidateQueries({ queryKey: ['reading_history', user.id, library.baseUrl, page, sort] }); + await queryClient.refetchQueries({ queryKey: ['reading_history', user.id, library.baseUrl, page, value] }); + setLoading(false); + }; + const [expanded, setExpanded] = React.useState(false); const getDisclaimer = () => { return ( @@ -236,7 +247,7 @@ export const MyReadingHistory = () => { bg: 'tertiary.300', endIcon: , }} - onValueChange={(itemValue) => setSort(itemValue)}> + onValueChange={(itemValue) => updateSort(itemValue)}> @@ -339,7 +350,7 @@ export const MyReadingHistory = () => { queryClient.setQueryData(['reading_history', user.id, library.baseUrl, page, sort], result); queryClient.setQueryData(['reading_history', user.id, library.baseUrl, newPage, sort], result); }); - setLoading(falses); + setLoading(false); } }} isDisabled={isPreviousData || !data?.hasMore}> @@ -380,7 +391,7 @@ export const MyReadingHistory = () => { ) : ( <> {getActionButtons()} - {status === 'loading' || isFetching ? ( + {status === 'loading' || isFetching || isLoading ? ( loadingSpinner() ) : status === 'error' ? ( loadError('Error', '') @@ -431,67 +442,71 @@ const Item = (data) => { ///bookcover.php?id=af5d146c-d9d8-130b-9857-03d4126be9fd-eng&size=small&type=grouped_work&category=Books" const key = 'medium_' + item.permanentId; let url = library.baseUrl + '/bookcover.php?id=' + item.permanentId + '&size=medium'; - return ( - - - - {item.title} - - - - {getTitle(item.title)} - {getAuthor(item.author)} - {getFormat(item.format)} - - - - - - - {getTitle(item.title)} - - - {item.existsInCatalog ? ( + if (item.title) { + return ( + + + + {item.title} + + + + {getTitle(item.title)} + {getAuthor(item.author)} + {getFormat(item.format)} + {getDateLastUsed(item.checkout, item.checkedOut)} + + + + + + + {getTitle(item.title)} + + + {item.existsInCatalog ? ( + { + openGroupedWork(item.permanentId, item.title); + toggle(); + }} + startIcon={}> + {getTermFromDictionary(language, 'view_item_details')} + + ) : null} { - openGroupedWork(item.permanentId, item.title); + isLoading={deleting} + isLoadingText={getTermFromDictionary(language, 'removing', true)} + onPress={async () => { + setDelete(true); + await deleteFromHistory(item.permanentId).then((r) => { + setDelete(false); + }); toggle(); }} - startIcon={}> - {getTermFromDictionary(language, 'view_item_details')} + startIcon={}> + {getTermFromDictionary(language, 'reading_history_delete')} - ) : null} - { - setDelete(true); - await deleteFromHistory(item.permanentId).then((r) => { - setDelete(false); - }); - toggle(); - }} - startIcon={}> - {getTermFromDictionary(language, 'reading_history_delete')} - - - - - ); + + + + ); + } + return null; }; \ No newline at end of file diff --git a/code/aspen_app/src/translations/defaults.json b/code/aspen_app/src/translations/defaults.json index ed9f095544..4e61e21978 100644 --- a/code/aspen_app/src/translations/defaults.json +++ b/code/aspen_app/src/translations/defaults.json @@ -559,5 +559,7 @@ "appears_on_list": "Appears on list", "android_end_of_life": "Your version of Android is no longer supported. Please upgrade to continue receiving updates to this app.", "access_instructions": "Access Instructions", - "using_palace_project": "Using Palace Project" + "using_palace_project": "Using Palace Project", + "last_used": "Last Used", + "in_use": "In Use" } \ No newline at end of file diff --git a/code/web/release_notes/24.08.00.MD b/code/web/release_notes/24.08.00.MD index e2901017ab..f2ae13af38 100644 --- a/code/web/release_notes/24.08.00.MD +++ b/code/web/release_notes/24.08.00.MD @@ -1,4 +1,5 @@ ## Aspen LiDA Updates +- Fixed sorting and pagination for Reading History screen. (Tickets 130936, 131043) (*KK*) - Fixed a bug where some devices were scanning incorrect barcode values. (Ticket 135365) (*KK*) ## Aspen Discovery Updates From 75f01fe583992c8276aae564f70b0b126cee91f3 Mon Sep 17 00:00:00 2001 From: Kirstien Kroeger Date: Fri, 26 Jul 2024 12:01:18 -0500 Subject: [PATCH 02/10] fix for checkout filtering --- .../src/screens/MyAccount/CheckedOutTitles/MyCheckouts.js | 2 +- code/web/release_notes/24.08.00.MD | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/code/aspen_app/src/screens/MyAccount/CheckedOutTitles/MyCheckouts.js b/code/aspen_app/src/screens/MyAccount/CheckedOutTitles/MyCheckouts.js index 55776d41db..b15cd7f956 100644 --- a/code/aspen_app/src/screens/MyAccount/CheckedOutTitles/MyCheckouts.js +++ b/code/aspen_app/src/screens/MyAccount/CheckedOutTitles/MyCheckouts.js @@ -83,7 +83,7 @@ export const MyCheckouts = () => { navigation.setOptions({ title: checkoutsBy.all }); } await queryClient.invalidateQueries({ queryKey: ['checkouts', user.id, library.baseUrl, source] }); - await queryClient.invalidateQueries({ queryKey: ['checkouts', user.id, library.baseUrl, value] }); + await queryClient.refetchQueries({ queryKey: ['checkouts', user.id, library.baseUrl, value] }); } setLoading(false); }; diff --git a/code/web/release_notes/24.08.00.MD b/code/web/release_notes/24.08.00.MD index f2ae13af38..bc2e06379e 100644 --- a/code/web/release_notes/24.08.00.MD +++ b/code/web/release_notes/24.08.00.MD @@ -1,6 +1,7 @@ ## Aspen LiDA Updates - Fixed sorting and pagination for Reading History screen. (Tickets 130936, 131043) (*KK*) - Fixed a bug where some devices were scanning incorrect barcode values. (Ticket 135365) (*KK*) +- Fixed filtering by source for Checked Out Titles screen. (*KK*) ## Aspen Discovery Updates // mark From adad087b3b7ccff4db338808635a47f8a43f9ee7 Mon Sep 17 00:00:00 2001 From: Kirstien Kroeger Date: Fri, 26 Jul 2024 12:05:05 -0500 Subject: [PATCH 03/10] Update ReadingHistory.js --- .../MyAccount/ReadingHistory/ReadingHistory.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/code/aspen_app/src/screens/MyAccount/ReadingHistory/ReadingHistory.js b/code/aspen_app/src/screens/MyAccount/ReadingHistory/ReadingHistory.js index 2b6497985e..46ada8b455 100644 --- a/code/aspen_app/src/screens/MyAccount/ReadingHistory/ReadingHistory.js +++ b/code/aspen_app/src/screens/MyAccount/ReadingHistory/ReadingHistory.js @@ -162,6 +162,15 @@ export const MyReadingHistory = () => { setLoading(false); }; + const updatePage = async (value) => { + console.log('updatePage: ' + value); + setLoading(true); + setPage(value); + await queryClient.invalidateQueries({ queryKey: ['reading_history', user.id, library.baseUrl, page, sort] }); + await queryClient.refetchQueries({ queryKey: ['reading_history', user.id, library.baseUrl, value, sort] }); + setLoading(false); + }; + const [expanded, setExpanded] = React.useState(false); const getDisclaimer = () => { return ( @@ -328,7 +337,7 @@ export const MyReadingHistory = () => { alignItems="center"> -