Skip to content

Commit

Permalink
Merge branch 'master' into repo_checks/ensure_workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ormsbee authored Feb 28, 2023
2 parents 76995e6 + 9a579da commit a9281e2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/components/skills-quiz/SearchJobCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import JobCardComponent from './JobCardComponent';

const SearchJobCard = ({ index }) => {
const { refinements } = useContext(SearchContext);
const { name: jobs } = refinements;
const { name: jobs, current_job: currentJob } = refinements;
const [isLoading, setIsLoading] = useState(true);
const { dispatch, state } = useContext(SkillsContext);
const { interestedJobs } = state;
Expand All @@ -20,6 +20,13 @@ const SearchJobCard = ({ index }) => {
}
return jobsArray;
}, [jobs]);
const jobToFetch = useMemo(() => {
const jobArray = [];
if (currentJob?.length > 0) {
jobArray.push(`name:${currentJob[0]}`);
}
return jobArray;
}, [currentJob]);

useEffect(
() => {
Expand All @@ -42,6 +49,22 @@ const SearchJobCard = ({ index }) => {
},
[dispatch, index, jobs, jobsToFetch],
);
useEffect(() => {
let fetch = true;
if (currentJob) {
fetchJob(); // eslint-disable-line no-use-before-define
}
return () => { fetch = false; };
async function fetchJob() {
const { hits } = await index.search('', {
facetFilters: [
jobToFetch,
],
});
if (!fetch) { return; }
dispatch({ type: SET_KEY_VALUE, key: 'currentJobRole', value: hits });
}
}, [dispatch, index, currentJob, jobToFetch]);

return <JobCardComponent jobs={interestedJobs} isLoading={isLoading} />;
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/skills-quiz/tests/SearchJobCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const testIndex = {
};

const initialSearchState = {
refinements: { name: [] },
refinements: { name: [], current_job: ['test-current-job'] },
dispatch: () => null,
};

Expand Down

0 comments on commit a9281e2

Please sign in to comment.