Prevent request to endpoint if not member

This commit is contained in:
Chewbacca 2023-04-18 16:51:55 -04:00
parent e88be5fada
commit fcf6d258ef

View file

@ -21,6 +21,9 @@ const GroupMediaPanel: React.FC<IGroupMediaPanel> = ({ group }) => {
const [loading, setLoading] = useState(true);
const isMember = !!group?.relationship?.member;
const isPrivate = group?.locked;
const attachments: ImmutableList<Attachment> = useAppSelector((state) => group ? getGroupGallery(state, group?.id) : ImmutableList());
const handleOpenMedia = (attachment: Attachment): void => {
@ -37,13 +40,13 @@ const GroupMediaPanel: React.FC<IGroupMediaPanel> = ({ group }) => {
useEffect(() => {
setLoading(true);
if (group) {
if (group && (isMember || !isPrivate)) {
dispatch(expandGroupMediaTimeline(group.id))
// @ts-ignore
.then(() => setLoading(false))
.catch(() => {});
}
}, [group?.id]);
}, [group?.id, isMember, isPrivate]);
const renderAttachments = () => {
const nineAttachments = attachments.slice(0, 9);
@ -69,6 +72,10 @@ const GroupMediaPanel: React.FC<IGroupMediaPanel> = ({ group }) => {
}
};
if (isPrivate && !isMember) {
return null;
}
return (
<Widget title={<FormattedMessage id='media_panel.title' defaultMessage='Media' />}>
{group && (