diff --git a/app/soapbox/hooks/index.ts b/app/soapbox/hooks/index.ts index dceae2cdfc..1b0545e836 100644 --- a/app/soapbox/hooks/index.ts +++ b/app/soapbox/hooks/index.ts @@ -5,8 +5,7 @@ export { useAppSelector } from './useAppSelector'; export { useClickOutside } from './useClickOutside'; export { useCompose } from './useCompose'; export { useDebounce } from './useDebounce'; -export { useGroup } from './useGroup'; -export { useGroups } from './useGroups'; +export { useGroup, useGroups } from './useGroups'; export { useGroupsPath } from './useGroupsPath'; export { useDimensions } from './useDimensions'; export { useFeatures } from './useFeatures'; diff --git a/app/soapbox/hooks/useGroup.ts b/app/soapbox/hooks/useGroup.ts deleted file mode 100644 index 7a2be86960..0000000000 --- a/app/soapbox/hooks/useGroup.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { useEffect } from 'react'; - -import { useEntity } from 'soapbox/entity-store/hooks'; -import { normalizeGroup } from 'soapbox/normalizers'; - -import type { Group } from 'soapbox/types/entities'; - -function useGroup(groupId: string) { - const result = useEntity(['Group', groupId], `/api/v1/groups/${groupId}`); - const { entity, isLoading, fetchEntity } = result; - - useEffect(() => { - if (!isLoading) { - fetchEntity(); - } - }, []); - - return { - ...result, - group: entity ? normalizeGroup(entity) : undefined, - }; -} - -export { useGroup }; \ No newline at end of file diff --git a/app/soapbox/hooks/useGroups.ts b/app/soapbox/hooks/useGroups.ts index eca2b663ba..3d12e1be82 100644 --- a/app/soapbox/hooks/useGroups.ts +++ b/app/soapbox/hooks/useGroups.ts @@ -1,6 +1,6 @@ import { useEffect } from 'react'; -import { useEntities } from 'soapbox/entity-store/hooks'; +import { useEntities, useEntity } from 'soapbox/entity-store/hooks'; import { normalizeGroup } from 'soapbox/normalizers'; import type { Group } from 'soapbox/types/entities'; @@ -9,6 +9,8 @@ function useGroups() { const result = useEntities(['Group', ''], '/api/v1/groups'); const { entities, isLoading, fetchEntities } = result; + // Note: we have to fetch them in the hook right now because I haven't implemented + // max-age or cache expiry in the entity store yet. It's planned. useEffect(() => { if (!isLoading) { fetchEntities(); @@ -21,4 +23,20 @@ function useGroups() { }; } -export { useGroups }; \ No newline at end of file +function useGroup(groupId: string) { + const result = useEntity(['Group', groupId], `/api/v1/groups/${groupId}`); + const { entity, isLoading, fetchEntity } = result; + + useEffect(() => { + if (!isLoading) { + fetchEntity(); + } + }, []); + + return { + ...result, + group: entity ? normalizeGroup(entity) : undefined, + }; +} + +export { useGroup, useGroups }; \ No newline at end of file