Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ddfbra 246 fix missing search results #70

Merged
merged 3 commits into from
Dec 9, 2024
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
4 changes: 4 additions & 0 deletions components/pages/searchPageLayout/SearchPageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const SearchPageLayout = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isInView])

useEffect(() => {
actor.send({ type: "RESET_BOOTSTRAP_STATE" })
}, [actor])

const isNoSearchResult = !isLoadingResults && (!data.search || !data.search.pages[0].length)
const hitCountText = data.search?.hitcount ? `(${data.search.hitcount})` : ""
const searchQueryText = searchQuery ? `"${searchQuery}"` : ""
Expand Down
8 changes: 6 additions & 2 deletions lib/machines/search/search.machine.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { assign, emit, setup } from "xstate"

import { correctFacetNames } from "./helpers"
import { getFacets, performSearch } from "./queries"
import { initialContext } from "./search.machine"
import { TContext, TFilters, TInput } from "./types"

export default setup({
Expand Down Expand Up @@ -52,10 +53,13 @@ export default setup({
submittedQuery: ({ context }) => (context.submittedQuery = context.currentQuery),
}),
resetFilters: assign(() => ({
selectedFilters: {},
selectedFilters: initialContext.selectedFilters,
})),
resetSearchData: assign(() => ({
searchData: undefined,
searchData: initialContext.searchData,
})),
resetOffset: assign(() => ({
searchOffset: initialContext.searchOffset,
})),
setFacetDataInContext: assign({
facetData: ({
Expand Down
54 changes: 42 additions & 12 deletions lib/machines/search/search.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@ import { and, not } from "xstate"

import searchMachineSetup from "./search.machine.setup"

export const initialContext = {
searchOffset: 0,
searchPageSize: 0,
facetLimit: 0,
currentQuery: "",
submittedQuery: undefined,
searchData: undefined,
facetData: undefined,
selectedFilters: {},
queryClient: null,
}

export default searchMachineSetup.createMachine({
/** @xstate-layout N4IgpgJg5mDOIC5SzAQwE4GMAWA6ARgPaEAusJ6qADgMQDKAogCoD6AigKoMBKAmiwGEAMgEkGAOSYBtAAwBdRKCqFYASxKrCAO0UgAHogC0ANgCMAVlwAWAJzGATDIAcNmeYDM9zwBoQAT0QLAHZcYycnIKdTSNcndysAXwTfFAwcAmIyCmp6ZhZGAEFuAQAJfKZuEXEAcVkFJBBlNQ1tXQMEQytjS0cbKyCg0xdwpytzXwCEd2jcGxt3d1Gne273AaSUtCw8IlJySlpGViqRJhECoRYAMREhJh46Ot0m9U0dBvaTR1Cw0ysFpzmLxuCaIKxDXCmdw2cwyFamYyLKIbECpbYZPbZWgAIQA8rimHQKgUAAosAAiuPEDCeDReLXeoE+5iiuCC0Js9isK36phhoIQphkNlC4Ui0RczniphRaPSuyyBxoeIJRO4pIpVJppnqShUr1aHyMLNMbI5XJ5g35-kQZlFESiMSl4NlW3SqggABswDQmLjqtUhAxrrd7txaXrmm82oh4j17C47OYHE5jALHPZcOYuiNxXF3A5XWk8B7vb7-YHgzc7jwpDrnvqGTGEPYgiKvH1ls4gkDugLzBZcAWglygmE22ZjEX0aWfUxeCSqrV5A2o4amcbubM-vY5gsYQiggK21ZIcCZHDjD3wVPkqi3SWvT7CsUShHGo3o0apnEs64HDInj2KYfJxAKiIigOxh9DIgyptCMp3nKj5li+pR1rqH5roy+ixgMkLcjYCLmD2Ep2AKsS4BEMLsi4njuAO07uk+NBCLiBTkiwACyuLcDSK50p+664YKRG4LutjxPYXIXgO9gCiBcxUQ4V7TMsaw2EETF4AAZqonokGA6CqFoUAFFoEB0A+JlQDQEDaGAuDkKghlOQ+uB6QZRk2eZlnWaZ770l+G4dHyMhZuYLJtqmbh-DIVj9qebgjmMgJcg4XTaR5+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4hjO3zp8uZ7s26e1drgJZ-zAgySzMMII3IryczWizf6pozCT3AXPSBUBoGwOLPA7eyKOi2BFFCH+QEezxCYXUv4lgMUOCzg4IYYQiUnygWfOB+Dr59NKc-EKnQByQgYvMRlDCWWTBeoM9KwFslcIsEkJIQA */
id: "search",
initial: "bootstrap",
context: ({ input }) => ({
searchOffset: input.initialOffset ?? 0,
searchPageSize: input.searchPageSize,
facetLimit: input.facetLimit,
currentQuery: input.q ?? "",
submittedQuery: undefined,
searchData: undefined,
facetData: undefined,
selectedFilters: input.filters ?? {},
queryClient: input.queryClient ?? null,
searchOffset: input.initialOffset ?? initialContext.searchOffset,
searchPageSize: input.searchPageSize ?? initialContext.searchPageSize,
facetLimit: input.facetLimit ?? initialContext.facetLimit,
currentQuery: input.q ?? initialContext.currentQuery,
submittedQuery: initialContext.submittedQuery,
searchData: initialContext.searchData,
facetData: initialContext.facetData,
selectedFilters: input.filters ?? initialContext.selectedFilters,
queryClient: input.queryClient ?? initialContext.queryClient,
}),
states: {
bootstrap: {
Expand Down Expand Up @@ -45,7 +57,12 @@ export default searchMachineSetup.createMachine({
TOGGLE_FILTER: [
{
guard: "contextHasSearchString",
actions: ["resetSearchData", "toggleFilterInContext", "emitFilterToggled"],
actions: [
"resetSearchData",
"resetOffset",
"toggleFilterInContext",
"emitFilterToggled",
],
target: "filteringAndSearching",
},
{
Expand All @@ -60,7 +77,12 @@ export default searchMachineSetup.createMachine({
SEARCH: [
{
guard: "contextHasSearchString",
actions: ["resetSearchData", "resetFilters", "setSubmittedQueryInContext"],
actions: [
"resetSearchData",
"resetFilters",
"setSubmittedQueryInContext",
"resetOffset",
],
target: "filteringAndSearching",
},
{
Expand All @@ -73,6 +95,9 @@ export default searchMachineSetup.createMachine({
actions: ["setLoadMoreValuesInContext"],
target: "loadingMoreSearchResults",
},
RESET_BOOTSTRAP_STATE: {
target: "bootstrap",
},
},
},
filteringAndSearching: {
Expand All @@ -87,7 +112,12 @@ export default searchMachineSetup.createMachine({
SEARCH: [
{
guard: "contextHasSearchString",
actions: ["resetSearchData", "resetFilters", "setSubmittedQueryInContext"],
actions: [
"resetSearchData",
"resetFilters",
"resetOffset",
"setSubmittedQueryInContext",
],
target: "filteringAndSearching",
},
{
Expand Down
Loading