Skip to content

Commit

Permalink
Merge pull request Aspen-Discovery#1936 from catsoup11789/24.08.00
Browse files Browse the repository at this point in the history
LiDA bug fixes, Koha API header
  • Loading branch information
mdnoble73 authored Jul 29, 2024
2 parents de982bd + 37f7c3f commit f822f98
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 74 deletions.
6 changes: 3 additions & 3 deletions code/aspen_app/app-configs/version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "24.07.00",
"build": "256",
"patch": "0"
"version": "24.08.00",
"build": "265",
"patch": "3"
}
24 changes: 23 additions & 1 deletion code/aspen_app/src/helpers/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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 (
<Text
fontSize={{
base: 'xs',
lg: 'sm',
}}>
<Text bold>{getTermFromDictionary(language, 'last_used')}:</Text> {itemLastUsedOn}
</Text>
);
}

return null;
};

export const willAutoRenew = (props) => {
const { language } = React.useContext(LanguageContext);
if (props.autoRenew === 1 || props.autoRenew === '1') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
158 changes: 91 additions & 67 deletions code/aspen_app/src/screens/MyAccount/ReadingHistory/ReadingHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -67,6 +67,8 @@ export const MyReadingHistory = () => {
onSettle: (data) => setLoading(false),
});

const state = queryClient.getQueryState(['reading_history']);

useFocusEffect(
React.useCallback(() => {
if (_.isArray(systemMessages)) {
Expand Down Expand Up @@ -151,6 +153,24 @@ 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 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 (
Expand Down Expand Up @@ -236,7 +256,7 @@ export const MyReadingHistory = () => {
bg: 'tertiary.300',
endIcon: <CheckIcon size="5" />,
}}
onValueChange={(itemValue) => setSort(itemValue)}>
onValueChange={(itemValue) => updateSort(itemValue)}>
<Select.Item label={sortBy.title} value="title" key={0} />
<Select.Item label={sortBy.author} value="author" key={1} />
<Select.Item label={sortBy.last_used} value="checkedOut" key={2} />
Expand Down Expand Up @@ -317,17 +337,17 @@ export const MyReadingHistory = () => {
alignItems="center">
<ScrollView horizontal>
<Button.Group size="sm">
<Button onPress={() => setPage(page - 1)} isDisabled={page === 1}>
<Button onPress={() => updatePage(page - 1)} isDisabled={page === 1}>
{getTermFromDictionary(language, 'previous')}
</Button>
<Button
onPress={async () => {
if (!isPreviousData && data?.hasMore) {
console.log('Adding to page');
let newPage = page + 1;
setPage(page + 1);
updatePage(newPage);
setLoading(true);
await fetchReadingHistory(page, pageSize, sort, library.baseUrl).then((result) => {
await fetchReadingHistory(newPage, pageSize, sort, library.baseUrl).then((result) => {
updateReadingHistory(data);
if (data.totalPages) {
let tmp = getTermFromDictionary(language, 'page_of_page');
Expand All @@ -339,7 +359,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}>
Expand Down Expand Up @@ -380,7 +400,7 @@ export const MyReadingHistory = () => {
) : (
<>
{getActionButtons()}
{status === 'loading' || isFetching ? (
{status === 'loading' || isFetching || isLoading ? (
loadingSpinner()
) : status === 'error' ? (
loadError('Error', '')
Expand Down Expand Up @@ -431,67 +451,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 (
<Pressable onPress={toggle} borderBottomWidth="1" _dark={{ borderColor: 'gray.600' }} borderColor="coolGray.200" pl="4" pr="5" py="2">
<HStack space={3}>
<VStack maxW="30%">
<Image
alt={item.title}
source={url}
style={{
width: 100,
height: 150,
borderRadius: 4,
}}
placeholder={blurhash}
transition={1000}
contentFit="cover"
/>
<AddToList itemId={item.permanentId} btnStyle="sm" />
</VStack>
<VStack w="65%">
{getTitle(item.title)}
{getAuthor(item.author)}
{getFormat(item.format)}
</VStack>
</HStack>
<Actionsheet isOpen={isOpen} onClose={toggle} size="full">
<Actionsheet.Content>
<Box w="100%" h={60} px={4} justifyContent="center">
<Text
fontSize="18"
color="gray.500"
_dark={{
color: 'gray.300',
}}>
{getTitle(item.title)}
</Text>
</Box>
{item.existsInCatalog ? (
if (item.title) {
return (
<Pressable onPress={toggle} borderBottomWidth="1" _dark={{ borderColor: 'gray.600' }} borderColor="coolGray.200" pl="4" pr="5" py="2">
<HStack space={3}>
<VStack maxW="30%">
<Image
alt={item.title}
source={url}
style={{
width: 100,
height: 150,
borderRadius: 4,
}}
placeholder={blurhash}
transition={1000}
contentFit="cover"
/>
<AddToList itemId={item.permanentId} btnStyle="sm" />
</VStack>
<VStack w="65%">
{getTitle(item.title)}
{getAuthor(item.author)}
{getFormat(item.format)}
{getDateLastUsed(item.checkout, item.checkedOut)}
</VStack>
</HStack>
<Actionsheet isOpen={isOpen} onClose={toggle} size="full">
<Actionsheet.Content>
<Box w="100%" h={60} px={4} justifyContent="center">
<Text
fontSize="18"
color="gray.500"
_dark={{
color: 'gray.300',
}}>
{getTitle(item.title)}
</Text>
</Box>
{item.existsInCatalog ? (
<Actionsheet.Item
onPress={() => {
openGroupedWork(item.permanentId, item.title);
toggle();
}}
startIcon={<Icon as={MaterialIcons} name="search" color="trueGray.400" mr="1" size="6" />}>
{getTermFromDictionary(language, 'view_item_details')}
</Actionsheet.Item>
) : null}
<Actionsheet.Item
onPress={() => {
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={<Icon as={MaterialIcons} name="search" color="trueGray.400" mr="1" size="6" />}>
{getTermFromDictionary(language, 'view_item_details')}
startIcon={<Icon as={MaterialIcons} name="delete" color="trueGray.400" mr="1" size="6" />}>
{getTermFromDictionary(language, 'reading_history_delete')}
</Actionsheet.Item>
) : null}
<Actionsheet.Item
isLoading={deleting}
isLoadingText={getTermFromDictionary(language, 'removing', true)}
onPress={async () => {
setDelete(true);
await deleteFromHistory(item.permanentId).then((r) => {
setDelete(false);
});
toggle();
}}
startIcon={<Icon as={MaterialIcons} name="delete" color="trueGray.400" mr="1" size="6" />}>
{getTermFromDictionary(language, 'reading_history_delete')}
</Actionsheet.Item>
</Actionsheet.Content>
</Actionsheet>
</Pressable>
);
</Actionsheet.Content>
</Actionsheet>
</Pressable>
);
}
return null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ export const NotificationPermissionStatus = () => {
setAppStateVisible(appState.current);
});

const subscriptionAndroid = AppState.addEventListener('focus', async (nextAppState) => {
const { status } = await Notifications.getPermissionsAsync();
setPermissionStatus(status === 'granted');
appState.current = nextAppState;
setAppStateVisible(appState.current);
});

return () => {
subscription.remove();
subscriptionAndroid.remove();
};
}, []);

Expand Down
4 changes: 4 additions & 0 deletions code/aspen_app/src/screens/MyAccount/TitlesOnHold/MyHolds.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ export const MyHolds = () => {
const toggleReadySort = async (value) => {
updateReadySortMethod(value);
const sortedHolds = sortHolds(holds, pendingSortMethod, value);
setLoading(true);
queryClient.setQueryData(['holds', library.baseUrl, language, readySortMethod, pendingSortMethod, holdSource], sortedHolds);
setLoading(false);
updateHolds(sortedHolds);
};

const togglePendingSort = async (value) => {
updatePendingSortMethod(value);
const sortedHolds = sortHolds(holds, value, readySortMethod);
//console.log(sortedHolds[1]);
setLoading(true);
queryClient.setQueryData(['holds', library.baseUrl, language, readySortMethod, pendingSortMethod, holdSource], sortedHolds);
setLoading(false);
updateHolds(sortedHolds);
};

Expand Down
4 changes: 3 additions & 1 deletion code/aspen_app/src/translations/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Loading

0 comments on commit f822f98

Please sign in to comment.