diff --git a/README.md b/README.md index 7a75eee5..fb1836c7 100644 --- a/README.md +++ b/README.md @@ -23,15 +23,17 @@ http://it2810-03.idi.ntnu.no/project2/ ## Core features -- **Plant Match:** The user swipes the card right to match with a plant and left to skip it, or uses the ♥ and ✖ buttons. Plants matching the most preferences come first, otherwise the order is random. This is to make it easier for the user to find plants they are compatible with. When plants are matched on Plant Match or Explore Plants, a badge on My Matches in the sidebar shows how many plants have been matched since the page was last opened, to make it easier to understand where the matches end up. +- **Plant Match:** The start page and the heart of the app. Instead of choosing from a long list, the user decides on one plant at a time by swiping right (♥) to match or left (✖) to skip, which makes finding plants quick and fun. The plants that fit the user's preferences best are shown first, so the user meets the plants they are most compatible with early. A badge on "My Matches" in the sidebar shows how many new matches the user has, so it is clear where the matches end up. -- **My Matches:** Collects the plants the user has liked (♥) on Plant Match and Explore Plants, and lets them search, filter and sort among them, with a count of how many matches they have. +- **My Matches:** One place for all the plants the user likes, whether they were matched on Plant Match or Explore Plants. It works as a personal collection the user can come back to, and search, filter and sort when it grows. -- **Explore Plants:** The page where the user can find specific plants they are searching for without having matched with them. Search, filtering and sorting are possible. The state is kept in the URL, so a view survives a refresh and the user can share the page as a link. +- **Explore Plants:** For users who already know what they are looking for. Instead of matching, they can search, filter and sort the whole catalogue directly. The view is kept in the URL, so it survives a refresh and can be shared as a link. -- **Plant Owner Test:** A short test (four questions) to give the user insight into what kind of plant owner they are. It is meant to help them set one preference each for watering, light and care level, based on the answers and the description of the type. It also gives an avatar that can be used as a profile picture that can only be achieved through the test to communicate the type of plant owner the user is. +- **Plant Owner Test:** For users who do not know their preferences yet. A short test tells them what kind of plant owner they are, and suggests preferences for watering, light and care level based on the answers. The result also gives an avatar that can only be earned through the test, so the user can show their plant owner type as their profile picture. -- **Walkthrough:** A short guide opens on the first visit and explains what the user can do on each page. It can be reopened at any time with the ? button. It is meant to help with any confusion connected to how the application works, and help the user to get started. +- **Walkthrough:** A short guide that opens on the first visit and explains what each page is for, so new users can get started without confusion. It can be reopened at any time with the ? button. + +- **Profile:** Lets the user make the app their own, with a name, description, avatar and plant preferences. The profile is also a starting point if the app is made more community-based later. ## Tech stack @@ -153,7 +155,7 @@ npm run test:e2e | Part | Statements | Branches | Functions | Lines | | -------- | ---------- | -------- | --------- | ------- | -| Frontend | 97.44 % | 93.78 % | 96.83 % | 98.43 % | +| Frontend | 97.45 % | 93.82 % | 96.83 % | 98.43 % | | Backend | 100 % | 100 % | 100 % | 100 % | See [tests.md](docs/tests.md) for the test strategy, more ways to run the tests, how to run the tests with coverage and screenshots of the coverage reports, what the test files cover and what the tests found. diff --git a/docs/ai-usage.md b/docs/ai-usage.md index 4ecc4ea8..e28fe4be 100644 --- a/docs/ai-usage.md +++ b/docs/ai-usage.md @@ -24,7 +24,7 @@ The mock-up was mostly used as a reference for us, not as context for the other ### Working across three tools -The three tools were used for different things. Copilot was used in the editor for small suggestions while we wrote code, and it only saw the files that were open. Claude and ChatGPT were used in a chat or in the terminal for bigger tasks, such as explaining a concept, writing tests or refactoring a file. +The three ai-coding tools were used for different things. Copilot was used in the editor for small suggestions while we wrote code, and it only saw the files that were open. Claude and ChatGPT were used in a chat or in the terminal for bigger tasks, such as explaining a concept, writing tests or refactoring a file. For most of the project we did not have a shared setup for AI. Each of us gave the tools context ourselves, by pasting in the relevant files, the issue we worked on, error messages or parts of the README and the architecture document. We found that the answers got much better when we gave the tool the code it should build on and told it what not to change. Short and specific prompts worked better than asking for a whole feature at once. @@ -74,11 +74,11 @@ AI saved us a lot of time on work that is repetitive or follows a known pattern, ### Learning -The biggest risk for us was that AI could do the work we were supposed to learn from. It is easy to accept code that works without understanding why it works, and then you have not learned anything, and you can not explain or fix the code later. It also became clear in the reviews: if the person who made the pull request could not explain the code, the reviewer could not trust it either. We tried to use AI to explain things rather than only to write them, and the rule was that you should be able to explain all code you made a pull request for. We still think we learned less about some parts, such as the configuration of Vite and Vitest, than we would have done without AI, since we mostly used the setup AI suggested. +The biggest risk for us was that AI could do the work we were supposed to learn from. It is easy to accept code that works without understanding why it works, and then you have not learned anything, and you cannot explain or fix the code later. It also became clear in the reviews: if the person who made the pull request could not explain the code, the reviewer could not trust it either. We tried to use AI to explain things rather than only to write them, and the rule was that you should be able to explain all code you made a pull request for. We still think we learned less about some parts, such as the configuration of Vite and Vitest, than we would have done without AI, since we mostly used the setup AI suggested. ### Copyright and data -AI models are trained on code and pictures made by other people, often without them having agreed to it, and it is not always clear who owns what the model makes. For code this was a small problem for us, since most of the code follows common patterns, and all of it was reviewed and changed by us. The pictures are more uncertain. The avatars and the placeholder picture are made with AI, and we can not know how much they are based on the work of real artists. If the app was to be used for real, we would think about using pictures made by a person or with a clear license instead. The plant data and images come from the Perenual API, and not from AI. +AI models are trained on code and pictures made by other people, often without them having agreed to it, and it is not always clear who owns what the model makes. For code this was a small problem for us, since most of the code follows common patterns, and all of it was reviewed and changed by us. The pictures are more uncertain. The avatars and the placeholder picture are made with AI, and we cannot know how much they are based on the work of real artists. If the app was to be published and used publicly, we would think about using pictures made by a person or with a clear license instead. The plant data and images come from the Perenual API, and not from AI. We also had to think about what we gave the tools. We never pasted secrets, such as the `.env` file or passwords to the VM, into an AI tool, since we do not control what happens with the data afterwards. diff --git a/docs/architecture.md b/docs/architecture.md index 65649e89..371ad420 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -221,7 +221,7 @@ The frontend is built with React and TypeScript (Vite). - **User state:** `UserProvider` (`context/UserContext.tsx`) loads the current user from the backend and makes it available through `useUser()`. The hooks `useProfile`, `usePreferences` and `useMatchedPlants` wrap the user mutations, so pages do not call GraphQL directly for user data. The user queries and mutations themselves live in `graphql/user/` (see [GraphQL operations](#graphql-operations-in-the-frontend)). - **Error messages:** `ErrorMessageProvider` (`context/ErrorMessageContext.tsx`) wraps the app and makes `showError()` available through `useErrorMessage()`. `useMatchedPlants` uses it to show an error message when adding or removing a match fails. -- **Reusable logic in hooks:** Logic without UI is kept in hooks. `useDebounce` delays updates while the user is typing (used for search and for saving the profile text). `useExploreParams` keeps the Explore search, filters, sort order and page in the URL, and sends the user back to page 1 when the search, a filter or the sort order changes. It uses `useUrlParams`, which reads the page number and updates the URL (with React Router's `useSearchParams`). `useMyMatchesParams` does the same for My Matches, but keeps the search, filters and sort order in `sessionStorage` with `useSessionState`, since the matches belong to the user in this browser and a link to them could not be shared. `usePageCursor` remembers the cursor that leads to the next or previous page on both pages, and only uses it for the exact search, filters and sort order it came from (see [Scalability](#design-choices-made-for-scalability)). `usePreferences` saves the preferences, both on the profile page and after the plant owner test. `useNewMatches` counts the plants matched since My Matches was last opened, which the sidebar shows as a badge on the My Matches link (with a text for screen readers). The matches the user already has when the app opens count as seen, so only the user id has to be kept in the browser. A plant that is removed from the matches is no longer seen, so it counts as new if it is matched again. `useDismissibleTooltip` lets the "i" help texts be hidden with Escape. +- **Reusable logic in hooks:** Logic without UI is kept in hooks. `useDebounce` delays updates while the user is typing (used for search and for saving the profile text). `useExploreParams` keeps the Explore search, filters, sort order and page in the URL, and sends the user back to page 1 when the search, a filter or the sort order changes. It uses `useUrlParams`, which reads the page number and updates the URL (with React Router's `useSearchParams`). `useMyMatchesParams` does the same for My Matches, but keeps the search, filters and sort order in `sessionStorage` with `useSessionState`, since the matches belong to the user in this browser and a link to them could not be shared. `usePageCursor` remembers the cursor that leads to the next or previous page on both pages, and only uses it for the exact search, filters and sort order it came from (see [Scalability](#design-choices-made-for-scalability)). `usePreferences` saves the preferences, both on the profile page and after the plant owner test. `useNewMatches` counts the plants matched since My Matches was last opened, which the sidebar shows as a badge on the My Matches link (with a text for screen readers). On mobile, where the sidebar is hidden, the menu button shows the same count, and says it in its accessible name. The matches the user already has when the app opens count as seen, so only the user id has to be kept in the browser. A plant that is removed from the matches is no longer seen, so it counts as new if it is matched again. `useDismissibleTooltip` lets the "i" help texts be hidden with Escape. - `usePlantDeck` fetches the Plant Match cards in batches of 8 (`getPlants`), and fetches the next batch when 3 or fewer cards are left. Each request sends the ids of the plants already fetched into the deck and the plants the user has already matched as `excludeIds`, so no plant is shown twice and plants in My Matches are never shown. A plant that is matched on another page while it is in the deck is skipped. The remaining cards are kept in `sessionStorage` while the user visits another page. It sends the saved preferences with each batch, and changing the preferences clears the current deck and fetches a new first batch so the order reflects the new preferences. Stale responses from the previous deck are ignored. When the deck is empty, the user can start it over with the Reload button, and if every plant is matched, the end card says so and links to My Matches instead. - **Swiping on Plant Match:** `PlantMatchPage` follows the card with Pointer Events, so the same code handles mouse, finger and pen. The match is saved before the card flies off, so it is not lost if the user leaves the page during the animation. The ♥ and ✖ buttons do the same as a swipe. - **Reusable components:** Shared UI is kept in `components/`. `Pagination` shows previous/next and numbered pages, `PlantSearchForm` is the search field, filters, sort menu and reset button used on both Explore Plants and My Matches (the filters are listed once in `plantFilters.ts`), `FilterSelect` is a labelled dropdown for one filter, and `SortMenu` is a sort button with a menu that can be used with the keyboard. `MatchButton` adds a plant to My Matches (♥) or removes it (✖), `HeartIcon` is the SVG heart used on the match buttons and on Plant Match, `ErrorMessage` shows a short error message, and `LanguageSwitcher` is used both in the sidebar and in the walkthrough. The components take already translated texts, so they can be used on other pages. diff --git a/docs/media/coverageFrontend.png b/docs/media/coverageFrontend.png index 184b7fbe..d5b456d1 100644 Binary files a/docs/media/coverageFrontend.png and b/docs/media/coverageFrontend.png differ diff --git a/docs/quality.md b/docs/quality.md index baa20cdf..ce043335 100644 --- a/docs/quality.md +++ b/docs/quality.md @@ -61,7 +61,7 @@ The app includes the following accessibility features: - **Forms and images:** Search, filters and profile inputs have associated labels. Plant images use the plant name as alternative text, and profile and avatar images also include alternative text. -- **Control states:** The sort menu and the mobile menu button expose their expanded state and which element they control. Sort, avatar and preference choices and the profile tabs expose their selected state with `aria-pressed`. The preference chips on the plant cards are a list, and a chip that matches the user's preferences also says so in text that only screen readers read, so the information is not given by color alone. Pagination marks the current page with `aria-current="page"` and announces page changes through an `aria-live="polite"` region. On Explore Plants and My Matches, the number of results or matches is also announced when it changes, including "No results found" when a search gives no plants and "no matches" when the last match is removed. Filter values that would give no plants are disabled options, so screen readers say they are unavailable, and the number of plants is part of the option text. Every page has one `h1` (the page title in the header) and a `main` landmark. The match button on the plant cards shows a heart to add a plant to My Matches and ✖ to remove it, and its accessible name and tooltip say what a click does. The badge with the number of new matches on the My Matches link in the sidebar is hidden from screen readers, which instead read a text such as "2 new matches" as part of the link. If adding or removing a match fails, an error message is shown at the top of the screen in a `role="alert"` region, so screen readers read it at once without moving focus. +- **Control states:** The sort menu and the mobile menu button expose their expanded state and which element they control. Sort, avatar and preference choices and the profile tabs expose their selected state with `aria-pressed`. The preference chips on the plant cards are a list, and a chip that matches the user's preferences also says so in text that only screen readers read, so the information is not given by color alone. Pagination marks the current page with `aria-current="page"` and announces page changes through an `aria-live="polite"` region. On Explore Plants and My Matches, the number of results or matches is also announced when it changes, including "No results found" when a search gives no plants and "no matches" when the last match is removed. Filter values that would give no plants are disabled options, so screen readers say they are unavailable, and the number of plants is part of the option text. Every page has one `h1` (the page title in the header) and a `main` landmark. The match button on the plant cards shows a heart to add a plant to My Matches and ✖ to remove it, and its accessible name and tooltip say what a click does. The badge with the number of new matches on the My Matches link in the sidebar is hidden from screen readers, which instead read a text such as "2 new matches" as part of the link. On mobile, the menu button shows the same badge, and the number is part of its accessible name. If adding or removing a match fails, an error message is shown at the top of the screen in a `role="alert"` region, so screen readers read it at once without moving focus. - **Plant cards:** The inactive side of a flipped card is hidden from assistive technology with `aria-hidden`, and its information button is removed from the keyboard tab order. @@ -127,7 +127,7 @@ We considered sustainability through both our design choices and our approach to - **Consistent icons:** All icons are inline SVG components in [Icons.tsx](../frontend/src/components/icons/Icons.tsx), [ThemeIcons.tsx](../frontend/src/components/sidebarButtons/ThemeIcons.tsx) and [HeartIcon.tsx](../frontend/src/components/heartIcon/HeartIcon.tsx), drawn on the same 24 × 24 grid. They use `currentColor`, so they follow the text color in both light and dark mode, and they are sized with `font-size`, so they scale with the text around them. They are marked with `aria-hidden` and `focusable="false"`, since the search field and the buttons they are in already have accessible names, so screen readers do not read the icons twice. Because we drew the icons ourselves, there are no third-party licences to credit. -- **Responsive design:** We designed the application for both desktop and mobile screens. The layout adapts to different screen sizes to ensure that the content and navigation remain usable across devices. +- **Responsive design:** We designed the application for both desktop and mobile screens. The layout adapts to different screen sizes to ensure that the content and navigation remain usable across devices. Phones held sideways also get the mobile layout, since their screens are wide but too low for the sidebar. - **Walkthrough:** The walkthrough was added after user testing showed that new users did not get a clear overview of the app (see [User testing and the walkthrough](#user-testing-and-the-walkthrough)). Each step uses one of the avatars from the profile page, and the Next and Back buttons are pink, so the guide looks like the rest of the app. The steps are kept short, with one page per step, so users can read through them quickly or close the guide and come back to it later. diff --git a/docs/tests.md b/docs/tests.md index 7f6360cb..b313d450 100644 --- a/docs/tests.md +++ b/docs/tests.md @@ -94,7 +94,7 @@ To watch an e2e test, open UI mode, run a test, and expand it to choose the desk | Part | Statements | Branches | Functions | Lines | | -------- | ---------- | -------- | --------- | ------- | -| Frontend | 97.44 % | 93.78 % | 96.83 % | 98.43 % | +| Frontend | 97.45 % | 93.82 % | 96.83 % | 98.43 % | | Backend | 100 % | 100 % | 100 % | 100 % | - Frontend test coverage: @@ -140,7 +140,7 @@ The tests are in `frontend/src/tests`. Snapshot tests are only used for small co - `usePageCursor.test.ts` - No cursor at first, the last plant for the next page and the first for the previous one, the offset for a jump, page 1, a sort order without cursors and a page that has not loaded yet, and that a cursor is forgotten when the search, filters or sort order change. - `Header.test.tsx` - - Shows the right title for each page, including the "Page not found" title for unknown paths, opens the sidebar with the menu button, and that the menu button tells screen readers whether the sidebar is open (`aria-expanded`, `aria-controls`). + - Shows the right title for each page, including the "Page not found" title for unknown paths, opens the sidebar with the menu button, that the menu button tells screen readers whether the sidebar is open (`aria-expanded`, `aria-controls`), and that it shows the number of new matches, also in its accessible name, and no number when there are none. - `i18n.test.tsx` - Switching language changes the content at once and is kept after a reload, an unsupported saved language falls back to Norwegian, and switching works when browser storage is blocked. - `LanguageSwitcher.test.tsx` @@ -375,7 +375,7 @@ The group has tested the application manually in Chrome and Safari on Mac and on **Keyboard only:** All pages have been tested with Tab, Shift+Tab, Enter and Escape only. All links and buttons can be reached and used, the focus is visible at all times, in the sort menu, focus moves into the menu when it opens and back to the sort button when it closes, and on mobile, focus moves into the sidebar when it opens and back to the menu button when it closes. The "i" help texts can be closed with Escape. The first Tab on every page shows the "Skip to content" link, which jumps past the sidebar, and the same happens after going to another page. -**Screen reader:** To ensure aria-live was performing according to our intention, the application was tested using Voiceover on macOS. We checked that changes to the number of matches, loading messages and empty search results were announced. +**Screen reader:** To ensure aria-live was performing according to our intention, the application was tested using VoiceOver on macOS. We checked that changes to the number of matches, loading messages and empty search results were announced. **Finding: the skip link hid the search field.** The first version scrolled the content up behind the sticky header, which the component tests did not catch, since jsdom does not scroll. The link now moves focus without scrolling. @@ -383,6 +383,6 @@ The group has tested the application manually in Chrome and Safari on Mac and on ## Lighthouse -We ran Lighthouse in Chrome DevTools on the deployed app on the VM. Lighthouse audits a page for performance, accessibility, best practices and SEO. In order to securely confirm accessibility, we tested all pages of the app in both dark and lightmode. All pages of the app passed the accessibility audit with a score of **100**, so Lighthouse found no problems with, for example, colour contrast, labels or alternative text. Lighthouse was also one of the tools we used to check the colour contrast (see [Accessibility](quality.md#accessibility) in quality.md). +We ran Lighthouse in Chrome DevTools on the deployed app on the VM. Lighthouse audits a page for performance, accessibility, best practices and SEO. To confirm the accessibility, we tested all pages of the app in both dark and light mode. All pages of the app passed the accessibility audit with a score of **100**, so Lighthouse found no problems with, for example, colour contrast, labels or alternative text. Lighthouse was also one of the tools we used to check the colour contrast (see [Accessibility](quality.md#accessibility) in quality.md). Like axe, Lighthouse only finds problems that can be detected automatically, so it does not replace the manual testing above. diff --git a/e2e/helpers/names.ts b/e2e/helpers/names.ts index c4e1113a..3963bd63 100644 --- a/e2e/helpers/names.ts +++ b/e2e/helpers/names.ts @@ -4,7 +4,9 @@ // The texts come from frontend/src/i18n/locales/{en,no}/translation.json. export const names = { // Sidebar - openSidebar: /^(open sidebar|åpne sidemeny)$/i, + // The menu button can also say how many new matches there are, + // e.g. "Open sidebar, 1 new match" + openSidebar: /^(open sidebar|åpne sidemeny)\b/i, sidebarNavigation: /^(sidebar navigation|navigasjon i sidemenyen)$/i, plantMatch: /^(plant match|plante-matching)$/i, // The link can also say how many new matches there are, diff --git a/frontend/src/components/errorMessage/ErrorMessage.css b/frontend/src/components/errorMessage/ErrorMessage.css index b4d1cdf6..fb33efd2 100644 --- a/frontend/src/components/errorMessage/ErrorMessage.css +++ b/frontend/src/components/errorMessage/ErrorMessage.css @@ -34,7 +34,7 @@ } /* On mobile the header is narrow, so the message is centred at the top */ -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { .error-message-region { top: 0.5rem; right: auto; diff --git a/frontend/src/components/filterSelect/FilterSelect.css b/frontend/src/components/filterSelect/FilterSelect.css index c42d2b8a..4862af7c 100644 --- a/frontend/src/components/filterSelect/FilterSelect.css +++ b/frontend/src/components/filterSelect/FilterSelect.css @@ -6,7 +6,11 @@ } .filter select { - padding: 0.5rem; + /* The same height as the sort button. Without it, the height is the + browser's own, which is lower than the sort button on some phones. */ + height: 40px; + padding: 0 0.5rem; + box-sizing: border-box; border: 1px solid var(--dark-pink); border-radius: 8px; min-width: 160px; diff --git a/frontend/src/components/header/Header.css b/frontend/src/components/header/Header.css index cf48ea42..f5716a1c 100644 --- a/frontend/src/components/header/Header.css +++ b/frontend/src/components/header/Header.css @@ -27,6 +27,42 @@ display: none; } +/* The number of new matches, on the menu button (only shown on mobile, like + the button). Looks like the count on My Matches in the sidebar. */ +.menu-badge { + position: absolute; + top: 2px; + right: -10px; + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 1.4rem; + height: 1.4rem; + padding: 0 0.4rem; + box-sizing: border-box; + border-radius: 999px; + background: var(--dark-pink); + color: var(--text-light); + font-family: Arial, Helvetica, sans-serif; + font-size: 0.8rem; + font-weight: 700; + line-height: 1; + animation: menu-badge-pop 0.3s ease; +} + +@keyframes menu-badge-pop { + from { + transform: scale(0.4); + opacity: 0; + } +} + +@media (prefers-reduced-motion: reduce) { + .menu-badge { + animation: none; + } +} + /* Opens the walkthrough. Always in the top right corner of the header. */ .help-button { position: absolute; @@ -61,7 +97,7 @@ outline-offset: 2px; } -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { .header { height: 70px; margin-left: 0; diff --git a/frontend/src/components/header/Header.tsx b/frontend/src/components/header/Header.tsx index 35a37537..1a49b4e1 100644 --- a/frontend/src/components/header/Header.tsx +++ b/frontend/src/components/header/Header.tsx @@ -2,6 +2,7 @@ import type { Ref } from "react"; import { useTranslation } from "react-i18next"; import { useLocation } from "react-router-dom"; import { ROUTES } from "../../AppRoutes"; +import { useNewMatches } from "../../hooks/useNewMatches"; import "./Header.css"; type HeaderProps = { @@ -30,6 +31,9 @@ export default function Header({ }: HeaderProps) { const { t } = useTranslation(); const { pathname } = useLocation(); + // The same count as on My Matches in the sidebar. On mobile the sidebar is + // hidden behind this button, so the count is shown here too. + const newMatches = useNewMatches(); // Paths that are not in pageTitles are shown by the 404 page const titleKey = pageTitles[pathname] ?? "notFound.title"; @@ -41,11 +45,21 @@ export default function Header({ type="button" className="menu-button" onClick={onOpenSidebar} - aria-label={t("sidebar.openSidebar")} + aria-label={ + newMatches > 0 + ? t("sidebar.openSidebar") + + t("sidebar.newMatches", { count: newMatches }) + : t("sidebar.openSidebar") + } aria-expanded={isSidebarOpen} aria-controls="sidebar" > ☰ + {newMatches > 0 && ( + + )}

{t(titleKey)}

diff --git a/frontend/src/components/matchButton/MatchButton.css b/frontend/src/components/matchButton/MatchButton.css index 780c1fe4..1f031f0b 100644 --- a/frontend/src/components/matchButton/MatchButton.css +++ b/frontend/src/components/matchButton/MatchButton.css @@ -75,7 +75,7 @@ box-shadow: 0 0 0 3px var(--text-light); } -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { .add-match { top: -12px; right: -12px; diff --git a/frontend/src/components/plantCard/PlantCard.css b/frontend/src/components/plantCard/PlantCard.css index 43d949fe..a5ccca83 100644 --- a/frontend/src/components/plantCard/PlantCard.css +++ b/frontend/src/components/plantCard/PlantCard.css @@ -10,7 +10,7 @@ two columns on Explore Plants and My Matches. From 1360 px three columns fit at the normal size, so the cards keep it there instead of getting a lot of space between them. */ -@media (min-width: 768px) and (max-width: 1359px) { +@media (min-width: 768px) and (max-width: 1359px) and (min-height: 501px) { :root { --plant-card-compact-scale: 0.7; } @@ -399,7 +399,7 @@ text-overflow: ellipsis; } -@media (min-width: 768px) { +@media (min-width: 768px) and (min-height: 501px) { .plant-card-flipper.is-compact .plant-preference-chip { font-size: 16px; } @@ -409,7 +409,7 @@ } } -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { :root { --plant-card-width: min(280px, 62vw); } diff --git a/frontend/src/components/sidebar/Sidebar.css b/frontend/src/components/sidebar/Sidebar.css index 3de5d72a..c0166e92 100644 --- a/frontend/src/components/sidebar/Sidebar.css +++ b/frontend/src/components/sidebar/Sidebar.css @@ -118,7 +118,7 @@ display: none; } -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { /* visibility: hidden takes the closed sidebar out of the tab order and hides it from screen readers. It changes after the slide, so the sidebar is still seen while it slides out. */ @@ -149,3 +149,23 @@ cursor: pointer; } } + +/* Phones held sideways: less space around the title and the links, so the + language and theme buttons fit without scrolling */ +@media (max-height: 500px) and (orientation: landscape) { + .sidebar { + padding-top: 1rem; + padding-bottom: 1rem; + } + + .sidebar-title { + margin-top: 0; + margin-bottom: 0.5rem; + font-size: 1.8rem; + } + + .sidebar-link { + padding-top: 0.35rem; + padding-bottom: 0.35rem; + } +} diff --git a/frontend/src/components/walkthrough/Walkthrough.css b/frontend/src/components/walkthrough/Walkthrough.css index eaf61910..c1e8acf5 100644 --- a/frontend/src/components/walkthrough/Walkthrough.css +++ b/frontend/src/components/walkthrough/Walkthrough.css @@ -168,7 +168,7 @@ outline-offset: 2px; } -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { .walkthrough-mobile-hint { display: block; } @@ -195,3 +195,37 @@ padding: 10px 14px; } } + +/* Phones held sideways: a wider box without the picture, so the text and the + buttons fit on the low screen */ +@media (max-height: 500px) and (orientation: landscape) { + .walkthrough { + width: min(600px, calc(100vw - 32px)); + } + + .walkthrough-content { + padding: 16px 24px 14px; + } + + .walkthrough-image { + display: none; + } + + .walkthrough-progress { + margin-top: 0; + } + + .walkthrough-title { + margin-bottom: 8px; + font-size: 22px; + } + + .walkthrough-text { + margin-bottom: 8px; + line-height: 1.4; + } + + .walkthrough-dots { + margin: 8px 0 12px; + } +} diff --git a/frontend/src/pages/explorePlants/ExplorePlantsPage.css b/frontend/src/pages/explorePlants/ExplorePlantsPage.css index 642087d9..337a7fa2 100644 --- a/frontend/src/pages/explorePlants/ExplorePlantsPage.css +++ b/frontend/src/pages/explorePlants/ExplorePlantsPage.css @@ -64,7 +64,7 @@ position: relative; } -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { .explore-page { margin-left: 0; width: 100%; @@ -77,8 +77,13 @@ border-radius: 12px; } + /* One card per row on a phone held upright, and more when it is held + sideways and there is room for them */ .plant-grid { - grid-template-columns: 1fr; + grid-template-columns: repeat( + auto-fill, + minmax(var(--plant-card-width), 1fr) + ); gap: 20px; } } diff --git a/frontend/src/pages/myMatches/MyMatchesPage.css b/frontend/src/pages/myMatches/MyMatchesPage.css index f9476ba5..e0268ab0 100644 --- a/frontend/src/pages/myMatches/MyMatchesPage.css +++ b/frontend/src/pages/myMatches/MyMatchesPage.css @@ -162,7 +162,7 @@ justify-self: center; } -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { .my-matches-page { margin-left: 0; width: 100%; @@ -180,8 +180,13 @@ border-radius: 12px; } + /* One card per row on a phone held upright, and more when it is held + sideways and there is room for them */ .matches-grid { - grid-template-columns: 1fr; + grid-template-columns: repeat( + auto-fill, + minmax(var(--plant-card-width), 1fr) + ); gap: 20px; padding: 20px 12px; border-radius: 12px; diff --git a/frontend/src/pages/notFound/NotFoundPage.css b/frontend/src/pages/notFound/NotFoundPage.css index aeb7bc88..db1b6b0d 100644 --- a/frontend/src/pages/notFound/NotFoundPage.css +++ b/frontend/src/pages/notFound/NotFoundPage.css @@ -54,7 +54,7 @@ display: none; } -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { .not-found-page { margin-left: 0; width: 100%; diff --git a/frontend/src/pages/plantMatch/PlantMatchPage.css b/frontend/src/pages/plantMatch/PlantMatchPage.css index d523a0f3..b1aa548c 100644 --- a/frontend/src/pages/plantMatch/PlantMatchPage.css +++ b/frontend/src/pages/plantMatch/PlantMatchPage.css @@ -272,7 +272,7 @@ a.reload-button { color: var(--dark-green); } -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { .plant-match-page { margin-left: 0; width: 100%; @@ -368,3 +368,41 @@ a.reload-button { row-gap: 14px; } } + +/* Phones held sideways: too low for the buttons under the card, so they are + on each side of it, and the card gets the height below the header, so the + page does not have to be scrolled to swipe */ +@media (max-height: 500px) and (orientation: landscape) { + .plant-match-page { + padding: 12px 8px; + } + + .plant-match { + --swipe-button-size: 64px; + --plant-card-height: clamp(240px, calc(100dvh - 71px - 24px - 16px), 480px); + /* Wider than on a phone held upright, so the picture and the chips + still get room on the low card */ + --plant-card-width: min(260px, calc(var(--plant-card-height) * 0.9)); + + margin-top: 0; + grid-template-columns: auto auto auto; + column-gap: 32px; + } + + .plant-card-container { + grid-column: 2; + } + + .dislike-button, + .like-button { + grid-row: 1; + } + + .dislike-button { + grid-column: 1; + } + + .like-button { + grid-column: 3; + } +} diff --git a/frontend/src/pages/plantOwnerTest/PlantOwnerTestPage.css b/frontend/src/pages/plantOwnerTest/PlantOwnerTestPage.css index b746d91d..61cbab7f 100644 --- a/frontend/src/pages/plantOwnerTest/PlantOwnerTestPage.css +++ b/frontend/src/pages/plantOwnerTest/PlantOwnerTestPage.css @@ -170,7 +170,7 @@ line-height: 1.9; } -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { .plant-owner-test { margin-left: 0; width: 100%; diff --git a/frontend/src/pages/profile/ProfilePage.css b/frontend/src/pages/profile/ProfilePage.css index 077cc127..829c0b86 100644 --- a/frontend/src/pages/profile/ProfilePage.css +++ b/frontend/src/pages/profile/ProfilePage.css @@ -218,19 +218,39 @@ outline-offset: 3px; } -@media (max-width: 767px) { +@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) { .profile { margin-left: 0; padding: 24px 16px; } + /* The page is shown 10 % larger on desktop. On mobile that would make it + wider than the screen, so it is shown at normal size here. */ + .profile > * { + zoom: 1; + } + .profile-tabs { width: 350px; } + /* The help text is placed under the heading and is as wide as it. Next to + the info button it would reach past the right edge, and even while it is + hidden, it would make the page wider than the screen. */ + .preferences-heading { + position: relative; + } + + .preferences-info { + position: static; + } + .preferences-info-box { top: calc(100% + 6px); left: 0; + right: 0; + width: auto; + max-width: none; transform: none; } } diff --git a/frontend/src/tests/Header.test.tsx b/frontend/src/tests/Header.test.tsx index 785a0ac7..e28afc96 100644 --- a/frontend/src/tests/Header.test.tsx +++ b/frontend/src/tests/Header.test.tsx @@ -1,12 +1,21 @@ import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { MemoryRouter } from "react-router-dom"; -import { describe, it, expect, vi } from "vitest"; +import { beforeEach, describe, it, expect, vi } from "vitest"; import Header from "../components/header/Header"; import { ROUTES } from "../AppRoutes"; vi.mock("react-i18next", () => ({ - useTranslation: () => ({ t: (key: string) => key }), + useTranslation: () => ({ + t: (key: string, options?: { count?: number }) => + options?.count === undefined ? key : `${key}:${options.count}`, + }), +})); + +// The number of new matches the menu button shows +const { newMatches } = vi.hoisted(() => ({ newMatches: { count: 0 } })); +vi.mock("../hooks/useNewMatches", () => ({ + useNewMatches: () => newMatches.count, })); function renderHeader(route: string, onOpenSidebar = vi.fn()) { @@ -19,6 +28,10 @@ function renderHeader(route: string, onOpenSidebar = vi.fn()) { } describe("Header", () => { + beforeEach(() => { + newMatches.count = 0; + }); + it("tells screen readers whether the sidebar it controls is open", () => { render( @@ -55,4 +68,24 @@ describe("Header", () => { expect(onOpenSidebar).toHaveBeenCalledTimes(1); }); + + it("shows the number of new matches on the menu button, also for screen readers", () => { + newMatches.count = 2; + renderHeader(ROUTES.explore); + + const menuButton = screen.getByRole("button", { + name: "sidebar.openSidebarsidebar.newMatches:2", + }); + expect(menuButton).toHaveTextContent("2"); + }); + + it("shows no number on the menu button without new matches", () => { + renderHeader(ROUTES.explore); + + const menuButton = screen.getByRole("button", { + name: "sidebar.openSidebar", + }); + expect(menuButton).toHaveTextContent("☰"); + expect(menuButton).not.toHaveTextContent(/\d/); + }); });