From ace73bddc1513876d3a72c8bd163ff815e218503 Mon Sep 17 00:00:00 2001 From: Mia Gamlem Date: Mon, 23 Nov 2026 12:15:01 +0100 Subject: [PATCH 1/5] added div with most compatible plant --- frontend/src/i18n/locales/en/translation.json | 3 +- frontend/src/i18n/locales/no/translation.json | 3 +- .../src/pages/myMatches/MyMatchesPage.css | 64 +++++++++++++++++++ .../src/pages/myMatches/MyMatchesPage.tsx | 63 +++++++++++++++++- 4 files changed, 129 insertions(+), 4 deletions(-) diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json index 7889c351..65178723 100644 --- a/frontend/src/i18n/locales/en/translation.json +++ b/frontend/src/i18n/locales/en/translation.json @@ -99,7 +99,8 @@ "oldest": "Oldest first", "name_asc": "Name (A-Z)", "name_desc": "Name (Z-A)", - "preferences": "Best match first" + "preferences": "Best match first", + "compatible-plant": "Your most compatible plant right now is:" }, "matches": { "addFailed": "Could not add the plant to My Matches. Please try again.", diff --git a/frontend/src/i18n/locales/no/translation.json b/frontend/src/i18n/locales/no/translation.json index 80637805..7175a2d5 100644 --- a/frontend/src/i18n/locales/no/translation.json +++ b/frontend/src/i18n/locales/no/translation.json @@ -99,7 +99,8 @@ "oldest": "Eldste først", "name_asc": "Navn (A-Z)", "name_desc": "Navn (Z-A)", - "preferences": "Best match først" + "preferences": "Best match først", + "compatible-plant": "Din mest kompatible plante akkurat nå er:" }, "matches": { "addFailed": "Kunne ikke legge planten til i Mine Matches. Prøv igjen.", diff --git a/frontend/src/pages/myMatches/MyMatchesPage.css b/frontend/src/pages/myMatches/MyMatchesPage.css index a8c51f36..9699e430 100644 --- a/frontend/src/pages/myMatches/MyMatchesPage.css +++ b/frontend/src/pages/myMatches/MyMatchesPage.css @@ -87,6 +87,55 @@ font-size: 20px; } + +.compatible-plant-field { + display: flex; + align-items: center; + justify-content: space-between; + width: 100%; + max-width: 100%; + min-height: 180px; + padding: 24px 36px; + box-sizing: border-box; + border-radius: 20px; + background: linear-gradient(120deg, var(--light-pink), #f8dce8); + cursor: pointer; + transition: transform 0.2s ease, box-shadow 0.2s ease; + overflow: hidden; +} + +.compatible-plant-field:hover { + transform: translateY(-3px); + box-shadow: 0 6px 18px rgba(0, 0, 0, 0.1); +} + +.compatible-plant-field img { + width: 150px; + height: 180px; + object-fit: cover; + object-position: center; + border-radius: 14px; +} + +.compatible-plant-field p { + margin: 0; + color: var(--text-dark); +} + +.compatible-plant-field p:first-child { + font-size: 0.95rem; + font-weight: 600; + color: var(--pink-text); + text-transform: uppercase; + letter-spacing: 1px; +} + +.compatible-plant-field p:last-child { + margin-top: 8px; + font-size: 1.6rem; + font-weight: 700; +} + .plant-card-match { position: relative; justify-self: center; @@ -116,4 +165,19 @@ padding: 20px 12px; border-radius: 12px; } + + .compatible-plant-field { + padding: 20px; + min-height: 140px; + gap: 12px; + } + + .compatible-plant-field img { + width: 110px; + height: 100px; + } + + .compatible-plant-field p:last-child { + font-size: 1.2rem; + } } diff --git a/frontend/src/pages/myMatches/MyMatchesPage.tsx b/frontend/src/pages/myMatches/MyMatchesPage.tsx index 8d0543f0..86a3a0a5 100644 --- a/frontend/src/pages/myMatches/MyMatchesPage.tsx +++ b/frontend/src/pages/myMatches/MyMatchesPage.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { useQuery } from "@apollo/client/react"; import MatchButton from "../../components/matchButton/MatchButton.tsx"; @@ -66,11 +66,46 @@ function MyMatchesPage() { fetchPolicy: "cache-and-network", }); + const { + data: bestMatchData, + } = useQuery(MY_MATCHES, { + variables: { + userId, + search: null, + watering: null, + sunlight: null, + careLevel: null, + sort: PREFERENCES_SORT, + limit: 1, + offset: 0, + }, + skip: !userId || !hasPreferences, + fetchPolicy: "cache-and-network", + }); + + const bestMatch = bestMatchData?.myMatches.plants[0]; + const scrollToBestMatch = useRef(false); + const showBestMatch = () => {reset(); setSort(PREFERENCES_SORT); setPage(1); scrollToBestMatch.current = true}; + // While new results load, the previous ones stay on screen, like on // Explore Plants, so the page does not flicker when the search, a filter // or the page changes const data = currentData ?? previousData; - const plants = data?.myMatches.plants ?? []; + const plants = useMemo(() => data?.myMatches.plants ?? [], [data]); + useEffect(() => { + if (!scrollToBestMatch.current || !bestMatch) return; + + const element = document.getElementById(`plant-${bestMatch.id}`); + + if (element) { + element.scrollIntoView({ + behavior: "smooth", + block: "center", + }); + + scrollToBestMatch.current = false; + } + }, [plants, bestMatch]); const totalCount = data?.myMatches.totalCount ?? 0; const totalPages = Math.max(1, Math.ceil(totalCount / PAGE_SIZE)); // Only show the loading text when there is nothing to show yet @@ -110,6 +145,7 @@ function MyMatchesPage() { : shownFiltered ? "" : t("myMatchesPage.noMatches"); + return (
@@ -120,6 +156,28 @@ function MyMatchesPage() { one is removed, and that none fit when the search finds nothing. While loading it says so, so "no matches" does not flash before the matches are fetched. */} + + {bestMatch && ( +
+ +
+

{t("myMatchesPage.compatible-plant")}

+

{bestMatch.name}

+
+ + + {bestMatch.imageURL && ( + {bestMatch.name + )} +
+ )} +

0 @@ -171,6 +229,7 @@ function MyMatchesPage() { {plants.map((plant) => (

From 0b02dda6b66b153b4bd90f4dda7281d9c2868176 Mon Sep 17 00:00:00 2001 From: Mia Gamlem Date: Mon, 23 Nov 2026 12:48:59 +0100 Subject: [PATCH 2/5] moved match count to matches section --- .../src/pages/myMatches/MyMatchesPage.css | 11 ++++++- .../src/pages/myMatches/MyMatchesPage.tsx | 29 +++++++++---------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/frontend/src/pages/myMatches/MyMatchesPage.css b/frontend/src/pages/myMatches/MyMatchesPage.css index 9699e430..491aee86 100644 --- a/frontend/src/pages/myMatches/MyMatchesPage.css +++ b/frontend/src/pages/myMatches/MyMatchesPage.css @@ -57,6 +57,15 @@ background-color: var(--light-pink); } +.matches-grid .my-matches-count { + grid-column: 1 / -1; + justify-self: center; + margin: 0 0 10px; + background-color: var(--light-pink); + border-color: var(--dark-pink); + color: var(--pink-text); +} + /* The previous matches are dimmed a little while new ones load, like on Explore Plants */ .matches-grid.is-refreshing .plant-card-match { @@ -98,7 +107,7 @@ padding: 24px 36px; box-sizing: border-box; border-radius: 20px; - background: linear-gradient(120deg, var(--light-pink), #f8dce8); + background: var(--light-green); cursor: pointer; transition: transform 0.2s ease, box-shadow 0.2s ease; overflow: hidden; diff --git a/frontend/src/pages/myMatches/MyMatchesPage.tsx b/frontend/src/pages/myMatches/MyMatchesPage.tsx index 86a3a0a5..0b02fd6b 100644 --- a/frontend/src/pages/myMatches/MyMatchesPage.tsx +++ b/frontend/src/pages/myMatches/MyMatchesPage.tsx @@ -162,7 +162,7 @@ function MyMatchesPage() { onClick={showBestMatch} role="button" tabIndex={0}> - +

{t("myMatchesPage.compatible-plant")}

{bestMatch.name}

@@ -177,18 +177,7 @@ function MyMatchesPage() { )}
)} - -

0 - ? "my-matches-count" - : "my-matches-count my-matches-count--message" - } - aria-live="polite" - aria-busy={loading} - > - {status} -

+ {/* Hidden when user has no preferences set in their profile.*/} {/* Hidden only when the user has no matches at all, so the search and filters stay on screen when they give no results and can be changed */} @@ -217,8 +206,18 @@ function MyMatchesPage() { when the user has no matches at all */} {!loading && (totalCount > 0 || shownFiltered) && (
+ className={`matches-grid${refreshing ? " is-refreshing" : ""}`}> +

0 + ? "my-matches-count" + : "my-matches-count my-matches-count--message" + } + aria-live="polite" + aria-busy={loading} + > + {status} +

{/* "None fit" is shown here, under the filters, like on Explore Plants. The element is always in the box, with aria-live, so screen readers hear it when the search or a filter removes the From 35a2dd8b13c276d0705328b672d68a9f6b147750 Mon Sep 17 00:00:00 2001 From: Mia Gamlem Date: Mon, 23 Nov 2026 15:30:48 +0100 Subject: [PATCH 3/5] added some tests for mymatchespage --- .../src/pages/myMatches/MyMatchesPage.tsx | 10 +++ frontend/src/tests/MyMatchesPage.test.tsx | 86 ++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/myMatches/MyMatchesPage.tsx b/frontend/src/pages/myMatches/MyMatchesPage.tsx index 0b02fd6b..adc5488d 100644 --- a/frontend/src/pages/myMatches/MyMatchesPage.tsx +++ b/frontend/src/pages/myMatches/MyMatchesPage.tsx @@ -157,6 +157,16 @@ function MyMatchesPage() { While loading it says so, so "no matches" does not flash before the matches are fetched. */} + {(loading || (totalCount === 0 && !shownFiltered)) && ( +

+ {status} +

+ )} + {bestMatch && (
useQuery.mock.lastCall?.[1].variables; +const lastMatchesCall = () => + useQuery.mock.calls + .filter(([, options]) => options.variables.limit === 12) + .at(-1); + +const lastVariables = () => lastMatchesCall()?.[1].variables; const nextPage = () => screen.getByRole("button", { name: "pagination.next" }); @@ -134,7 +139,7 @@ describe("myMatchesPage", () => { mockMatches([]); render(); - expect(useQuery.mock.lastCall?.[1]).toMatchObject({ + expect(lastMatchesCall()?.[1]).toMatchObject({ variables: { userId: "user-1", sort: "newest", limit: 12, offset: 0 }, skip: false, fetchPolicy: "cache-and-network", @@ -228,6 +233,24 @@ describe("myMatchesPage", () => { expect(lastVariables()).toMatchObject({ offset: 12 }), ); }); + + it("stays on the current page when it is still valid", async () => { + const user = userEvent.setup(); + + mockMatches([orchid], 30); + + const { rerender } = render(); + + await user.click(nextPage()); + + expect(lastVariables()).toMatchObject({ offset: 12 }); + + // 25 matches still give 3 pages + mockMatches([orchid], 25); + rerender(); + + expect(lastVariables()).toMatchObject({ offset: 12 }); + }); }); // The same search and filters as on Explore Plants, kept in sessionStorage @@ -440,5 +463,64 @@ describe("myMatchesPage", () => { expect(lastVariables()).toMatchObject({ sort: "newest" }); }); + + it("shows the best match when clicked", async () => { + const user = userEvent.setup(); + mockUserWithPreferences(); + mockMatches([orchid]); + + render(); + + await user.click( + screen.getByRole("button", { name: /Orchid/ }), + ); + + expect( + screen.getByRole("button", { name: /preferences/ }), + ).toBeInTheDocument(); + }); + + it("scrolls to the best match when clicked", async () => { + mockUserWithPreferences(); + + const scrollIntoView = vi.fn(); + + Object.defineProperty(HTMLElement.prototype, "scrollIntoView", { + configurable: true, + value: scrollIntoView, + }); + + useQuery.mockImplementation((_query, options) => { + const plants = [orchid]; + + return { + data: { + myMatches: { + totalCount: 1, + plants: + options.variables.limit === 1 ? [orchid] : plants, + filterCounts: makeFilterCounts(), + }, + }, + loading: false, + }; + }); + + render(); + + fireEvent.click( + screen.getByText("myMatchesPage.compatible-plant").closest('[role="button"]')!, + ); + + await waitFor(() => { + expect(scrollIntoView).toHaveBeenCalledWith({ + behavior: "smooth", + block: "center", + }); + }); + + delete (HTMLElement.prototype as Partial).scrollIntoView; + }); + }); }); From 4dc0000ae469a8d6ee1e86984bce29580292a038 Mon Sep 17 00:00:00 2001 From: Mia Gamlem Date: Mon, 23 Nov 2026 15:33:12 +0100 Subject: [PATCH 4/5] formatting on mymatches --- .../src/pages/myMatches/MyMatchesPage.css | 5 +- .../src/pages/myMatches/MyMatchesPage.tsx | 93 ++++++++++--------- frontend/src/tests/MyMatchesPage.test.tsx | 14 ++- 3 files changed, 57 insertions(+), 55 deletions(-) diff --git a/frontend/src/pages/myMatches/MyMatchesPage.css b/frontend/src/pages/myMatches/MyMatchesPage.css index 491aee86..f88d097f 100644 --- a/frontend/src/pages/myMatches/MyMatchesPage.css +++ b/frontend/src/pages/myMatches/MyMatchesPage.css @@ -96,7 +96,6 @@ font-size: 20px; } - .compatible-plant-field { display: flex; align-items: center; @@ -109,7 +108,9 @@ border-radius: 20px; background: var(--light-green); cursor: pointer; - transition: transform 0.2s ease, box-shadow 0.2s ease; + transition: + transform 0.2s ease, + box-shadow 0.2s ease; overflow: hidden; } diff --git a/frontend/src/pages/myMatches/MyMatchesPage.tsx b/frontend/src/pages/myMatches/MyMatchesPage.tsx index adc5488d..263bd140 100644 --- a/frontend/src/pages/myMatches/MyMatchesPage.tsx +++ b/frontend/src/pages/myMatches/MyMatchesPage.tsx @@ -66,9 +66,7 @@ function MyMatchesPage() { fetchPolicy: "cache-and-network", }); - const { - data: bestMatchData, - } = useQuery(MY_MATCHES, { + const { data: bestMatchData } = useQuery(MY_MATCHES, { variables: { userId, search: null, @@ -85,7 +83,12 @@ function MyMatchesPage() { const bestMatch = bestMatchData?.myMatches.plants[0]; const scrollToBestMatch = useRef(false); - const showBestMatch = () => {reset(); setSort(PREFERENCES_SORT); setPage(1); scrollToBestMatch.current = true}; + const showBestMatch = () => { + reset(); + setSort(PREFERENCES_SORT); + setPage(1); + scrollToBestMatch.current = true; + }; // While new results load, the previous ones stay on screen, like on // Explore Plants, so the page does not flicker when the search, a filter @@ -145,7 +148,6 @@ function MyMatchesPage() { : shownFiltered ? "" : t("myMatchesPage.noMatches"); - return (
@@ -157,37 +159,37 @@ function MyMatchesPage() { While loading it says so, so "no matches" does not flash before the matches are fetched. */} - {(loading || (totalCount === 0 && !shownFiltered)) && ( -

- {status} -

- )} + {(loading || (totalCount === 0 && !shownFiltered)) && ( +

+ {status} +

+ )} - {bestMatch && ( -
- -
-

{t("myMatchesPage.compatible-plant")}

-

{bestMatch.name}

-
- + {bestMatch && ( +
+
+

{t("myMatchesPage.compatible-plant")}

+

{bestMatch.name}

+
- {bestMatch.imageURL && ( - {bestMatch.name - )} -
+ {bestMatch.imageURL && ( + {bestMatch.name )} - {/* Hidden when user has no preferences set in their profile.*/} +
+ )} + {/* Hidden when user has no preferences set in their profile.*/} {/* Hidden only when the user has no matches at all, so the search and filters stay on screen when they give no results and can be changed */} @@ -216,18 +218,19 @@ function MyMatchesPage() { when the user has no matches at all */} {!loading && (totalCount > 0 || shownFiltered) && (
-

0 - ? "my-matches-count" - : "my-matches-count my-matches-count--message" - } - aria-live="polite" - aria-busy={loading} - > - {status} -

+ className={`matches-grid${refreshing ? " is-refreshing" : ""}`} + > +

0 + ? "my-matches-count" + : "my-matches-count my-matches-count--message" + } + aria-live="polite" + aria-busy={loading} + > + {status} +

{/* "None fit" is shown here, under the filters, like on Explore Plants. The element is always in the box, with aria-live, so screen readers hear it when the search or a filter removes the diff --git a/frontend/src/tests/MyMatchesPage.test.tsx b/frontend/src/tests/MyMatchesPage.test.tsx index c8fe6572..c9b72689 100644 --- a/frontend/src/tests/MyMatchesPage.test.tsx +++ b/frontend/src/tests/MyMatchesPage.test.tsx @@ -463,7 +463,7 @@ describe("myMatchesPage", () => { expect(lastVariables()).toMatchObject({ sort: "newest" }); }); - + it("shows the best match when clicked", async () => { const user = userEvent.setup(); mockUserWithPreferences(); @@ -471,9 +471,7 @@ describe("myMatchesPage", () => { render(); - await user.click( - screen.getByRole("button", { name: /Orchid/ }), - ); + await user.click(screen.getByRole("button", { name: /Orchid/ })); expect( screen.getByRole("button", { name: /preferences/ }), @@ -497,8 +495,7 @@ describe("myMatchesPage", () => { data: { myMatches: { totalCount: 1, - plants: - options.variables.limit === 1 ? [orchid] : plants, + plants: options.variables.limit === 1 ? [orchid] : plants, filterCounts: makeFilterCounts(), }, }, @@ -509,7 +506,9 @@ describe("myMatchesPage", () => { render(); fireEvent.click( - screen.getByText("myMatchesPage.compatible-plant").closest('[role="button"]')!, + screen + .getByText("myMatchesPage.compatible-plant") + .closest('[role="button"]')!, ); await waitFor(() => { @@ -521,6 +520,5 @@ describe("myMatchesPage", () => { delete (HTMLElement.prototype as Partial).scrollIntoView; }); - }); }); From 35dd576e26a6c298e9e24ee205e271c3d3fb92c2 Mon Sep 17 00:00:00 2001 From: Mia Gamlem Date: Mon, 23 Nov 2026 15:44:14 +0100 Subject: [PATCH 5/5] removed unused import preventing from building --- frontend/src/tests/MyMatchesPage.test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/tests/MyMatchesPage.test.tsx b/frontend/src/tests/MyMatchesPage.test.tsx index 650c2080..72f97327 100644 --- a/frontend/src/tests/MyMatchesPage.test.tsx +++ b/frontend/src/tests/MyMatchesPage.test.tsx @@ -3,7 +3,6 @@ import userEvent from "@testing-library/user-event"; import { beforeEach, describe, it, expect, vi } from "vitest"; import MyMatchesPage from "../pages/myMatches/MyMatchesPage"; import type { Plant } from "../types/Plant"; -import { PAGE_SIZE } from "../graphql/plants/queries"; const { removeUserMatch, useQuery, useUser } = vi.hoisted(() => ({ removeUserMatch: vi.fn(),