sforkowany z mirror/soapbox
Use EntityStore for Groups
rodzic
c492af7042
commit
4c6d13e4ef
|
@ -6,8 +6,7 @@ import { openModal } from 'soapbox/actions/modals';
|
||||||
import GroupCard from 'soapbox/components/group-card';
|
import GroupCard from 'soapbox/components/group-card';
|
||||||
import ScrollableList from 'soapbox/components/scrollable-list';
|
import ScrollableList from 'soapbox/components/scrollable-list';
|
||||||
import { Button, Stack, Text } from 'soapbox/components/ui';
|
import { Button, Stack, Text } from 'soapbox/components/ui';
|
||||||
import { useAppDispatch, useAppSelector, useFeatures } from 'soapbox/hooks';
|
import { useAppDispatch, useAppSelector, useGroups, useFeatures } from 'soapbox/hooks';
|
||||||
import { useGroups } from 'soapbox/queries/groups';
|
|
||||||
import { PERMISSION_CREATE_GROUPS, hasPermission } from 'soapbox/utils/permissions';
|
import { PERMISSION_CREATE_GROUPS, hasPermission } from 'soapbox/utils/permissions';
|
||||||
|
|
||||||
import PlaceholderGroupCard from '../placeholder/components/placeholder-group-card';
|
import PlaceholderGroupCard from '../placeholder/components/placeholder-group-card';
|
||||||
|
@ -16,16 +15,6 @@ import TabBar, { TabItems } from './components/tab-bar';
|
||||||
|
|
||||||
import type { Group as GroupEntity } from 'soapbox/types/entities';
|
import type { Group as GroupEntity } from 'soapbox/types/entities';
|
||||||
|
|
||||||
// const getOrderedGroups = createSelector([
|
|
||||||
// (state: RootState) => state.groups.items,
|
|
||||||
// (state: RootState) => state.group_relationships,
|
|
||||||
// ], (groups, group_relationships) => ({
|
|
||||||
// groups: (groups.toList().filter((item: GroupEntity | false) => !!item) as ImmutableList<GroupEntity>)
|
|
||||||
// .map((item) => item.set('relationship', group_relationships.get(item.id) || null))
|
|
||||||
// .filter((item) => item.relationship?.member)
|
|
||||||
// .sort((a, b) => a.display_name.localeCompare(b.display_name)),
|
|
||||||
// }));
|
|
||||||
|
|
||||||
const EmptyMessage = () => (
|
const EmptyMessage = () => (
|
||||||
<Stack space={6} alignItems='center' justifyContent='center' className='h-full p-6'>
|
<Stack space={6} alignItems='center' justifyContent='center' className='h-full p-6'>
|
||||||
<Stack space={2} className='max-w-sm'>
|
<Stack space={2} className='max-w-sm'>
|
||||||
|
|
|
@ -5,6 +5,8 @@ export { useAppSelector } from './useAppSelector';
|
||||||
export { useClickOutside } from './useClickOutside';
|
export { useClickOutside } from './useClickOutside';
|
||||||
export { useCompose } from './useCompose';
|
export { useCompose } from './useCompose';
|
||||||
export { useDebounce } from './useDebounce';
|
export { useDebounce } from './useDebounce';
|
||||||
|
export { useGroup } from './useGroup';
|
||||||
|
export { useGroups } from './useGroups';
|
||||||
export { useGroupsPath } from './useGroupsPath';
|
export { useGroupsPath } from './useGroupsPath';
|
||||||
export { useDimensions } from './useDimensions';
|
export { useDimensions } from './useDimensions';
|
||||||
export { useFeatures } from './useFeatures';
|
export { useFeatures } from './useFeatures';
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
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>(['Group', groupId], `/api/v1/groups/${groupId}`);
|
||||||
|
const { entity, isLoading, fetchEntity } = result;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isLoading) {
|
||||||
|
fetchEntity();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
group: entity ? normalizeGroup(entity) : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export { useGroup };
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
|
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||||
|
import { normalizeGroup } from 'soapbox/normalizers';
|
||||||
|
|
||||||
|
import type { Group } from 'soapbox/types/entities';
|
||||||
|
|
||||||
|
function useGroups() {
|
||||||
|
const result = useEntities<Group>(['Group', ''], '/api/v1/groups');
|
||||||
|
const { entities, isLoading, fetchEntities } = result;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isLoading) {
|
||||||
|
fetchEntities();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
groups: entities.map(normalizeGroup),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export { useGroups };
|
|
@ -11,8 +11,7 @@ import {
|
||||||
GroupMediaPanel,
|
GroupMediaPanel,
|
||||||
SignUpPanel,
|
SignUpPanel,
|
||||||
} from 'soapbox/features/ui/util/async-components';
|
} from 'soapbox/features/ui/util/async-components';
|
||||||
import { useOwnAccount } from 'soapbox/hooks';
|
import { useGroup, useOwnAccount } from 'soapbox/hooks';
|
||||||
import { useGroup } from 'soapbox/queries/groups';
|
|
||||||
|
|
||||||
import { Tabs } from '../components/ui';
|
import { Tabs } from '../components/ui';
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue