pl-fe: remove group normalizer
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import { importEntities as importEntityStoreEntities } from 'pl-fe/entity-store/actions';
|
||||
import { Entities } from 'pl-fe/entity-store/entities';
|
||||
import { normalizeGroup } from 'pl-fe/normalizers/group';
|
||||
import { queryClient } from 'pl-fe/queries/client';
|
||||
import { selectAccount } from 'pl-fe/selectors';
|
||||
|
||||
@ -114,7 +113,7 @@ const importEntities = (entities: {
|
||||
}
|
||||
|
||||
if (!isEmpty(accounts)) dispatch(importEntityStoreEntities(Object.values(accounts), Entities.ACCOUNTS));
|
||||
if (!isEmpty(groups)) dispatch(importEntityStoreEntities(Object.values(groups).map(normalizeGroup), Entities.GROUPS));
|
||||
if (!isEmpty(groups)) dispatch(importEntityStoreEntities(Object.values(groups), Entities.GROUPS));
|
||||
if (!isEmpty(polls)) {
|
||||
for (const poll of Object.values(polls)) {
|
||||
queryClient.setQueryData<BasePoll>(['statuses', 'polls', poll.id], poll);
|
||||
|
||||
@ -1,17 +1,15 @@
|
||||
import { Entities } from 'pl-fe/entity-store/entities';
|
||||
import { useCreateEntity } from 'pl-fe/entity-store/hooks/use-create-entity';
|
||||
import { useClient } from 'pl-fe/hooks/use-client';
|
||||
import { normalizeGroup, type Group } from 'pl-fe/normalizers/group';
|
||||
|
||||
import type { Group as BaseGroup, CreateGroupParams } from 'pl-api';
|
||||
import type { Group, CreateGroupParams } from 'pl-api';
|
||||
|
||||
const useCreateGroup = () => {
|
||||
const client = useClient();
|
||||
|
||||
const { createEntity, ...rest } = useCreateEntity<BaseGroup, Group, CreateGroupParams>(
|
||||
const { createEntity, ...rest } = useCreateEntity<Group, Group, CreateGroupParams>(
|
||||
[Entities.GROUPS, 'search', ''],
|
||||
(params: CreateGroupParams) => client.experimental.groups.createGroup(params),
|
||||
{ transform: normalizeGroup },
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@ -4,21 +4,19 @@ import { useHistory } from 'react-router-dom';
|
||||
import { Entities } from 'pl-fe/entity-store/entities';
|
||||
import { useEntity } from 'pl-fe/entity-store/hooks/use-entity';
|
||||
import { useClient } from 'pl-fe/hooks/use-client';
|
||||
import { normalizeGroup, type Group } from 'pl-fe/normalizers/group';
|
||||
|
||||
import { useGroupRelationship } from './use-group-relationship';
|
||||
|
||||
import type { Group as BaseGroup } from 'pl-api';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
const useGroup = (groupId: string, refetch = true) => {
|
||||
const client = useClient();
|
||||
const history = useHistory();
|
||||
|
||||
const { entity: group, isUnauthorized, ...result } = useEntity<BaseGroup, Group>(
|
||||
const { entity: group, isUnauthorized, ...result } = useEntity<Group, Group>(
|
||||
[Entities.GROUPS, groupId],
|
||||
() => client.experimental.groups.getGroup(groupId),
|
||||
{
|
||||
transform: normalizeGroup,
|
||||
refetch,
|
||||
enabled: !!groupId,
|
||||
},
|
||||
|
||||
@ -2,20 +2,19 @@ import { Entities } from 'pl-fe/entity-store/entities';
|
||||
import { useEntities } from 'pl-fe/entity-store/hooks/use-entities';
|
||||
import { useClient } from 'pl-fe/hooks/use-client';
|
||||
import { useFeatures } from 'pl-fe/hooks/use-features';
|
||||
import { normalizeGroup, type Group } from 'pl-fe/normalizers/group';
|
||||
|
||||
import { useGroupRelationships } from './use-group-relationships';
|
||||
|
||||
import type { Group as BaseGroup } from 'pl-api';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
const useGroups = () => {
|
||||
const client = useClient();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<BaseGroup, Group>(
|
||||
const { entities, ...result } = useEntities<Group, Group>(
|
||||
[Entities.GROUPS, 'search', ''],
|
||||
() => client.experimental.groups.getGroups(),
|
||||
{ enabled: features.groups, transform: normalizeGroup },
|
||||
{ enabled: features.groups },
|
||||
);
|
||||
const { relationships } = useGroupRelationships(
|
||||
['search', ''],
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { Entities } from 'pl-fe/entity-store/entities';
|
||||
import { useCreateEntity } from 'pl-fe/entity-store/hooks/use-create-entity';
|
||||
import { useClient } from 'pl-fe/hooks/use-client';
|
||||
import { normalizeGroup } from 'pl-fe/normalizers/group';
|
||||
|
||||
interface UpdateGroupParams {
|
||||
display_name?: string;
|
||||
@ -18,7 +17,6 @@ const useUpdateGroup = (groupId: string) => {
|
||||
const { createEntity, ...rest } = useCreateEntity(
|
||||
[Entities.GROUPS],
|
||||
(params: UpdateGroupParams) => client.experimental.groups.updateGroup(groupId, params),
|
||||
{ transform: normalizeGroup },
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@ -11,10 +11,10 @@ import GroupRelationship from 'pl-fe/features/group/components/group-relationshi
|
||||
|
||||
import GroupAvatar from './groups/group-avatar';
|
||||
|
||||
import type { Group as GroupEntity } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
interface IGroupCard {
|
||||
group: GroupEntity;
|
||||
group: Group;
|
||||
}
|
||||
|
||||
const GroupCard: React.FC<IGroupCard> = ({ group }) => (
|
||||
|
||||
@ -14,7 +14,7 @@ import GroupPrivacy from 'pl-fe/features/group/components/group-privacy';
|
||||
|
||||
import GroupAvatar from '../group-avatar';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
interface IGroupPopoverContainer {
|
||||
children: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { type CustomEmoji, GroupRoles } from 'pl-api';
|
||||
import { type CustomEmoji, GroupRoles, Group } from 'pl-api';
|
||||
import React, { useCallback, useMemo } from 'react';
|
||||
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||
import { useHistory, useRouteMatch } from 'react-router-dom';
|
||||
@ -42,7 +42,6 @@ import type { Menu } from 'pl-fe/components/dropdown-menu';
|
||||
import type { Emoji as EmojiType } from 'pl-fe/features/emoji';
|
||||
import type { UnauthorizedModalAction } from 'pl-fe/modals/unauthorized-modal';
|
||||
import type { Account } from 'pl-fe/normalizers/account';
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { SelectedStatus } from 'pl-fe/selectors';
|
||||
import type { Me } from 'pl-fe/types/pl-fe';
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@ interface IAvatar extends Pick<IStillImage, 'alt' | 'src' | 'staticSrc' | 'onErr
|
||||
isCat?: boolean;
|
||||
username?: string;
|
||||
showAlt?: boolean;
|
||||
isDefault?: boolean;
|
||||
}
|
||||
|
||||
const fac = new FastAverageColor();
|
||||
@ -39,7 +40,7 @@ const Avatar = (props: IAvatar) => {
|
||||
const intl = useIntl();
|
||||
const { disableUserProvidedMedia } = useSettings();
|
||||
|
||||
const { alt, src, size = AVATAR_SIZE, className, isCat } = props;
|
||||
const { alt, src, size = AVATAR_SIZE, className, isCat, isDefault } = props;
|
||||
|
||||
const [color, setColor] = useState<string | undefined>(undefined);
|
||||
const [isAvatarMissing, setIsAvatarMissing] = useState(false);
|
||||
@ -73,7 +74,7 @@ const Avatar = (props: IAvatar) => {
|
||||
}, [size, color]);
|
||||
|
||||
if (disableUserProvidedMedia) {
|
||||
if (isAvatarMissing || !alt || isDefaultAvatar(src)) return null;
|
||||
if (isAvatarMissing || !alt || isDefault) return null;
|
||||
return (
|
||||
<Popover
|
||||
interaction='hover'
|
||||
@ -122,7 +123,7 @@ const Avatar = (props: IAvatar) => {
|
||||
className={clsx('rounded-lg leading-[0]', isCat && 'avatar__cat bg-gray-200 dark:bg-gray-900', className)}
|
||||
innerClassName='rounded-[inherit] text-sm'
|
||||
style={style}
|
||||
src={src}
|
||||
src={src || require('pl-fe/assets/images/avatar-missing.png')}
|
||||
alt={altText}
|
||||
onError={handleLoadFailure}
|
||||
/>
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import type { GroupMember, GroupRelationship } from 'pl-api';
|
||||
import type { GroupMember, GroupRelationship, Group } from 'pl-api';
|
||||
import type { Account } from 'pl-fe/normalizers/account';
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
|
||||
enum Entities {
|
||||
ACCOUNTS = 'Accounts',
|
||||
|
||||
@ -6,7 +6,7 @@ import { render, screen } from 'pl-fe/jest/test-helpers';
|
||||
|
||||
import GroupActionButton from './group-action-button';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
let group: Group;
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import { defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import Icon from 'pl-fe/components/ui/icon';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
const messages = defineMessages({
|
||||
header: { id: 'group.header.alt', defaultMessage: 'Group header' },
|
||||
|
||||
@ -5,7 +5,7 @@ import { render, screen } from 'pl-fe/jest/test-helpers';
|
||||
|
||||
import GroupHeader from './group-header';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
let group: Group;
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ import GroupOptionsButton from './group-options-button';
|
||||
import GroupPrivacy from './group-privacy';
|
||||
import GroupRelationship from './group-relationship';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
const messages = defineMessages({
|
||||
header: { id: 'group.header.alt', defaultMessage: 'Group header' },
|
||||
|
||||
@ -5,7 +5,7 @@ import { render, screen } from 'pl-fe/jest/test-helpers';
|
||||
|
||||
import GroupMemberCount from './group-member-count';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
let group: Group;
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ import { Link } from 'react-router-dom';
|
||||
import Text from 'pl-fe/components/ui/text';
|
||||
import { shortNumberFormat } from 'pl-fe/utils/numbers';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
interface IGroupMemberCount {
|
||||
group: Pick<Group, 'id' | 'members_count'>;
|
||||
|
||||
@ -18,8 +18,8 @@ import { useKickGroupMemberMutation, type MinifiedGroupMember } from 'pl-fe/quer
|
||||
import { useModalsActions } from 'pl-fe/stores/modals';
|
||||
import toast from 'pl-fe/toast';
|
||||
|
||||
import type { Group } from 'pl-api';
|
||||
import type { Menu as IMenu } from 'pl-fe/components/dropdown-menu';
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
|
||||
const messages = defineMessages({
|
||||
adminLimitTitle: { id: 'group.member.admin.limit.title', defaultMessage: 'Admin limit reached' },
|
||||
|
||||
@ -6,7 +6,7 @@ import { render, screen } from 'pl-fe/jest/test-helpers';
|
||||
|
||||
import GroupOptionsButton from './group-options-button';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
let group: Group;
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ import { render, screen } from 'pl-fe/jest/test-helpers';
|
||||
|
||||
import GroupPrivacy from './group-privacy';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
let group: Group;
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import Popover from 'pl-fe/components/ui/popover';
|
||||
import Stack from 'pl-fe/components/ui/stack';
|
||||
import Text from 'pl-fe/components/ui/text';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
interface IGroupPolicy {
|
||||
group: Pick<Group, 'locked'>;
|
||||
|
||||
@ -6,7 +6,7 @@ import { render, screen } from 'pl-fe/jest/test-helpers';
|
||||
|
||||
import GroupRelationship from './group-relationship';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
let group: Group;
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ import Emojify from 'pl-fe/features/emoji/emojify';
|
||||
import GroupActionButton from 'pl-fe/features/group/components/group-action-button';
|
||||
import { shortNumberFormat } from 'pl-fe/utils/numbers';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
interface IGroupListItem {
|
||||
group: Pick<Group, 'id' | 'avatar' | 'avatar_description' | 'display_name' | 'emojis' | 'locked' | 'members_count' | 'relationship'>;
|
||||
|
||||
@ -8,7 +8,7 @@ import { type AccountGalleryAttachment, useGroupGallery } from 'pl-fe/hooks/use-
|
||||
import { MediaItem } from 'pl-fe/pages/accounts/account-gallery';
|
||||
import { useModalsActions } from 'pl-fe/stores/modals';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
interface IGroupMediaPanel {
|
||||
group: Group;
|
||||
|
||||
@ -10,10 +10,9 @@ import toast from 'pl-fe/toast';
|
||||
import ConfirmationStep from './steps/confirmation-step';
|
||||
import DetailsStep from './steps/details-step';
|
||||
|
||||
import type { CreateGroupParams } from 'pl-api';
|
||||
import type { CreateGroupParams, Group } from 'pl-api';
|
||||
import type { PlfeResponse } from 'pl-fe/api';
|
||||
import type { BaseModalProps } from 'pl-fe/features/ui/components/modal-root';
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
|
||||
const messages = defineMessages({
|
||||
create: { id: 'manage_group.create', defaultMessage: 'Create group' },
|
||||
|
||||
@ -11,7 +11,7 @@ import Text from 'pl-fe/components/ui/text';
|
||||
import toast from 'pl-fe/toast';
|
||||
import copy from 'pl-fe/utils/copy';
|
||||
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { Group } from 'pl-api';
|
||||
|
||||
interface IConfirmationStep {
|
||||
group: Group | null;
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
import type { Group as BaseGroup } from 'pl-api';
|
||||
|
||||
const normalizeGroup = (group: BaseGroup) => {
|
||||
const missingAvatar = require('pl-fe/assets/images/avatar-missing.png');
|
||||
const missingHeader = require('pl-fe/assets/images/header-missing.png');
|
||||
|
||||
return {
|
||||
...group,
|
||||
avatar: group.avatar || group.avatar_static || missingAvatar,
|
||||
header: group.header || group.header_static || missingHeader,
|
||||
};
|
||||
};
|
||||
|
||||
type Group = ReturnType<typeof normalizeGroup>;
|
||||
|
||||
export { normalizeGroup, type Group };
|
||||
@ -9,7 +9,6 @@ import * as v from 'valibot';
|
||||
import { unescapeHTML } from 'pl-fe/utils/html';
|
||||
|
||||
import { normalizeAccount } from './account';
|
||||
import { normalizeGroup } from './group';
|
||||
|
||||
const domParser = new DOMParser();
|
||||
|
||||
@ -106,7 +105,7 @@ const normalizeStatus = (status: BaseStatus & {
|
||||
}
|
||||
|
||||
// Normalize group
|
||||
const group = status.group ? normalizeGroup(status.group) : null;
|
||||
const group = status.group || null;
|
||||
|
||||
return {
|
||||
account_id: status.account.id,
|
||||
|
||||
@ -7,10 +7,9 @@ import { validId } from 'pl-fe/utils/auth';
|
||||
import ConfigDB from 'pl-fe/utils/config-db';
|
||||
import { shouldFilter } from 'pl-fe/utils/timelines';
|
||||
|
||||
import type { Filter, FilterResult, NotificationGroup } from 'pl-api';
|
||||
import type { Filter, FilterResult, NotificationGroup, Group } from 'pl-api';
|
||||
import type { EntityStore } from 'pl-fe/entity-store/types';
|
||||
import type { Account } from 'pl-fe/normalizers/account';
|
||||
import type { Group } from 'pl-fe/normalizers/group';
|
||||
import type { minifyAdminReport } from 'pl-fe/queries/utils/minify-list';
|
||||
import type { MinifiedStatus } from 'pl-fe/reducers/statuses';
|
||||
import type { MRFSimple } from 'pl-fe/schemas/pleroma';
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import range from 'lodash/range';
|
||||
|
||||
import type { Account } from 'pl-fe/normalizers/account';
|
||||
|
||||
const getDomainFromURL = (account: Pick<Account, 'url'>): string => {
|
||||
|
||||
Reference in New Issue
Block a user