pleroma/app/soapbox/components/hoc/group-lookup-hoc.tsx

62 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-04-17 11:56:31 -07:00
import React from 'react';
2023-05-01 11:58:40 -07:00
import { useGroupLookup } from 'soapbox/api/hooks';
2023-04-17 12:28:20 -07:00
import ColumnLoading from 'soapbox/features/ui/components/column-loading';
2023-04-17 11:56:31 -07:00
2023-04-17 12:45:16 -07:00
import { Layout } from '../ui';
2023-04-17 11:56:31 -07:00
interface IGroupLookup {
params: {
groupSlug: string
}
}
2023-04-17 12:28:20 -07:00
interface IMaybeGroupLookup {
params?: {
groupSlug?: string
groupId?: string
}
}
2023-04-17 11:56:31 -07:00
function GroupLookupHoc(Component: React.ComponentType<{ params: { groupId: string } }>) {
const GroupLookup: React.FC<IGroupLookup> = (props) => {
const { entity: group } = useGroupLookup(props.params.groupSlug);
2023-04-17 12:28:20 -07:00
2023-04-17 11:56:31 -07:00
if (!group) return (
2023-04-17 12:45:16 -07:00
<>
<Layout.Main>
<ColumnLoading />
</Layout.Main>
<Layout.Aside />
</>
2023-04-17 11:56:31 -07:00
);
const newProps = {
...props,
params: {
...props.params,
id: group.id,
groupId: group.id,
},
};
return (
<Component {...newProps} />
);
};
2023-04-17 12:28:20 -07:00
const MaybeGroupLookup: React.FC<IMaybeGroupLookup> = (props) => {
const { params } = props;
if (params?.groupId) {
return <Component {...props} params={{ ...params, groupId: params.groupId }} />;
} else {
return <GroupLookup {...props} params={{ ...params, groupSlug: params?.groupSlug || '' }} />;
}
};
return MaybeGroupLookup;
2023-04-17 11:56:31 -07:00
}
export default GroupLookupHoc;