Skip to content

Commit

Permalink
Merge pull request #1539 from danskernesdigitalebibliotek/DDFNEXT-205…
Browse files Browse the repository at this point in the history
…-upgrade-orval

Upgrade Orval
  • Loading branch information
JacobArrow authored Nov 19, 2024
2 parents de391fc + f03f073 commit b6cd08f
Show file tree
Hide file tree
Showing 182 changed files with 700 additions and 567 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"markdownlint-cli2": "^0.4.0",
"mutationobserver-shim": "^0.3.7",
"nyc": "^17.1.0",
"orval": "^6.26.0",
"orval": "^7.2.0",
"postcss": "^8.4.49",
"postcss-cli": "^11.0.0",
"postcss-loader": "^8.1.1",
Expand Down
32 changes: 22 additions & 10 deletions src/components/button-favourite/button-favourite.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useCallback, useEffect, useState } from "react";
import { useQueryClient } from "react-query";
import LoadIcon from "@danskernesdigitalebibliotek/dpl-design-system/build/icons/collection/Reload.svg";
import { useQueryClient } from "react-query";
import { IconFavourite } from "../icon-favourite/icon-favourite";
import {
removeItem,
useHasItem
getGetListQueryKey,
useHasItem,
useRemoveItem
} from "../../core/material-list-api/material-list";
import { useText } from "../../core/utils/text";
import { Pid, WorkId } from "../../core/utils/types/ids";
Expand All @@ -25,20 +26,23 @@ const ButtonFavourite: React.FC<ButtonFavouriteProps> = ({
darkBackground,
title
}) => {
const queryClient = useQueryClient();
const [fillState, setFillState] = useState<boolean>(false);
const [isLoadingHeart, setIsLoadingHeart] = useState<boolean>(true);
const t = useText();
const { mutate } = useHasItem();
const { mutate: hasItem } = useHasItem();
const { mutate: removeItem } = useRemoveItem();
const { track } = useStatistics();
const queryClient = useQueryClient();

const listId = "default";

useEffect(() => {
// The heart icon needs to change into a loading icon while the material
// is being removed from the favorite list
setIsLoadingHeart(true);
mutate(
hasItem(
{
listId: "default",
listId,
itemId: id
},
{
Expand All @@ -55,13 +59,21 @@ const ButtonFavourite: React.FC<ButtonFavouriteProps> = ({
}
}
);
}, [id, mutate]);
}, [id, hasItem]);

const handleClick = useCallback(
(e: React.MouseEvent<HTMLButtonElement>) => {
if (fillState) {
removeItem("default", id, queryClient);
setFillState(false);
removeItem(
{ listId, itemId: id },
{
onSuccess: () => {
// Invalidate the query to remove any faved materials from favorites list
queryClient.invalidateQueries(getGetListQueryKey(listId));
}
}
);
} else {
track("click", {
id: statistics.addToFavorites.id,
Expand All @@ -75,7 +87,7 @@ const ButtonFavourite: React.FC<ButtonFavouriteProps> = ({
// this wont interfere with their click handler.
e.stopPropagation();
},
[addToListRequest, fillState, id, queryClient, track]
[addToListRequest, fillState, id, removeItem, track, queryClient]
);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useCallback, useId } from "react";
import { useDispatch } from "react-redux";
import { useQueryClient } from "react-query";
import { useText } from "../../../core/utils/text";
import { WorkId } from "../../../core/utils/types/ids";
import Arrow from "../../atoms/icons/arrow/arrow";
Expand Down Expand Up @@ -75,7 +74,6 @@ const CardListItem: React.FC<CardListItemProps> = ({
const bookManifestation = getFirstBookManifestation(manifestations);

const dispatch = useDispatch<TypedDispatch>();
const queryClient = useQueryClient();
const author = creatorsToString(flattenCreators(creators), t);
const manifestationPids = getManifestationsPids(manifestations);
const materialFullUrl = constructMaterialUrl(
Expand Down Expand Up @@ -106,7 +104,7 @@ const CardListItem: React.FC<CardListItemProps> = ({
dispatch(
guardedRequest({
type: "addFavorite",
args: { id, queryClient },
args: { id },
app: "search-result"
})
);
Expand Down
4 changes: 1 addition & 3 deletions src/components/material/MaterialHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useId } from "react";
import { useDispatch } from "react-redux";
import { useDeepCompareEffect } from "react-use";
import { useQueryClient } from "react-query";
import { guardedRequest } from "../../core/guardedRequests.slice";
import { TypedDispatch } from "../../core/store";
import {
Expand Down Expand Up @@ -65,12 +64,11 @@ const MaterialHeader: React.FC<MaterialHeaderProps> = ({
const { itemRef, hasBeenVisible: showItem } = useItemHasBeenVisible();
const t = useText();
const dispatch = useDispatch<TypedDispatch>();
const queryClient = useQueryClient();
const addToListRequest = (id: ButtonFavouriteId) => {
dispatch(
guardedRequest({
type: "addFavorite",
args: { id, queryClient },
args: { id },
app: "material"
})
);
Expand Down
4 changes: 1 addition & 3 deletions src/components/simple-material/SimpleMaterial.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from "react";
import { FC } from "react";
import { useDispatch } from "react-redux";
import { useQueryClient } from "react-query";
import ButtonFavourite, {
ButtonFavouriteId
} from "../button-favourite/button-favourite";
Expand Down Expand Up @@ -35,7 +34,6 @@ const SimpleMaterial: FC<SimpleMaterialProps> = ({
const materialUrl = u("materialUrl");

const dispatch = useDispatch<TypedDispatch>();
const queryClient = useQueryClient();
const materialFullUrl = constructMaterialUrl(materialUrl, workId);

// Create authors string
Expand All @@ -52,7 +50,7 @@ const SimpleMaterial: FC<SimpleMaterialProps> = ({
dispatch(
guardedRequest({
type: "addFavorite",
args: { id, queryClient },
args: { id },
app
})
);
Expand Down
9 changes: 5 additions & 4 deletions src/core/cover-service-api/cover-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.26.0 🍺
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* DDF Cover Service
* This service provides covers for library materials indexed by isbn, issn, faust, pid.
Expand Down Expand Up @@ -78,7 +78,8 @@ export type GetCoverCollectionQueryError = ErrorType<void>;
/**
* @summary Search multiple covers
*/
export const useGetCoverCollection = <

export function useGetCoverCollection<
TData = Awaited<ReturnType<typeof getCoverCollection>>,
TError = ErrorType<void>
>(
Expand All @@ -90,7 +91,7 @@ export const useGetCoverCollection = <
TData
>;
}
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
const queryOptions = getGetCoverCollectionQueryOptions(params, options);

const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & {
Expand All @@ -100,4 +101,4 @@ export const useGetCoverCollection = <
query.queryKey = queryOptions.queryKey;

return query;
};
}
2 changes: 1 addition & 1 deletion src/core/cover-service-api/model/cover.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.26.0 🍺
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* DDF Cover Service
* This service provides covers for library materials indexed by isbn, issn, faust, pid.
Expand Down
2 changes: 1 addition & 1 deletion src/core/cover-service-api/model/coverImageUrls.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.26.0 🍺
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* DDF Cover Service
* This service provides covers for library materials indexed by isbn, issn, faust, pid.
Expand Down
2 changes: 1 addition & 1 deletion src/core/cover-service-api/model/coverType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.26.0 🍺
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* DDF Cover Service
* This service provides covers for library materials indexed by isbn, issn, faust, pid.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.26.0 🍺
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* DDF Cover Service
* This service provides covers for library materials indexed by isbn, issn, faust, pid.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.26.0 🍺
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* DDF Cover Service
* This service provides covers for library materials indexed by isbn, issn, faust, pid.
Expand Down
2 changes: 1 addition & 1 deletion src/core/cover-service-api/model/getCoverCollectionType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.26.0 🍺
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* DDF Cover Service
* This service provides covers for library materials indexed by isbn, issn, faust, pid.
Expand Down
2 changes: 1 addition & 1 deletion src/core/cover-service-api/model/imageUrl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.26.0 🍺
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* DDF Cover Service
* This service provides covers for library materials indexed by isbn, issn, faust, pid.
Expand Down
2 changes: 1 addition & 1 deletion src/core/cover-service-api/model/imageUrlSize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.26.0 🍺
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* DDF Cover Service
* This service provides covers for library materials indexed by isbn, issn, faust, pid.
Expand Down
2 changes: 1 addition & 1 deletion src/core/cover-service-api/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.26.0 🍺
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* DDF Cover Service
* This service provides covers for library materials indexed by isbn, issn, faust, pid.
Expand Down
Loading

0 comments on commit b6cd08f

Please sign in to comment.