diff --git a/README.md b/README.md index 0d2f96aa..3581bffa 100644 --- a/README.md +++ b/README.md @@ -147,4 +147,5 @@ See [quality.md](docs/quality.md) for work practices, accessibility, sustainable ## Known issues +- The plant images are stored as base64 in the database and sent inside the GraphQL responses. This makes the responses larger, and the browser can't cache the images or load them lazily. See [Limitations of the architecture](docs/architecture.md#limitations-of-the-architecture) for why we chose it and how it could be improved in further development. - The plant descriptions and names on the plant cards are not translated to Norwegian, since they come from the English Perenual API. The watering, sunlight and care values are translated. diff --git a/docs/architecture.md b/docs/architecture.md index d6571ab8..9dd449aa 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -301,7 +301,7 @@ T03-Project-2/ │ └── testDb.ts # Shared settings for the test database (name, port, URI) ├── frontend/ │ ├── src/ -│ │ ├── assets/ # Static images +│ │ ├── assets/ # Static images (WebP) │ │ ├── components/ # Reusable UI components, each in its own folder with a matching .css file (walkthrough/ has the guide and its steps) │ │ ├── context/ # UserProvider and useUser() for the current user, ErrorMessageProvider and useErrorMessage() for error messages │ │ ├── graphql/ # All GraphQL queries, mutations and fragments, grouped by domain (fragments/, plants/, user/) @@ -328,7 +328,7 @@ T03-Project-2/ ### Naming conventions - **PascalCase** for React components and their files (`PlantCard.tsx`, `SortMenu.css`), and for TypeScript types (`Plant`, `PlantCardProps`). Every page component ends in `Page` (`ExplorePlantsPage`), and test files are named after what they test (`ExplorePlantsPage.test.tsx`). -- **camelCase** for variables, functions, hooks (`useMatchedPlants`), folders, routes (`/myMatches`), translation sections and keys (`explorePlantsPage.search`), and all other files, including images and e2e helpers (`snakePlant.png`, `globalSetup.ts`). +- **camelCase** for variables, functions, hooks (`useMatchedPlants`), folders, routes (`/myMatches`), translation sections and keys (`explorePlantsPage.search`), and all other files, including images and e2e helpers (`snakePlant.webp`, `globalSetup.ts`). - **UPPER_SNAKE_CASE** for module-level constants that never change (`ROUTES`, `PAGE_SIZE`, `GET_PLANTS`, `LANGUAGE_STORAGE_KEY`). ## How to start the backend if it stops diff --git a/docs/quality.md b/docs/quality.md index 0e9cc443..cfb210b2 100644 --- a/docs/quality.md +++ b/docs/quality.md @@ -93,6 +93,16 @@ We considered sustainability through both our design choices and our approach to - **Filter counts in one query:** The number of plants for every filter value on Explore Plants is counted in the same request as the results, in one database query, instead of one request per value. Values that would give no plants can't be chosen, so the user does not send requests that only return an empty list. +- **Images in WebP:** The avatars, plant owner test images and plant placeholder were converted from PNG to WebP. Measured on the build and on the Profile page with the avatar chooser open: + + | | PNG | WebP | Change | + | ------------------------------------ | ------ | ------ | ------ | + | All 15 images | 395 kB | 156 kB | −60 % | + | Profile page, images (8) | 260 kB | 84 kB | −68 % | + | Profile page, everything transferred | 444 kB | 268 kB | −40 % | + + The pictures were more than half of what the Profile page downloads, so this was the biggest single saving for that page. + ## Design choices - **Color palette and contrast:** We used a limited color palette to maintain a consistent visual identity across the application. We also checked the contrast between our chosen colors to help ensure that text and other interface elements remain distinguishable and in line with accessibility requirements. See [Accessibility](#accessibility). diff --git a/e2e/uiImages.spec.ts b/e2e/uiImages.spec.ts index 6af52f8b..8b22f05e 100644 --- a/e2e/uiImages.spec.ts +++ b/e2e/uiImages.spec.ts @@ -113,7 +113,7 @@ test("the placeholder picture loads on plant cards without an image", async ({ (element) => getComputedStyle(element, "::before").backgroundImage, ); const url = backgroundImage.match(/url\("?(.*?)"?\)/)?.[1]; - // Vite adds a hash to the file name in the build, for example plantPlaceholder-a1b2c3.png + // Vite adds a hash to the file name in the build, for example plantPlaceholder-a1b2c3.webp expect(url).toContain("plantPlaceholder"); expect(await loadImageWidth(page, url!)).toBeGreaterThan(0); diff --git a/frontend/src/assets/avatars/anthurium.png b/frontend/src/assets/avatars/anthurium.png deleted file mode 100644 index 14af55e8..00000000 Binary files a/frontend/src/assets/avatars/anthurium.png and /dev/null differ diff --git a/frontend/src/assets/avatars/anthurium.webp b/frontend/src/assets/avatars/anthurium.webp new file mode 100644 index 00000000..3787d666 Binary files /dev/null and b/frontend/src/assets/avatars/anthurium.webp differ diff --git a/frontend/src/assets/avatars/fern.png b/frontend/src/assets/avatars/fern.png deleted file mode 100644 index 96a33141..00000000 Binary files a/frontend/src/assets/avatars/fern.png and /dev/null differ diff --git a/frontend/src/assets/avatars/fern.webp b/frontend/src/assets/avatars/fern.webp new file mode 100644 index 00000000..110e37e7 Binary files /dev/null and b/frontend/src/assets/avatars/fern.webp differ diff --git a/frontend/src/assets/avatars/monstera.png b/frontend/src/assets/avatars/monstera.png deleted file mode 100644 index a68d8e31..00000000 Binary files a/frontend/src/assets/avatars/monstera.png and /dev/null differ diff --git a/frontend/src/assets/avatars/monstera.webp b/frontend/src/assets/avatars/monstera.webp new file mode 100644 index 00000000..6b01b5be Binary files /dev/null and b/frontend/src/assets/avatars/monstera.webp differ diff --git a/frontend/src/assets/avatars/orchid.png b/frontend/src/assets/avatars/orchid.png deleted file mode 100644 index be1b8484..00000000 Binary files a/frontend/src/assets/avatars/orchid.png and /dev/null differ diff --git a/frontend/src/assets/avatars/orchid.webp b/frontend/src/assets/avatars/orchid.webp new file mode 100644 index 00000000..3b772571 Binary files /dev/null and b/frontend/src/assets/avatars/orchid.webp differ diff --git a/frontend/src/assets/avatars/pothos.png b/frontend/src/assets/avatars/pothos.png deleted file mode 100644 index bba4626f..00000000 Binary files a/frontend/src/assets/avatars/pothos.png and /dev/null differ diff --git a/frontend/src/assets/avatars/pothos.webp b/frontend/src/assets/avatars/pothos.webp new file mode 100644 index 00000000..1a2078dd Binary files /dev/null and b/frontend/src/assets/avatars/pothos.webp differ diff --git a/frontend/src/assets/avatars/profile.png b/frontend/src/assets/avatars/profile.png deleted file mode 100644 index 1139c813..00000000 Binary files a/frontend/src/assets/avatars/profile.png and /dev/null differ diff --git a/frontend/src/assets/avatars/profile.webp b/frontend/src/assets/avatars/profile.webp new file mode 100644 index 00000000..47bf0072 Binary files /dev/null and b/frontend/src/assets/avatars/profile.webp differ diff --git a/frontend/src/assets/avatars/snakePlant.png b/frontend/src/assets/avatars/snakePlant.png deleted file mode 100644 index 52d6c0c4..00000000 Binary files a/frontend/src/assets/avatars/snakePlant.png and /dev/null differ diff --git a/frontend/src/assets/avatars/snakePlant.webp b/frontend/src/assets/avatars/snakePlant.webp new file mode 100644 index 00000000..4569c9e5 Binary files /dev/null and b/frontend/src/assets/avatars/snakePlant.webp differ diff --git a/frontend/src/assets/avatars/succulent.png b/frontend/src/assets/avatars/succulent.png deleted file mode 100644 index d0ff9de6..00000000 Binary files a/frontend/src/assets/avatars/succulent.png and /dev/null differ diff --git a/frontend/src/assets/avatars/succulent.webp b/frontend/src/assets/avatars/succulent.webp new file mode 100644 index 00000000..9edc0141 Binary files /dev/null and b/frontend/src/assets/avatars/succulent.webp differ diff --git a/frontend/src/assets/plantPlaceholder.png b/frontend/src/assets/plantPlaceholder.png deleted file mode 100644 index eadc554b..00000000 Binary files a/frontend/src/assets/plantPlaceholder.png and /dev/null differ diff --git a/frontend/src/assets/plantPlaceholder.webp b/frontend/src/assets/plantPlaceholder.webp new file mode 100644 index 00000000..cfb2de85 Binary files /dev/null and b/frontend/src/assets/plantPlaceholder.webp differ diff --git a/frontend/src/assets/plantQuiz/averageCityGardener.png b/frontend/src/assets/plantQuiz/averageCityGardener.png deleted file mode 100644 index 2b458e88..00000000 Binary files a/frontend/src/assets/plantQuiz/averageCityGardener.png and /dev/null differ diff --git a/frontend/src/assets/plantQuiz/averageCityGardener.webp b/frontend/src/assets/plantQuiz/averageCityGardener.webp new file mode 100644 index 00000000..6524e753 Binary files /dev/null and b/frontend/src/assets/plantQuiz/averageCityGardener.webp differ diff --git a/frontend/src/assets/plantQuiz/averageCountryGardener.png b/frontend/src/assets/plantQuiz/averageCountryGardener.png deleted file mode 100644 index 1ce89388..00000000 Binary files a/frontend/src/assets/plantQuiz/averageCountryGardener.png and /dev/null differ diff --git a/frontend/src/assets/plantQuiz/averageCountryGardener.webp b/frontend/src/assets/plantQuiz/averageCountryGardener.webp new file mode 100644 index 00000000..4ec3ef5f Binary files /dev/null and b/frontend/src/assets/plantQuiz/averageCountryGardener.webp differ diff --git a/frontend/src/assets/plantQuiz/cityGardenerDreaming.png b/frontend/src/assets/plantQuiz/cityGardenerDreaming.png deleted file mode 100644 index fbdb1c5a..00000000 Binary files a/frontend/src/assets/plantQuiz/cityGardenerDreaming.png and /dev/null differ diff --git a/frontend/src/assets/plantQuiz/cityGardenerDreaming.webp b/frontend/src/assets/plantQuiz/cityGardenerDreaming.webp new file mode 100644 index 00000000..c80059c7 Binary files /dev/null and b/frontend/src/assets/plantQuiz/cityGardenerDreaming.webp differ diff --git a/frontend/src/assets/plantQuiz/cityMinimalist.png b/frontend/src/assets/plantQuiz/cityMinimalist.png deleted file mode 100644 index 116350be..00000000 Binary files a/frontend/src/assets/plantQuiz/cityMinimalist.png and /dev/null differ diff --git a/frontend/src/assets/plantQuiz/cityMinimalist.webp b/frontend/src/assets/plantQuiz/cityMinimalist.webp new file mode 100644 index 00000000..a0e14f86 Binary files /dev/null and b/frontend/src/assets/plantQuiz/cityMinimalist.webp differ diff --git a/frontend/src/assets/plantQuiz/countryMinimalist.png b/frontend/src/assets/plantQuiz/countryMinimalist.png deleted file mode 100644 index a3ba243d..00000000 Binary files a/frontend/src/assets/plantQuiz/countryMinimalist.png and /dev/null differ diff --git a/frontend/src/assets/plantQuiz/countryMinimalist.webp b/frontend/src/assets/plantQuiz/countryMinimalist.webp new file mode 100644 index 00000000..8d5365e7 Binary files /dev/null and b/frontend/src/assets/plantQuiz/countryMinimalist.webp differ diff --git a/frontend/src/assets/plantQuiz/gardenExpert.png b/frontend/src/assets/plantQuiz/gardenExpert.png deleted file mode 100644 index fdda2b99..00000000 Binary files a/frontend/src/assets/plantQuiz/gardenExpert.png and /dev/null differ diff --git a/frontend/src/assets/plantQuiz/gardenExpert.webp b/frontend/src/assets/plantQuiz/gardenExpert.webp new file mode 100644 index 00000000..45dbebab Binary files /dev/null and b/frontend/src/assets/plantQuiz/gardenExpert.webp differ diff --git a/frontend/src/components/plantCard/PlantCard.css b/frontend/src/components/plantCard/PlantCard.css index 58e4fa91..43d949fe 100644 --- a/frontend/src/components/plantCard/PlantCard.css +++ b/frontend/src/components/plantCard/PlantCard.css @@ -237,7 +237,7 @@ content: ""; position: absolute; inset: 0; - background: url("../../assets/plantPlaceholder.png") center / cover no-repeat; + background: url("../../assets/plantPlaceholder.webp") center / cover no-repeat; } .plant-card-front .plant-card-preferences { diff --git a/frontend/src/components/walkthrough/walkthroughSteps.ts b/frontend/src/components/walkthrough/walkthroughSteps.ts index dc724358..c5b5a4be 100644 --- a/frontend/src/components/walkthrough/walkthroughSteps.ts +++ b/frontend/src/components/walkthrough/walkthroughSteps.ts @@ -2,13 +2,13 @@ // The text for each step is in translation.json under walkthrough.steps.. import { ROUTES } from "../../AppRoutes"; -import monstera from "../../assets/avatars/monstera.png"; -import pothos from "../../assets/avatars/pothos.png"; -import fern from "../../assets/avatars/fern.png"; -import anthurium from "../../assets/avatars/anthurium.png"; -import orchid from "../../assets/avatars/orchid.png"; -import succulent from "../../assets/avatars/succulent.png"; -import snakePlant from "../../assets/avatars/snakePlant.png"; +import monstera from "../../assets/avatars/monstera.webp"; +import pothos from "../../assets/avatars/pothos.webp"; +import fern from "../../assets/avatars/fern.webp"; +import anthurium from "../../assets/avatars/anthurium.webp"; +import orchid from "../../assets/avatars/orchid.webp"; +import succulent from "../../assets/avatars/succulent.webp"; +import snakePlant from "../../assets/avatars/snakePlant.webp"; export type WalkthroughStep = { id: string; diff --git a/frontend/src/pages/plantOwnerTest/plantOwnerTest.ts b/frontend/src/pages/plantOwnerTest/plantOwnerTest.ts index 1a750b29..032f9525 100644 --- a/frontend/src/pages/plantOwnerTest/plantOwnerTest.ts +++ b/frontend/src/pages/plantOwnerTest/plantOwnerTest.ts @@ -1,11 +1,11 @@ // The questions and results of the plant owner test -import cityMinimalist from "../../assets/plantQuiz/cityMinimalist.png"; -import averageCityGardener from "../../assets/plantQuiz/averageCityGardener.png"; -import cityGardenerDreaming from "../../assets/plantQuiz/cityGardenerDreaming.png"; -import countryMinimalist from "../../assets/plantQuiz/countryMinimalist.png"; -import averageCountryGardener from "../../assets/plantQuiz/averageCountryGardener.png"; -import gardenExpert from "../../assets/plantQuiz/gardenExpert.png"; +import cityMinimalist from "../../assets/plantQuiz/cityMinimalist.webp"; +import averageCityGardener from "../../assets/plantQuiz/averageCityGardener.webp"; +import cityGardenerDreaming from "../../assets/plantQuiz/cityGardenerDreaming.webp"; +import countryMinimalist from "../../assets/plantQuiz/countryMinimalist.webp"; +import averageCountryGardener from "../../assets/plantQuiz/averageCountryGardener.webp"; +import gardenExpert from "../../assets/plantQuiz/gardenExpert.webp"; export type PlantOwnerType = | "cityMinimalist" diff --git a/frontend/src/pages/profile/ProfilePage.tsx b/frontend/src/pages/profile/ProfilePage.tsx index a4911e84..7e4f062e 100644 --- a/frontend/src/pages/profile/ProfilePage.tsx +++ b/frontend/src/pages/profile/ProfilePage.tsx @@ -1,16 +1,16 @@ import "./ProfilePage.css"; -import profileImg from "../../assets/avatars/profile.png"; +import profileImg from "../../assets/avatars/profile.webp"; import type { Preference } from "../../types/Preference.ts"; import { useTranslation } from "react-i18next"; import { useState } from "react"; import PlantPreferences from "../../components/plantPreferences/PlantPreferences.tsx"; -import monstera from "../../assets/avatars/monstera.png"; -import anthurium from "../../assets/avatars/anthurium.png"; -import fern from "../../assets/avatars/fern.png"; -import orchid from "../../assets/avatars/orchid.png"; -import pothos from "../../assets/avatars/pothos.png"; -import snakePlant from "../../assets/avatars/snakePlant.png"; -import succulent from "../../assets/avatars/succulent.png"; +import monstera from "../../assets/avatars/monstera.webp"; +import anthurium from "../../assets/avatars/anthurium.webp"; +import fern from "../../assets/avatars/fern.webp"; +import orchid from "../../assets/avatars/orchid.webp"; +import pothos from "../../assets/avatars/pothos.webp"; +import snakePlant from "../../assets/avatars/snakePlant.webp"; +import succulent from "../../assets/avatars/succulent.webp"; import { useProfile } from "../../hooks/useProfile.ts"; import { useDismissibleTooltip } from "../../hooks/useDismissibleTooltip.ts"; import {