Skip to content

Commit

Permalink
Periodically refresh the neighbourhood of matches (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis authored Nov 20, 2023
1 parent 8b15ad6 commit 2d7ec5d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions components/quiz-card-stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,13 @@ const prospectState = (
};
};

const fetchNBestProspects = async (n: number): Promise<ProspectState[]> => {
const response = n === 1 ?
await japi('get', '/search') :
await japi('get', `/search?n=${n}&o=0`);
const fetchNBestProspects = async (
n: number,
refreshNeighborhood: boolean,
): Promise<ProspectState[]> => {
const response = refreshNeighborhood || n > 1 ?
await japi('get', `/search?n=${n}&o=0`) :
await japi('get', '/search');

if (!response.ok) {
return [];
Expand Down Expand Up @@ -284,7 +287,14 @@ const addNextProspectsInPlace = async (
) => {
const prospects = state.prospects;

prospects.push(...await fetchNBestProspects(n));
const topCardQuestionNumber = state.cards[
state.topCardIndex
]?.questionNumber ?? -1;

prospects.push(...await fetchNBestProspects(
n,
[4, 8, 16, 32, 64].includes(topCardQuestionNumber)
));

callback && callback();
};
Expand Down

0 comments on commit 2d7ec5d

Please sign in to comment.