Merge branch 'fix-useless-call' into 'develop'
Prevent lookup if not enabled See merge request soapbox-pub/soapbox!2539
This commit is contained in:
commit
8fa9854016
2 changed files with 5 additions and 2 deletions
|
@ -12,7 +12,7 @@ function useGroupLookup(slug: string) {
|
||||||
Entities.GROUPS,
|
Entities.GROUPS,
|
||||||
(group) => group.slug === slug,
|
(group) => group.slug === slug,
|
||||||
() => api.get(`/api/v1/groups/lookup?name=${slug}`),
|
() => api.get(`/api/v1/groups/lookup?name=${slug}`),
|
||||||
{ schema: groupSchema },
|
{ schema: groupSchema, enabled: !!slug },
|
||||||
);
|
);
|
||||||
|
|
||||||
const { entity: relationship } = useGroupRelationship(group?.id);
|
const { entity: relationship } = useGroupRelationship(group?.id);
|
||||||
|
|
|
@ -25,6 +25,7 @@ function useEntityLookup<TEntity extends Entity>(
|
||||||
const [isFetching, setPromise] = useLoading(true);
|
const [isFetching, setPromise] = useLoading(true);
|
||||||
|
|
||||||
const entity = useAppSelector(state => findEntity(state, entityType, lookupFn));
|
const entity = useAppSelector(state => findEntity(state, entityType, lookupFn));
|
||||||
|
const isEnabled = opts.enabled ?? true;
|
||||||
const isLoading = isFetching && !entity;
|
const isLoading = isFetching && !entity;
|
||||||
|
|
||||||
const fetchEntity = async () => {
|
const fetchEntity = async () => {
|
||||||
|
@ -38,10 +39,12 @@ function useEntityLookup<TEntity extends Entity>(
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!isEnabled) return;
|
||||||
|
|
||||||
if (!entity || opts.refetch) {
|
if (!entity || opts.refetch) {
|
||||||
fetchEntity();
|
fetchEntity();
|
||||||
}
|
}
|
||||||
}, []);
|
}, [isEnabled]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
entity,
|
entity,
|
||||||
|
|
Loading…
Reference in a new issue