Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: trigger un/collapse action #829

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
"@emotion/styled": "11.13.0",
"@graasp/chatbox": "3.1.0",
"@graasp/query-client": "3.16.0",
"@graasp/sdk": "4.20.0",
"@graasp/sdk": "https://github.com/graasp/graasp-sdk.git#add-un/collapse-action-trigger",
"@graasp/translations": "1.32.0",
"@graasp/ui": "4.21.0",
"@graasp/ui": "https://github.com/graasp/graasp-ui.git#feat-add-oncollapse-handler",
"@mui/icons-material": "5.16.4",
"@mui/lab": "5.0.0-alpha.172",
"@mui/material": "5.16.4",
Expand Down
74 changes: 64 additions & 10 deletions src/modules/item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ const FileContent = ({ item }: FileContentProps) => {
} = useFileContentUrl(item.id);
const { mutate: triggerAction } = mutations.usePostItemAction();

const onCollapse = (c: boolean) => {
triggerAction({
itemId: item.id,
payload: {
type: c ? ActionTriggers.CollapseItem : ActionTriggers.UnCollapseItem,
},
});
};

const onDownloadClick = useCallback(() => {
triggerAction({
itemId: item.id,
Expand Down Expand Up @@ -168,6 +177,7 @@ const FileContent = ({ item }: FileContentProps) => {
showCollapse={item.settings?.isCollapsible}
pdfViewerLink={PDF_VIEWER_LINK}
onClick={onDownloadClick}
onCollapse={onCollapse}
/>
);
};
Expand All @@ -184,6 +194,15 @@ const LinkContent = ({ item }: { item: LinkItemType }): JSX.Element => {
});
};

const onCollapse = (c: boolean) => {
triggerAction({
itemId: item.id,
payload: {
type: c ? ActionTriggers.CollapseItem : ActionTriggers.UnCollapseItem,
},
});
};

return (
<Box id={buildLinkItemId(item.id)}>
<LinkItem
Expand All @@ -196,21 +215,35 @@ const LinkContent = ({ item }: { item: LinkItemType }): JSX.Element => {
showIframe={item.settings?.showLinkIframe}
showCollapse={item.settings?.isCollapsible}
onClick={handleLinkClick}
onCollapse={onCollapse}
/>
</Box>
);
};

const DocumentContent = ({ item }: { item: DocumentItemType }): JSX.Element => (
<DocumentItem
id={buildDocumentId(item.id)}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
showTitle={item.settings?.showTitle}
item={{ ...item, name: item.displayName }}
showCollapse={item.settings?.isCollapsible}
/>
);
const DocumentContent = ({ item }: { item: DocumentItemType }): JSX.Element => {
const { mutate: triggerAction } = mutations.usePostItemAction();

const onCollapse = (c: boolean) => {
triggerAction({
itemId: item.id,
payload: {
type: c ? ActionTriggers.CollapseItem : ActionTriggers.UnCollapseItem,
},
});
};
return (
<DocumentItem
id={buildDocumentId(item.id)}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
showTitle={item.settings?.showTitle}
item={{ ...item, name: item.displayName }}
showCollapse={item.settings?.isCollapsible}
onCollapse={onCollapse}
/>
);
};

const AppContent = ({ item }: { item: AppItemType }): JSX.Element => {
const {
Expand All @@ -219,7 +252,16 @@ const AppContent = ({ item }: { item: AppItemType }): JSX.Element => {
isSuccess: isSuccessMember,
} = useCurrentMemberContext();
const { t: translateMessage } = useMessagesTranslation();
const { mutate: triggerAction } = mutations.usePostItemAction();

const onCollapse = (c: boolean) => {
triggerAction({
itemId: item.id,
payload: {
type: c ? ActionTriggers.CollapseItem : ActionTriggers.UnCollapseItem,
},
});
};
if (member || isSuccessMember)
return (
<AppItem
Expand All @@ -240,6 +282,7 @@ const AppContent = ({ item }: { item: AppItemType }): JSX.Element => {
itemId: item.id,
}}
showCollapse={item.settings?.isCollapsible}
onCollapse={onCollapse}
/>
);

Expand All @@ -258,6 +301,8 @@ const AppContent = ({ item }: { item: AppItemType }): JSX.Element => {

const H5PContent = ({ item }: { item: H5PItemType }): JSX.Element => {
const { t: translateMessage } = useMessagesTranslation();
const { mutate: triggerAction } = mutations.usePostItemAction();

const contentId = item?.extra?.h5p?.contentId;
if (!contentId) {
return (
Expand All @@ -266,6 +311,14 @@ const H5PContent = ({ item }: { item: H5PItemType }): JSX.Element => {
</Alert>
);
}
const onCollapse = (c: boolean) => {
triggerAction({
itemId: item.id,
payload: {
type: c ? ActionTriggers.CollapseItem : ActionTriggers.UnCollapseItem,
},
});
};

return (
<H5PItem
Expand All @@ -274,6 +327,7 @@ const H5PContent = ({ item }: { item: H5PItemType }): JSX.Element => {
contentId={contentId}
integrationUrl={H5P_INTEGRATION_URL}
showCollapse={item.settings?.isCollapsible}
onCollapse={onCollapse}
/>
);
};
Expand Down
Loading