-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1162 from City-of-Helsinki/UHF-11306-hakuvahti-fixes
UHF-11306: hakuvahti fixes
- Loading branch information
Showing
7 changed files
with
170 additions
and
239 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
116 changes: 0 additions & 116 deletions
116
src/js/react/apps/job-search/containers/PromotedResultsContainer.tsx
This file was deleted.
Oops, something went wrong.
111 changes: 99 additions & 12 deletions
111
src/js/react/apps/job-search/containers/ResultsContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,106 @@ | ||
import { useAtomValue } from 'jotai'; | ||
import { useAtomValue, useSetAtom } from 'jotai'; | ||
import { SyntheticEvent, createRef } from 'react'; | ||
|
||
import SimpleResultsContainer from './SimpleResultsContainer'; | ||
import PromotedResultsContainer from './PromotedResultsContainer'; | ||
import { configurationsAtom } from '../store'; | ||
import Pagination from '@/react/common/Pagination'; | ||
import ResultWrapper from '@/react/common/ResultWrapper'; | ||
import useScrollToResults from '@/react/common/hooks/useScrollToResults'; | ||
import ResultsError from '@/react/common/ResultsError'; | ||
import Global from '../enum/Global'; | ||
import URLParams from '../types/URLParams'; | ||
import { configurationsAtom, pageAtom, setPageAtom, urlAtom } from '../store'; | ||
import useIndexQuery from '../hooks/useIndexQuery'; | ||
import useResultsQuery from '../hooks/useResultsQuery'; | ||
import ResultsSort from '../components/results/ResultsSort'; | ||
import ResultsList from '../components/results/ResultsList'; | ||
import ResultsHeader from '@/react/common/ResultsHeader'; | ||
import ResultsEmpty from '@/react/common/ResultsEmpty'; | ||
import SearchMonitorContainer from './SearchMonitorContainer'; | ||
|
||
const ResultsContainer = () => { | ||
const { promoted } = useAtomValue(configurationsAtom); | ||
|
||
return promoted?.length ? | ||
<PromotedResultsContainer /> : | ||
<> | ||
{drupalSettings?.helfi_react_search?.hakuvahti_url_set && <SearchMonitorContainer />} | ||
<SimpleResultsContainer /> | ||
</>; | ||
const { size } = Global; | ||
const urlParams: URLParams = useAtomValue(urlAtom); | ||
const currentPage = useAtomValue(pageAtom); | ||
const setPage = useSetAtom(setPageAtom); | ||
const { error: initializationError } = useAtomValue(configurationsAtom); | ||
const scrollTarget = createRef<HTMLDivElement>(); | ||
const { query, promoted, handleResults } = useResultsQuery(urlParams); | ||
|
||
// Scroll to results when they change. | ||
const choices = Boolean(Object.keys(urlParams).length); | ||
useScrollToResults(scrollTarget, choices); | ||
|
||
const { data, error, isLoading, isValidating } = useIndexQuery({ | ||
keepPreviousData: true, | ||
query, | ||
multi: promoted | ||
}); | ||
|
||
const updatePage = (e: SyntheticEvent<HTMLButtonElement>, index: number) => { | ||
e.preventDefault(); | ||
setPage(index.toString()); | ||
}; | ||
|
||
const getResults = () => { | ||
if (!data && !error) { | ||
return; | ||
} | ||
|
||
if (error || initializationError || data.error) { | ||
return ( | ||
<ResultsError | ||
error={error || initializationError || data.error} | ||
className='react-search__results' | ||
ref={scrollTarget} | ||
/> | ||
); | ||
} | ||
|
||
const { results, jobs, total } = handleResults(data); | ||
|
||
if (total <= 0) { | ||
return <ResultsEmpty wrapperClass='hdbt-search--react__results--container' ref={scrollTarget} />; | ||
} | ||
|
||
const pages = Math.ceil(total / size); | ||
|
||
return ( | ||
<> | ||
<ResultsHeader | ||
resultText={ | ||
<> | ||
{ Drupal.formatPlural(jobs, '1 open position', '@count open positions',{},{ context: 'Job search results statline' }) } | ||
</> | ||
} | ||
optionalResultsText={ | ||
<> | ||
{ Drupal.formatPlural(total, '1 job listing', '@count job listings',{},{context: 'Job search results statline'}) } | ||
</> | ||
} | ||
actions={<ResultsSort />} | ||
actionsClass="hdbt-search--react__results--sort" | ||
ref={scrollTarget} | ||
/> | ||
<ResultsList hits={results} /> | ||
<Pagination | ||
currentPage={currentPage} | ||
pages={5} | ||
totalPages={pages} | ||
updatePage={updatePage} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
{drupalSettings?.helfi_react_search?.hakuvahti_url_set && <SearchMonitorContainer />} | ||
<div className='job-search__results'> | ||
<ResultWrapper loading={isLoading || isValidating}> | ||
{getResults()} | ||
</ResultWrapper> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default ResultsContainer; |
106 changes: 0 additions & 106 deletions
106
src/js/react/apps/job-search/containers/SimpleResultsContainer.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.