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

fix: display folder thumbnails on shortcuts #670

Merged
merged 2 commits into from
May 2, 2024
Merged
Changes from all commits
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
72 changes: 23 additions & 49 deletions src/modules/item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
PermissionLevel,
S3FileItemType,
ShortcutItemType,
ThumbnailSize,
} from '@graasp/sdk';
import { DEFAULT_LANG, FAILURE_MESSAGES } from '@graasp/translations';
import {
Expand Down Expand Up @@ -294,62 +295,35 @@ const ShortcutContent = ({ item }: { item: ShortcutItemType }): JSX.Element => {
);
};

const FolderButtonContent = ({ item }: { item: FolderItemType }) => {
const { data: thumbnail } = hooks.useItemThumbnailUrl({
id: item.id,
size: ThumbnailSize.Medium,
});
return (
<FolderCard
id={buildFolderButtonId(item.id)}
name={item.name}
thumbnail={thumbnail}
description={
// to not display the default empty description we check it here
item.description && item.description !== '<p><br></p>' ? (
<TextDisplay content={item.description ?? ''} />
) : undefined
}
to={buildMainPath({ rootId: item.id })}
/>
);
};

type ItemContentProps = {
item: DiscriminatedItem;
};

const ItemContent = ({ item }: ItemContentProps) => {
switch (item.type) {
case ItemType.FOLDER: {
const folderButton = (
<FolderCard
id={buildFolderButtonId(item.id)}
name={item.name}
description={
<Box
sx={{
height: '1lh',
display: '-webkit-box',
overflow: 'hidden',
// number of lines to show
WebkitLineClamp: 1,
WebkitBoxOrient: 'vertical',
'& > p': {
margin: 0,
},
}}
>
<TextDisplay content={item.description ?? ''} />
</Box>
}
to={buildMainPath({ rootId: item.id })}
/>
);
return folderButton;

// todo: check that the folders are displayed as expected.
// in case everything is okay, remove the following

// // display children shortcut pinned folders
// if (isShortcut && isShortcutPinned) {
// return folderButton;
// }

// // do not display shortcut folders if they are not pinned
// if (isShortcut && !isShortcutPinned) {
// return null;
// }

// // // do not display children folders if they are not pinned
// // if (!item.settings?.isPinned) {
// // return null;
// // }

// // only display children folders if they are pinned
// if (item.settings?.isPinned) {
// return folderButton;
// }
// break;
return <FolderButtonContent item={item} />;
}
case ItemType.LINK: {
return <LinkContent item={item} />;
Expand Down