Skip to content

Commit

Permalink
Merge pull request #2324 from Plant-for-the-Planet-org/hotfix/transla…
Browse files Browse the repository at this point in the history
…tion_issue_search_result

feat: add `locale` as a dependency for `getSearchProjects` useCallback
  • Loading branch information
mohitb35 authored Dec 10, 2024
2 parents e958cad + 91eeeba commit 0110f3d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/features/projectsV2/ProjectsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const ProjectsProvider: FC<ProjectsProviderProps> = ({
>([]);
const [debouncedSearchValue, setDebouncedSearchValue] = useState('');
const [isSearching, setIsSearching] = useState(false);
const [projectsLocale, setProjectsLocale] = useState('');
const { setErrors } = useContext(ErrorHandlingContext);
const { tenantConfig } = useTenant();
const locale = useLocale();
Expand Down Expand Up @@ -171,7 +172,7 @@ export const ProjectsProvider: FC<ProjectsProviderProps> = ({
});
return filteredProjects;
},
[]
[locale]
);

const filteredProjects = useMemo(() => {
Expand All @@ -188,15 +189,11 @@ export const ProjectsProvider: FC<ProjectsProviderProps> = ({

useEffect(() => {
async function loadProjects() {
if (page !== 'project-list' || !currencyCode) {
return;
}
if (projects !== null) {
return;
}
if (page !== 'project-list' || !currencyCode) return;
if (projectsLocale === locale && projects !== null) return;

setIsLoading(true);
setIsError(false);

try {
const fetchedProjects = await getRequest<MapProject[]>(
tenantConfig.id,
Expand All @@ -210,6 +207,7 @@ export const ProjectsProvider: FC<ProjectsProviderProps> = ({
}
);
setProjects(fetchedProjects);
setProjectsLocale(locale);
} catch (err) {
setErrors(handleError(err as APIError));
setIsError(true);
Expand Down

0 comments on commit 0110f3d

Please sign in to comment.