diff --git a/frontend/src/components/matchButton/MatchButton.css b/frontend/src/components/matchButton/MatchButton.css index 3a679fb0..bd2e06a7 100644 --- a/frontend/src/components/matchButton/MatchButton.css +++ b/frontend/src/components/matchButton/MatchButton.css @@ -1,9 +1,7 @@ -/* The round flower button in the top right corner of a plant card, used on - Explore Plants and My Matches. The parent of the card must be position: relative. */ .add-match { position: absolute; - top: -15px; - right: -15px; + top: -17px; + right: -17px; z-index: 2; } @@ -35,8 +33,8 @@ /* A filled dark pink button with a white flower (add) or X (remove) */ .add-match-button { - width: 50px; - height: 50px; + width: 56px; + height: 56px; display: flex; align-items: center; justify-content: center; @@ -44,18 +42,26 @@ border-radius: 50%; background-color: var(--dark-pink); color: var(--text-light); - font-size: 18px; + font-size: 21px; line-height: 1; cursor: pointer; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15); } -/* In dark mode the dark pink border is too close to the dark pink results box - behind the button (2.6:1), so the border and focus ring are white */ [data-theme="dark"] .add-match-button { border-color: var(--text-light); } +.add-match-button--matched { + border-color: var(--dark-pink); + background-color: var(--light-pink); + color: var(--dark-pink); +} + +[data-theme="dark"] .add-match-button--matched { + color: var(--dislike-icon); +} + .add-match-button:hover { transform: scale(1.1); } @@ -70,8 +76,14 @@ } @media (max-width: 767px) { + .add-match { + top: -12px; + right: -12px; + } + .add-match-button { - width: 35px; - height: 35px; + width: 42px; + height: 42px; + font-size: 17px; } } diff --git a/frontend/src/hooks/usePlantDeck.ts b/frontend/src/hooks/usePlantDeck.ts index a40ad79c..70e49b77 100644 --- a/frontend/src/hooks/usePlantDeck.ts +++ b/frontend/src/hooks/usePlantDeck.ts @@ -210,6 +210,42 @@ export function usePlantDeck() { const next = useCallback(() => setIndex(shownIndex + 1), [shownIndex]); const plant = resetting ? undefined : plants[shownIndex]; + const noMorePlants = !plant && !hasMore && !loading && !resetting; + + const matchedKey = (user?.matchedPlantIds ?? []).join(","); + const [allMatchedCheck, setAllMatchedCheck] = useState<{ + matchedKey: string; + allMatched: boolean; + }>(); + useEffect(() => { + if (!noMorePlants || matchedKey === "") return; + let cancelled = false; + client + .query({ + query: GET_PLANTS, + variables: { + limit: 1, + excludeIds: matchedKey.split(","), + preferences: [], + }, + fetchPolicy: "no-cache", + }) + .then(({ data }) => { + if (cancelled) return; + setAllMatchedCheck({ + matchedKey, + allMatched: (data?.getPlants ?? []).length === 0, + }); + }) + .catch(() => {}); + return () => { + cancelled = true; + }; + }, [client, matchedKey, noMorePlants]); + const allMatched = + noMorePlants && + allMatchedCheck?.matchedKey === matchedKey && + allMatchedCheck.allMatched; return { plant, @@ -217,7 +253,8 @@ export function usePlantDeck() { // Only true while there is no card to show, background loads stay hidden loading: (loading || userLoading) && !plant, error: plant ? undefined : error, - noMorePlants: !plant && !hasMore && !loading && !resetting, + noMorePlants, + allMatched, restart, } as const; } diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json index 48bbd7b4..aa0c20d5 100644 --- a/frontend/src/i18n/locales/en/translation.json +++ b/frontend/src/i18n/locales/en/translation.json @@ -27,7 +27,10 @@ "error": "Could not load plants. Please try again later.", "noMorePlantsTitle": "Done!", "noMorePlants": "No more plants to show. Reload to see them again!", - "reload": "Reload" + "reload": "Reload", + "allMatchedTitle": "You've matched every plant!", + "allMatched": "There are no more plants to show. Remove some from My Matches to see them here again.", + "goToMyMatches": "Go to My Matches" }, "preferences": { "infoLabel": "What are preferences?", diff --git a/frontend/src/i18n/locales/no/translation.json b/frontend/src/i18n/locales/no/translation.json index 478c3b17..3976953b 100644 --- a/frontend/src/i18n/locales/no/translation.json +++ b/frontend/src/i18n/locales/no/translation.json @@ -27,7 +27,10 @@ "error": "Kunne ikke hente planter. Prøv igjen senere.", "noMorePlantsTitle": "Ferdig!", "noMorePlants": "Ingen flere planter å vise. Last inn på nytt for å se dem igjen!", - "reload": "Last inn på nytt" + "reload": "Last inn på nytt", + "allMatchedTitle": "Du har matchet alle plantene!", + "allMatched": "Det finnes ingen flere planter å vise. Fjern noen fra Mine Matches for å se dem her igjen.", + "goToMyMatches": "Gå til Mine Matches" }, "preferences": { "infoLabel": "Hva er preferanser?", diff --git a/frontend/src/pages/plantMatch/PlantMatchPage.css b/frontend/src/pages/plantMatch/PlantMatchPage.css index 78081990..37250d8e 100644 --- a/frontend/src/pages/plantMatch/PlantMatchPage.css +++ b/frontend/src/pages/plantMatch/PlantMatchPage.css @@ -157,6 +157,11 @@ color 0.2s ease; } +a.reload-button { + display: inline-block; + text-decoration: none; +} + .reload-button:hover { background-color: transparent; color: var(--text-light); diff --git a/frontend/src/pages/plantMatch/PlantMatchPage.tsx b/frontend/src/pages/plantMatch/PlantMatchPage.tsx index cfa47d7f..92176364 100644 --- a/frontend/src/pages/plantMatch/PlantMatchPage.tsx +++ b/frontend/src/pages/plantMatch/PlantMatchPage.tsx @@ -4,6 +4,7 @@ import PlantCard from "../../components/plantCard/PlantCard.tsx"; import { useMatchedPlants } from "../../hooks/useMatchedPlants.ts"; import { usePlantDeck } from "../../hooks/usePlantDeck.ts"; import { useDismissibleTooltip } from "../../hooks/useDismissibleTooltip.ts"; +import { ROUTES } from "../../AppRoutes.tsx"; function PlantMatchPage() { const { t } = useTranslation(); @@ -14,6 +15,7 @@ function PlantMatchPage() { loading, error, noMorePlants, + allMatched, restart, } = usePlantDeck(); const infoTooltip = useDismissibleTooltip(); @@ -90,16 +92,27 @@ function PlantMatchPage() { ✿ -

{t("plantMatchPage.noMorePlantsTitle")}

- -

{t("plantMatchPage.noMorePlants")}

- + {allMatched ? ( + <> +

{t("plantMatchPage.allMatchedTitle")}

+

{t("plantMatchPage.allMatched")}

+ + {t("plantMatchPage.goToMyMatches")} + + + ) : ( + <> +

{t("plantMatchPage.noMorePlantsTitle")}

+

{t("plantMatchPage.noMorePlants")}

+ + + )} )} diff --git a/frontend/src/tests/PlantMatchPage.test.tsx b/frontend/src/tests/PlantMatchPage.test.tsx index 472132ac..662b2bd2 100644 --- a/frontend/src/tests/PlantMatchPage.test.tsx +++ b/frontend/src/tests/PlantMatchPage.test.tsx @@ -336,6 +336,43 @@ describe("PlantMatchPage", () => { ).toBeDisabled(); }); + it("says so when every plant is matched, and links to My Matches", async () => { + mockUser([], ["0", "1"]); + render(); + expect( + await screen.findByRole("heading", { + name: "plantMatchPage.allMatchedTitle", + }), + ).toBeInTheDocument(); + expect( + screen.queryByRole("button", { name: "plantMatchPage.reload" }), + ).not.toBeInTheDocument(); + expect( + screen.getByRole("link", { name: "plantMatchPage.goToMyMatches" }), + ).toHaveAttribute("href", "#/myMatches"); + }); + + it("shows the normal end card when some plants are not matched", async () => { + mockUser([], ["0"]); + render(); + await screen.findAllByText("Orchid"); + skip(); + expect( + await screen.findByRole("heading", { + name: "plantMatchPage.noMorePlantsTitle", + }), + ).toBeInTheDocument(); + await waitFor(() => + expect(query.mock.lastCall?.[0].variables.limit).toBe(1), + ); + expect( + screen.getByRole("heading", { name: "plantMatchPage.noMorePlantsTitle" }), + ).toBeInTheDocument(); + expect( + screen.getByRole("button", { name: "plantMatchPage.reload" }), + ).toBeInTheDocument(); + }); + it("sends the user's preferences so the best matches come first", async () => { mockUser(["averageWater", "fullSun"]); render();