Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions frontend/src/components/matchButton/MatchButton.css
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down Expand Up @@ -35,27 +33,35 @@

/* 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;
border: 2px solid var(--dark-pink);
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);
}
Expand All @@ -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;
}
}
39 changes: 38 additions & 1 deletion frontend/src/hooks/usePlantDeck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,51 @@ 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<GetPlantsData>({
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,
next,
// 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;
}
5 changes: 4 additions & 1 deletion frontend/src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/i18n/locales/no/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/pages/plantMatch/PlantMatchPage.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 23 additions & 10 deletions frontend/src/pages/plantMatch/PlantMatchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -14,6 +15,7 @@ function PlantMatchPage() {
loading,
error,
noMorePlants,
allMatched,
restart,
} = usePlantDeck();
const infoTooltip = useDismissibleTooltip();
Expand Down Expand Up @@ -90,16 +92,27 @@ function PlantMatchPage() {
✿
</span>

<h2>{t("plantMatchPage.noMorePlantsTitle")}</h2>

<p>{t("plantMatchPage.noMorePlants")}</p>
<button
type="button"
className="reload-button"
onClick={restart}
>
{t("plantMatchPage.reload")}
</button>
{allMatched ? (
<>
<h2>{t("plantMatchPage.allMatchedTitle")}</h2>
<p>{t("plantMatchPage.allMatched")}</p>
<a className="reload-button" href={`#${ROUTES.myMatches}`}>
{t("plantMatchPage.goToMyMatches")}
</a>
</>
) : (
<>
<h2>{t("plantMatchPage.noMorePlantsTitle")}</h2>
<p>{t("plantMatchPage.noMorePlants")}</p>
<button
type="button"
className="reload-button"
onClick={restart}
>
{t("plantMatchPage.reload")}
</button>
</>
)}
</div>
</div>
)}
Expand Down
37 changes: 37 additions & 0 deletions frontend/src/tests/PlantMatchPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<PlantMatchPage />);
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(<PlantMatchPage />);
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(<PlantMatchPage />);
Expand Down
Loading