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
2 changes: 1 addition & 1 deletion frontend/src/pages/SearchResults/SearchEmptyState.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import type { FilterCount } from "./searchTypes";
import type { FilterCount } from "../../types/filters";

type SearchEmptyStateProps = {
searchTerm: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/SearchResults/SearchFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import type { FilterCount } from "./searchTypes";
import type { FilterCount } from "../../types/filters";
import FilterRow from "../../components/filterRow/FilterRow";

type SearchFiltersProps = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/SearchResults/SearchProductList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ResultRow from "../../components/resultRow/ResultRow";
import type {
SearchProduct,
ProductPrice,
} from "./searchTypes";
} from "../../types/product";

type SearchProductListProps = {
products: SearchProduct[];
Expand Down
9 changes: 3 additions & 6 deletions frontend/src/pages/SearchResults/SearchResultsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/SearchResults/SearchSortSelect.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/SearchResults/searchPreferences.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import type { SearchSort } from "./searchTypes";
import type { SearchSort } from "../../types/filters";

export type SearchPreferences = {
searchTerm: string;
Expand Down
33 changes: 27 additions & 6 deletions frontend/src/pages/SearchResults/searchQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
51 changes: 0 additions & 51 deletions frontend/src/pages/SearchResults/searchTypes.ts

This file was deleted.

9 changes: 2 additions & 7 deletions frontend/src/pages/home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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<
Expand Down
18 changes: 1 addition & 17 deletions frontend/src/pages/productDetails/productQueries.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/shoppingLists/CompletedListView.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/shoppingLists/PreviousListRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { Link } from "react-router";
import type { ShoppingList } from "./shoppingListTypes";
import type { ShoppingList } from "../../types/shoppingList";

interface PreviousListRowProps {
list: ShoppingList;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/shoppingLists/PreviousListsPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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")
)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/shoppingLists/ShoppingListCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import type { ShoppingList } from "./shoppingListTypes";
import type { ShoppingList } from "../../types/shoppingList";
import Badge from "../../components/badge/Badge";
import "./ShoppingListsPage.css";

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/shoppingLists/ShoppingListDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -97,7 +97,7 @@ function ShoppingListDetailPage() {
);
}
// Handlede lister vises uten redigering
if (list.status === "COMPLETED") {
if (list.status === "DONE") {
return <CompletedListView list={list} />;
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/shoppingLists/shoppingListMockData.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/types/filters.ts
Original file line number Diff line number Diff line change
@@ -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;
};
27 changes: 27 additions & 0 deletions frontend/src/types/product.ts
Original file line number Diff line number Diff line change
@@ -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<SearchProduct, "categoryId" | "prices"> & {
category: Category | null;
prices: (ProductPrice & { url: string | null })[];
};
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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[];
Expand Down