Skip to content

Commit

Permalink
Merge pull request #1100 from danskernesdigitalebibliotek/add-initial…
Browse files Browse the repository at this point in the history
…-loading-state-to-reservation-button

Show a loading reserve button on material page until all data is loaded
  • Loading branch information
Adamik10 authored Apr 10, 2024
2 parents 49adc82 + e1b68c1 commit 45b0ad9
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import MaterialButtonLoading from "../generic/MaterialButtonLoading";
import MaterialButtonDisabled from "../generic/MaterialButtonDisabled";
import { useText } from "../../../../core/utils/text";
import { usePatronData } from "../../../../core/utils/helpers/usePatronData";
import useGetAvailability from "../../../../core/utils/useGetAvailability";
import { useConfig } from "../../../../core/utils/config";

export interface MaterialButtonsPhysicalProps {
manifestations: Manifestation[];
Expand All @@ -26,14 +28,23 @@ const MaterialButtonsPhysical: React.FC<MaterialButtonsPhysicalProps> = ({
dataCy = "material-buttons-physical"
}) => {
const t = useText();
const config = useConfig();
const faustIds = getAllFaustIds(manifestations);
// We extract loading of Availability here, as it isn't possible within
// UseReservableManifestations. React query uses cached version of the data
// so we can determine if the request inside UseReservableManifestations is
// loading this way.
const { isLoading: isLoadingAvailability } = useGetAvailability({
faustIds,
config
});
const { reservableManifestations } = UseReservableManifestations({
manifestations
});
const { data: userData, isLoading } = usePatronData();
const isUserBlocked = !!(userData?.patron && isBlocked(userData?.patron));

if (isLoading) {
if (isLoading || isLoadingAvailability) {
return <MaterialButtonLoading />;
}

Expand Down

0 comments on commit 45b0ad9

Please sign in to comment.