+
Mine anmeldelser
+
+
+ Vil prøve
+
+
+ {loading ? 'Laster viner …' : ''}
+
+
+ {savedCount === 0 ? (
+
+ Du har ikke lagret noen viner ennå. Trykk på hjertet på en vin for å legge den her.{' '}
+ Utforsk viner
+
+ ) : (
+ <>
+ {pluralize(savedCount, 'vin', 'viner')}
+
+ {loading && wines.length === 0 && }
+
+ {error && (
+
+ )}
+
+ {wines.length > 0 && }
+ >
+ )}
+
+
+
+ Mine dommer
+
+ Dommene dine vises her når innlogging er på plass. Fram til da finner du dem på vinsiden.
+
+
+
+ );
+}
diff --git a/frontend/src/features/my/api/useWishlistWines.ts b/frontend/src/features/my/api/useWishlistWines.ts
new file mode 100644
index 0000000..224c0bd
--- /dev/null
+++ b/frontend/src/features/my/api/useWishlistWines.ts
@@ -0,0 +1,44 @@
+import { useMemo } from 'react';
+import { useQuery } from '@apollo/client/react';
+import { useWishlistIds } from '../../../hooks/useWishlist';
+import { toWineSummary } from '../../../lib/mapWine';
+import type { WineSummary } from '../../../lib/types';
+import { wishlistQuery, wishlistVariables, type WishlistData } from './wishlistQuery';
+
+export interface WishlistResult {
+ wines: WineSummary[];
+ /** How many wines are on the list, also before they are loaded. */
+ savedCount: number;
+ loading: boolean;
+ error: Error | undefined;
+ refetch: () => void;
+}
+
+/** The wines on the «Vil prøve» list, fetched in one request. */
+export function useWishlistWines(): WishlistResult {
+ const ids = useWishlistIds();
+ // useWishlistIds gives a new array every render, so the query is rebuilt from the ids as text.
+ const key = ids.join(',');
+
+ // A new query object on every render would make Apollo fetch again in a loop.
+ const query = useMemo(() => wishlistQuery(key ? key.split(',') : []), [key]);
+
+ const { data, loading, error, refetch } = useQuery