Skip to content

Commit

Permalink
fix: missing export in search input
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasGross committed Oct 18, 2024
1 parent 23401dc commit bc1a3ca
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 69 deletions.
2 changes: 1 addition & 1 deletion components/global/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react"
import { Button } from "@/components/shared/button/Button"
import DarkModeToggle from "@/components/shared/darkModeToggle/DarkModeToggle"
import Icon from "@/components/shared/icon/Icon"
import { SearchInput } from "@/components/shared/searchInput/SearchInput"
import SearchInput from "@/components/shared/searchInput/SearchInput"

function Header() {
return (
Expand Down
130 changes: 63 additions & 67 deletions components/pages/searchPageLayout/SearchPageLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
'use client'
"use client"

import { useSearchParams } from 'next/navigation'
import { useSearchParams } from "next/navigation"
import { useEffect } from "react"

import SearchFilterBar from "./SearchFilterBar"

import {
FacetField,
FacetValue,
useSearchFacetsQuery,
useSearchWithPaginationQuery
} from '@/lib/graphql/generated/fbi/graphql'
import SearchFilterBar from './SearchFilterBar'
import { useEffect } from 'react'
useSearchWithPaginationQuery,
} from "@/lib/graphql/generated/fbi/graphql"

const facetDefinitions = [
'materialTypesGeneral',
'mainLanguages',
'age',
'lix',
'subjects',
'let'
"materialTypesGeneral",
"mainLanguages",
"age",
"lix",
"subjects",
"let",
] as FacetField[]

// TODO: Add branches though endpoint
const branchIds = [
'775120',
'775122',
'775144',
'775167',
'775146',
'775168',
'751010',
'775147',
'751032',
'751031',
'775126',
'751030',
'775149',
'775127',
'775160',
'775162',
'775140',
'751009',
'751029',
'751027',
'751026',
'751025',
'775133',
'751024',
'775100',
'775170',
'775150',
'775130'
"775120",
"775122",
"775144",
"775167",
"775146",
"775168",
"751010",
"775147",
"751032",
"751031",
"775126",
"751030",
"775149",
"775127",
"775160",
"775162",
"775140",
"751009",
"751029",
"751027",
"751026",
"751025",
"775133",
"751024",
"775100",
"775170",
"775150",
"775130",
] as string[]

export type FilterItemTerm = Omit<FacetValue, '__typename'>
export type FilterItemTerm = Omit<FacetValue, "__typename">

export const formatFacetTerms = (filters: {
[key: string]: { [key: string]: FilterItemTerm }
}) => {
export const formatFacetTerms = (filters: { [key: string]: { [key: string]: FilterItemTerm } }) => {
return Object.keys(filters).reduce(
(acc, key) => ({
...acc,
[key]: Object.keys(filters[key])
[key]: Object.keys(filters[key]),
}),
{}
)
}

const SearchPageLayout = ({ searchQuery }: { searchQuery?: string }) => {
const searchParams = useSearchParams()
const q = searchQuery || searchParams.get('q') || ''
const q = searchQuery || searchParams.get("q") || ""

const facetsForSearchRequest = facetDefinitions.reduce(
(acc, facetDefinition) => {
const value = searchParams.get(facetDefinition)
if (value) {
return {
...acc,
[facetDefinition]: [value]
[facetDefinition]: [value],
}
}

Expand All @@ -84,34 +84,30 @@ const SearchPageLayout = ({ searchQuery }: { searchQuery?: string }) => {
{} as { [key: string]: string[] }
)

console.log('facetsForSearchRequest', facetsForSearchRequest)

const { data, error, isLoading, isPending, isFetching } =
useSearchWithPaginationQuery({
q: { all: q },
offset: 0,
limit: 10,
filters: {
// TODO: Add filters though endpoint
branchId: branchIds,
...facetsForSearchRequest
}
})
const { data, error, isLoading, isPending, isFetching } = useSearchWithPaginationQuery({
q: { all: q },
offset: 0,
limit: 10,
filters: {
branchId: branchIds,
...facetsForSearchRequest,
},
})

const {
data: facetData,
error: facetError,
isLoading: facetIsLoading,
isPending: facetIsPending,
isFetching: facetIsFetching
isFetching: facetIsFetching,
} = useSearchFacetsQuery({
q: { all: q },
facetLimit: 100,
facets: facetDefinitions,
filters: {
branchId: branchIds,
...facetsForSearchRequest
}
...facetsForSearchRequest,
},
})

useEffect(() => {
Expand All @@ -123,18 +119,18 @@ const SearchPageLayout = ({ searchQuery }: { searchQuery?: string }) => {
}

return (
<div>
<div className="content-container">
<SearchFilterBar facets={facetData?.search?.facets || []} />
<h1 className="text-typo-heading-2">{`Viser resultater for "${q}" ${data?.search.hitcount ? '(' + data?.search.hitcount + ')' : ''}`}</h1>
<h1 className="text-typo-heading-2">{`Viser resultater for "${q}" ${data?.search.hitcount ? "(" + data?.search.hitcount + ")" : ""}`}</h1>
{isFetching && <p>isFetching...</p>}
{isLoading && <p>isLoading...</p>}
{isPending && <p>isPending...</p>}
{data?.search.hitcount === 0 && <p>Ingen resultater</p>}
<div className="gap-grid-gap-x grid grid-cols-3">
{data?.search?.hitcount &&
data?.search?.hitcount > 0 &&
data.search.works.map((work) => (
<div key={work.workId} className="bg-background-foreground p-4">
data.search.works.map(work => (
<div key={work.workId} className="bg-background-overlay p-4">
<p>{work.titles.full}</p>

<pre>{JSON.stringify(work, null, 2)}</pre>
Expand Down
4 changes: 3 additions & 1 deletion components/shared/searchInput/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const SearchInput = ({ className }: { className?: string }) => {
<input
ref={inputRef}
className={cn(
`text-sm file:text-sm bg-background-foreground flex h-[50px] w-full rounded-base px-5
`text-sm file:text-sm flex h-[50px] w-full rounded-base bg-background-overlay px-5
text-typo-subtitle-lg shadow-sm transition-colors file:border-0 file:bg-transparent file:font-medium
file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none
focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 lg:h-20`,
Expand All @@ -64,3 +64,5 @@ const SearchInput = ({ className }: { className?: string }) => {
)
}
SearchInput.displayName = "SearchInput"

export default SearchInput
1 change: 1 addition & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ const config: Config = {
"grid-column": "var(--grid-column)",
"grid-column-half": "calc(var(--grid-column)/2)",
"grid-column-quarter": "calc(var(--grid-column)/4)",
"grid-gap-x": "var(--grid-gap-x)",
},
boxShadow: {
button: "2px 2px 0 0px var(--foreground)",
Expand Down

0 comments on commit bc1a3ca

Please sign in to comment.