diff --git a/frontend/src/pages/SearchResults/SearchEmptyState.tsx b/frontend/src/pages/SearchResults/SearchEmptyState.tsx index bf5510d..9264e0f 100644 --- a/frontend/src/pages/SearchResults/SearchEmptyState.tsx +++ b/frontend/src/pages/SearchResults/SearchEmptyState.tsx @@ -1,5 +1,5 @@ -import type { FilterCount } from "./searchTypes"; +import type { FilterCount } from "../../types/filters"; type SearchEmptyStateProps = { searchTerm: string; diff --git a/frontend/src/pages/SearchResults/SearchFilters.tsx b/frontend/src/pages/SearchResults/SearchFilters.tsx index 38a9db6..e5b00c2 100644 --- a/frontend/src/pages/SearchResults/SearchFilters.tsx +++ b/frontend/src/pages/SearchResults/SearchFilters.tsx @@ -1,5 +1,5 @@ -import type { FilterCount } from "./searchTypes"; +import type { FilterCount } from "../../types/filters"; import FilterRow from "../../components/filterRow/FilterRow"; type SearchFiltersProps = { diff --git a/frontend/src/pages/SearchResults/SearchProductList.tsx b/frontend/src/pages/SearchResults/SearchProductList.tsx index 7b920b8..b35446d 100644 --- a/frontend/src/pages/SearchResults/SearchProductList.tsx +++ b/frontend/src/pages/SearchResults/SearchProductList.tsx @@ -2,7 +2,7 @@ import ResultRow from "../../components/resultRow/ResultRow"; import type { SearchProduct, ProductPrice, -} from "./searchTypes"; +} from "../../types/product"; type SearchProductListProps = { products: SearchProduct[]; diff --git a/frontend/src/pages/SearchResults/SearchResultsPage.tsx b/frontend/src/pages/SearchResults/SearchResultsPage.tsx index 44f001f..bf6a522 100644 --- a/frontend/src/pages/SearchResults/SearchResultsPage.tsx +++ b/frontend/src/pages/SearchResults/SearchResultsPage.tsx @@ -26,11 +26,8 @@ import { saveSearchPreferences, } from "./searchPreferences"; -import type { - SearchSort, - SearchProduct, - FilterCount, -} from "./searchTypes"; +import type { SearchProduct, Category } from "../../types/product"; +import type { SearchSort, FilterCount } from "../../types/filters"; import "./SearchResultsPage.css"; @@ -42,7 +39,7 @@ const PAGE_SIZE = 20; // Typer for spørringen som henter alle kategorinavn type CategoryNamesData = { - categories: { id: string; name: string }[]; + categories: Category[]; }; // Henter alle kategorinavn én gang, slik at filterbrikkene alltid kan vise diff --git a/frontend/src/pages/SearchResults/SearchSortSelect.tsx b/frontend/src/pages/SearchResults/SearchSortSelect.tsx index 5422d61..61b7437 100644 --- a/frontend/src/pages/SearchResults/SearchSortSelect.tsx +++ b/frontend/src/pages/SearchResults/SearchSortSelect.tsx @@ -1,7 +1,7 @@ import { useEffect, useId, useRef, useState } from "react"; import type { KeyboardEvent } from "react"; -import type { SearchSort } from "./searchTypes"; +import type { SearchSort } from "../../types/filters"; type SearchSortSelectProps = { value: SearchSort; diff --git a/frontend/src/pages/SearchResults/searchPreferences.ts b/frontend/src/pages/SearchResults/searchPreferences.ts index 11a0cae..0397bc5 100644 --- a/frontend/src/pages/SearchResults/searchPreferences.ts +++ b/frontend/src/pages/SearchResults/searchPreferences.ts @@ -1,5 +1,5 @@ -import type { SearchSort } from "./searchTypes"; +import type { SearchSort } from "../../types/filters"; export type SearchPreferences = { searchTerm: string; diff --git a/frontend/src/pages/SearchResults/searchQueries.ts b/frontend/src/pages/SearchResults/searchQueries.ts index 973f0db..e16b259 100644 --- a/frontend/src/pages/SearchResults/searchQueries.ts +++ b/frontend/src/pages/SearchResults/searchQueries.ts @@ -2,12 +2,33 @@ import { gql } from "@apollo/client"; import type { TypedDocumentNode } from "@apollo/client"; -import type { - SearchProductsData, - SearchProductsVariables, - SearchFilterCountsData, - SearchFilterCountsVariables, -} from "./searchTypes"; +import type { SearchProduct } from "../../types/product"; +import type { FilterCount, SearchSort } from "../../types/filters"; + +export type SearchProductsData = { + products: SearchProduct[]; + productsCount: number; +}; + +export type SearchProductsVariables = { + search?: string; + categories?: string[]; + storeCodes?: string[]; + sort?: SearchSort; + limit?: number; + offset?: number; +}; + +export type SearchFilterCountsData = { + categoryFilterCounts: FilterCount[]; + storeFilterCounts: FilterCount[]; +}; + +export type SearchFilterCountsVariables = { + search?: string; + storeCodes?: string[]; + categories?: string[]; +}; export const SEARCH_PRODUCTS_QUERY: TypedDocumentNode< SearchProductsData, diff --git a/frontend/src/pages/SearchResults/searchTypes.ts b/frontend/src/pages/SearchResults/searchTypes.ts deleted file mode 100644 index 0e44811..0000000 --- a/frontend/src/pages/SearchResults/searchTypes.ts +++ /dev/null @@ -1,51 +0,0 @@ - -export type ProductPrice = { - storeCode: string; - price: number; - unitPrice: number | null; -}; - -export type SearchProduct = { - ean: string; - name: string; - brand: string | null; - imageUrl: string | null; - categoryId: string | null; - prices: ProductPrice[]; -}; - -export type SearchSort = - | "relevance" - | "price_asc" - | "price_desc"; - -export type SearchProductsData = { - products: SearchProduct[]; - productsCount: number; -}; - -export type SearchProductsVariables = { - search?: string; - categories?: string[]; - storeCodes?: string[]; - sort?: SearchSort; - limit?: number; - offset?: number; -}; - -export type FilterCount = { - value: string; - label: string; - count: number; -}; - -export type SearchFilterCountsData = { - categoryFilterCounts: FilterCount[]; - storeFilterCounts: FilterCount[]; -}; - -export type SearchFilterCountsVariables = { - search?: string; - storeCodes?: string[]; - categories?: string[]; -}; diff --git a/frontend/src/pages/home/HomePage.tsx b/frontend/src/pages/home/HomePage.tsx index 03f2a30..4b6ada4 100644 --- a/frontend/src/pages/home/HomePage.tsx +++ b/frontend/src/pages/home/HomePage.tsx @@ -3,6 +3,7 @@ import { gql } from "@apollo/client"; import type { TypedDocumentNode } from "@apollo/client"; import { useQuery } from "@apollo/client/react"; +import type { FilterCount } from "../../types/filters"; import { homeCategories } from "./homeCategories"; @@ -29,14 +30,8 @@ const noteItems = [ // GRAPHQL – KATEGORIER OG PRODUKTANTALL // ========================================== -type CategoryCount = { - value: string; - label: string; - count: number; -}; - type CategoryCountsData = { - categoryFilterCounts: CategoryCount[]; + categoryFilterCounts: FilterCount[]; }; const HOME_CATEGORY_COUNTS_QUERY: TypedDocumentNode< diff --git a/frontend/src/pages/productDetails/productQueries.ts b/frontend/src/pages/productDetails/productQueries.ts index 83fca79..7e20417 100644 --- a/frontend/src/pages/productDetails/productQueries.ts +++ b/frontend/src/pages/productDetails/productQueries.ts @@ -1,22 +1,6 @@ import { gql } from "@apollo/client"; import type { TypedDocumentNode } from "@apollo/client"; - -export type Product = { - ean: string; - name: string; - brand: string | null; - imageUrl: string | null; - category: { - id: string; - name: string; - } | null; - prices: { - storeCode: string; - price: number; - unitPrice: number | null; - url: string | null; - }[]; -}; +import type { Product } from "../../types/product"; type ProductQueryData = { product: Product | null; diff --git a/frontend/src/pages/shoppingLists/CompletedListView.tsx b/frontend/src/pages/shoppingLists/CompletedListView.tsx index d7d08e4..84271bd 100644 --- a/frontend/src/pages/shoppingLists/CompletedListView.tsx +++ b/frontend/src/pages/shoppingLists/CompletedListView.tsx @@ -1,5 +1,5 @@ import { Link } from "react-router"; -import type { ShoppingList } from "./shoppingListTypes"; +import type { ShoppingList } from "../../types/shoppingList"; import "./CompletedListView.css"; import Button from "../../components/button/Button"; diff --git a/frontend/src/pages/shoppingLists/PreviousListRow.tsx b/frontend/src/pages/shoppingLists/PreviousListRow.tsx index 5e48ca4..624b99a 100644 --- a/frontend/src/pages/shoppingLists/PreviousListRow.tsx +++ b/frontend/src/pages/shoppingLists/PreviousListRow.tsx @@ -1,6 +1,6 @@ import { Link } from "react-router"; -import type { ShoppingList } from "./shoppingListTypes"; +import type { ShoppingList } from "../../types/shoppingList"; interface PreviousListRowProps { list: ShoppingList; diff --git a/frontend/src/pages/shoppingLists/PreviousListsPage.tsx b/frontend/src/pages/shoppingLists/PreviousListsPage.tsx index 829b471..52213b7 100644 --- a/frontend/src/pages/shoppingLists/PreviousListsPage.tsx +++ b/frontend/src/pages/shoppingLists/PreviousListsPage.tsx @@ -1,7 +1,7 @@ import { useEffect, useMemo, useState } from "react"; import SegmentedControl from "../../components/segmentedControl/SegmentedControl"; import PreviousListRow from "./PreviousListRow"; -import type { ShoppingList } from "./shoppingListTypes"; +import type { ShoppingList } from "../../types/shoppingList"; import "./PreviousListsPage.css"; import "./ShoppingListsPage.css"; import { mockLists } from "./shoppingListMockData"; @@ -86,7 +86,7 @@ export default function PreviousListsPage() { return mockLists .filter( (list) => - list.status === "COMPLETED" && + list.status === "DONE" && list.name.toLocaleLowerCase("nb-NO").includes( search.trim().toLocaleLowerCase("nb-NO") ) diff --git a/frontend/src/pages/shoppingLists/ShoppingListCard.tsx b/frontend/src/pages/shoppingLists/ShoppingListCard.tsx index 030243c..3c23d94 100644 --- a/frontend/src/pages/shoppingLists/ShoppingListCard.tsx +++ b/frontend/src/pages/shoppingLists/ShoppingListCard.tsx @@ -1,5 +1,5 @@ -import type { ShoppingList } from "./shoppingListTypes"; +import type { ShoppingList } from "../../types/shoppingList"; import Badge from "../../components/badge/Badge"; import "./ShoppingListsPage.css"; diff --git a/frontend/src/pages/shoppingLists/ShoppingListDetailPage.tsx b/frontend/src/pages/shoppingLists/ShoppingListDetailPage.tsx index 1e6cbe4..323ec23 100644 --- a/frontend/src/pages/shoppingLists/ShoppingListDetailPage.tsx +++ b/frontend/src/pages/shoppingLists/ShoppingListDetailPage.tsx @@ -2,7 +2,7 @@ import { useState } from "react"; import type { SubmitEvent } from "react"; import { Link, useParams } from "react-router"; import { mockLists } from "./shoppingListMockData"; -import type { ShoppingListItem } from "./shoppingListTypes"; +import type { ShoppingListItem } from "../../types/shoppingList"; import "./ShoppingListDetailPage.css"; import Button from "../../components/button/Button"; import ShoppingListRow from "../../components/shoppingListRow/ShoppingListRow"; @@ -97,7 +97,7 @@ function ShoppingListDetailPage() { ); } // Handlede lister vises uten redigering - if (list.status === "COMPLETED") { + if (list.status === "DONE") { return ; } diff --git a/frontend/src/pages/shoppingLists/shoppingListMockData.ts b/frontend/src/pages/shoppingLists/shoppingListMockData.ts index 244f6f4..612dbb4 100644 --- a/frontend/src/pages/shoppingLists/shoppingListMockData.ts +++ b/frontend/src/pages/shoppingLists/shoppingListMockData.ts @@ -1,4 +1,4 @@ -import type { ShoppingList } from "./shoppingListTypes"; +import type { ShoppingList } from "../../types/shoppingList"; // Midlertidige data som brukes av både oversikten og handlelistesiden. // Byttes ut med GraphQL når backend er klar. @@ -195,7 +195,7 @@ export const mockLists: ShoppingList[] = [ { id: "11", name: "Ukeshandel", - status: "COMPLETED", + status: "DONE", inUse: false, createdAt: "2026-09-15", completedAt: "2026-09-18", diff --git a/frontend/src/types/filters.ts b/frontend/src/types/filters.ts new file mode 100644 index 0000000..15724f4 --- /dev/null +++ b/frontend/src/types/filters.ts @@ -0,0 +1,8 @@ +export type SearchSort = "relevance" | "price_asc" | "price_desc"; + +// Ett valg i et filter, f.eks. en kategori eller butikk, med antall treff +export type FilterCount = { + value: string; + label: string; + count: number; +}; diff --git a/frontend/src/types/product.ts b/frontend/src/types/product.ts new file mode 100644 index 0000000..8f470b1 --- /dev/null +++ b/frontend/src/types/product.ts @@ -0,0 +1,27 @@ +// Pris i én butikk +export type ProductPrice = { + storeCode: string; + price: number; + unitPrice: number | null; +}; + +export type Category = { + id: string; + name: string; +}; + +// Vare slik den vises i søkeresultatene +export type SearchProduct = { + ean: string; + name: string; + brand: string | null; + imageUrl: string | null; + categoryId: string | null; + prices: ProductPrice[]; +}; + +// Vare slik den vises på produktsiden: hele kategorien og lenke til butikken +export type Product = Omit & { + category: Category | null; + prices: (ProductPrice & { url: string | null })[]; +}; diff --git a/frontend/src/pages/shoppingLists/shoppingListTypes.ts b/frontend/src/types/shoppingList.ts similarity index 75% rename from frontend/src/pages/shoppingLists/shoppingListTypes.ts rename to frontend/src/types/shoppingList.ts index 8a7ed85..a004ee3 100644 --- a/frontend/src/pages/shoppingLists/shoppingListTypes.ts +++ b/frontend/src/types/shoppingList.ts @@ -1,3 +1,6 @@ +// Samme verdier som databasen tillater (CHECK i 001_init.sql) +export type ShoppingListStatus = "ACTIVE" | "DONE"; + export interface ShoppingListItem { id: string; ean: string; @@ -11,7 +14,7 @@ export interface ShoppingListItem { export interface ShoppingList { id: string; name: string; - status: "ACTIVE" | "COMPLETED"; + status: ShoppingListStatus; inUse: boolean; createdAt: string; items: ShoppingListItem[];