Merge branch 'fix-useless-call' into 'develop'

Prevent lookup if not enabled

See merge request soapbox-pub/soapbox!2539
environments/review-develop-3zknud/deployments/3442
Chewbacca 2023-06-02 14:56:56 +00:00
commit 8fa9854016
2 zmienionych plików z 5 dodań i 2 usunięć

Wyświetl plik

@ -12,7 +12,7 @@ function useGroupLookup(slug: string) {
Entities.GROUPS,
(group) => group.slug === slug,
() => api.get(`/api/v1/groups/lookup?name=${slug}`),
{ schema: groupSchema },
{ schema: groupSchema, enabled: !!slug },
);
const { entity: relationship } = useGroupRelationship(group?.id);

Wyświetl plik

@ -25,6 +25,7 @@ function useEntityLookup<TEntity extends Entity>(
const [isFetching, setPromise] = useLoading(true);
const entity = useAppSelector(state => findEntity(state, entityType, lookupFn));
const isEnabled = opts.enabled ?? true;
const isLoading = isFetching && !entity;
const fetchEntity = async () => {
@ -38,10 +39,12 @@ function useEntityLookup<TEntity extends Entity>(
};
useEffect(() => {
if (!isEnabled) return;
if (!entity || opts.refetch) {
fetchEntity();
}
}, []);
}, [isEnabled]);
return {
entity,