Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

fix: no display for loading state in bookmarks, published and recycled #1369

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions src/components/layout/LoadingScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Skeleton, Stack } from '@mui/material';

type LoadingScreenProps = {
chipsPlaceholder?: boolean;
};
const LoadingScreen = ({
chipsPlaceholder = false,
}: LoadingScreenProps): JSX.Element => (
<Stack gap={1}>
{chipsPlaceholder && <Skeleton variant="rounded" height={40} width={180} />}
<Stack direction="row" justifyContent="space-between">
<Skeleton variant="rounded" height={40} width={200} />
<Stack direction="row" gap={1}>
<Skeleton variant="rounded" height={40} width={200} />
<Skeleton variant="rounded" height={40} width={40} />
<Skeleton variant="rounded" height={40} width={40} />
</Stack>
</Stack>
<Stack gap={1}>
<Skeleton variant="rounded" height={60} />
<Skeleton variant="rounded" height={60} />
<Skeleton variant="rounded" height={60} />
<Skeleton variant="rounded" height={60} />
<Skeleton variant="rounded" height={60} />
<Skeleton variant="rounded" height={60} />
</Stack>
</Stack>
);

export default LoadingScreen;
154 changes: 73 additions & 81 deletions src/components/pages/BookmarkedItemsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Alert, Box, Stack } from '@mui/material';

import { Loader } from '@graasp/ui';
import { Alert, Stack } from '@mui/material';

import { Ordering } from '@/enums';

Expand All @@ -16,21 +14,25 @@ import SelectTypes from '../common/SelectTypes';
import { useFilterItemsContext } from '../context/FilterItemsContext';
import { useItemSearch } from '../item/ItemSearch';
import ModeButton from '../item/header/ModeButton';
import LoadingScreen from '../layout/LoadingScreen';
import ItemsTable from '../main/ItemsTable';
import SortingSelect from '../table/SortingSelect';
import { SortingOptions } from '../table/types';
import { useSorting, useTranslatedSortingOptions } from '../table/useSorting';
import PageWrapper from './PageWrapper';

const BookmarkedItems = (): JSX.Element | null => {
const BookmarkedItems = ({
searchText,
}: {
searchText: string;
}): JSX.Element | null => {
const { t: translateBuilder } = useBuilderTranslation();
const {
data,
isLoading: isItemsLoading,
data: bookmarkedItems,
isLoading,
isError,
} = hooks.useBookmarkedItems();
const { shouldDisplayItem } = useFilterItemsContext();
const { input, text } = useItemSearch();

const { sortBy, setSortBy, ordering, setOrdering, sortFn } =
useSorting<SortingOptions>({
Expand All @@ -39,93 +41,83 @@ const BookmarkedItems = (): JSX.Element | null => {
});
const options = useTranslatedSortingOptions();

const filteredData = data
const filteredData = bookmarkedItems
?.map((d) => d.item)
?.filter(
(item) => shouldDisplayItem(item.type) && item.name.includes(text),
(item) =>
shouldDisplayItem(item.type) &&
item.name.toLowerCase().includes(searchText.toLowerCase()),
);

filteredData?.sort(sortFn);

const renderContent = () => {
if (isError) {
return (
<Box mt={2}>
<ErrorAlert id={BOOKMARKED_ITEMS_ERROR_ALERT_ID} />
</Box>
);
}

if (!data?.length) {
return (
<Alert severity="info">
{translateBuilder(BUILDER.BOOKMARKS_NO_ITEM)}
</Alert>
);
}

if (filteredData) {
return (
<Stack gap={1}>
if (bookmarkedItems?.length) {
return (
<Stack gap={1}>
<Stack
alignItems="space-between"
direction="column"
gap={1}
width="100%"
>
<Stack
alignItems="space-between"
direction="column"
mt={2}
gap={1}
width="100%"
spacing={1}
direction="row"
justifyContent="space-between"
alignItems="center"
>
<Stack
spacing={1}
direction="row"
justifyContent="space-between"
alignItems="center"
>
<SelectTypes />
<Stack direction="row" gap={1}>
{sortBy && setSortBy && (
<SortingSelect
options={options}
sortBy={sortBy}
setSortBy={setSortBy}
ordering={ordering}
setOrdering={setOrdering}
/>
)}
<ModeButton />
</Stack>
<SelectTypes />
<Stack direction="row" gap={1}>
{sortBy && setSortBy && (
<SortingSelect
options={options}
sortBy={sortBy}
setSortBy={setSortBy}
ordering={ordering}
setOrdering={setOrdering}
/>
)}
<ModeButton />
</Stack>
</Stack>
{filteredData.length ? (
<ItemsTable
items={filteredData}
canMove={false}
enableMoveInBetween={false}
/>
) : (
<Alert severity="info">
{translateBuilder(BUILDER.BOOKMARKS_NO_ITEM_SEARCH, {
search: text,
})}
</Alert>
)}
</Stack>
);
}
{filteredData?.length ? (
<ItemsTable
items={filteredData}
canMove={false}
enableMoveInBetween={false}
/>
) : (
<Alert severity="info">
{translateBuilder(BUILDER.BOOKMARKS_NO_ITEM_SEARCH, {
search: searchText,
})}
</Alert>
)}
</Stack>
);
}

if (isItemsLoading) {
return <Loader />;
}
if (isError) {
return <ErrorAlert id={BOOKMARKED_ITEMS_ERROR_ALERT_ID} />;
}

return (
<Box mt={2}>
<ErrorAlert id={BOOKMARKED_ITEMS_ERROR_ALERT_ID} />
</Box>
);
};
if (isLoading) {
return <LoadingScreen />;
}

return (
<Alert severity="info">{translateBuilder(BUILDER.BOOKMARKS_NO_ITEM)}</Alert>
);
};

const BookmarkedItemsWrapper = (): JSX.Element => {
const { t } = useBuilderTranslation();
const itemSearch = useItemSearch();

return (
<PageWrapper
title={translateBuilder(BUILDER.BOOKMARKED_ITEMS_TITLE)}
title={t(BUILDER.BOOKMARKED_ITEMS_TITLE)}
id={BOOKMARKED_ITEMS_ID}
options={
<Stack
Expand All @@ -134,13 +126,13 @@ const BookmarkedItems = (): JSX.Element | null => {
justifyContent="flex-end"
spacing={1}
>
{input}
{itemSearch.input}
</Stack>
}
>
{renderContent()}
<BookmarkedItems searchText={itemSearch.text} />
</PageWrapper>
);
};

export default BookmarkedItems;
export default BookmarkedItemsWrapper;
106 changes: 45 additions & 61 deletions src/components/pages/PublishedItemsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Alert, Box, Stack } from '@mui/material';

import { Loader } from '@graasp/ui';
import { Alert, Stack } from '@mui/material';

import { Ordering } from '@/enums';

Expand All @@ -17,6 +15,7 @@ import { useCurrentUserContext } from '../context/CurrentUserContext';
import { useFilterItemsContext } from '../context/FilterItemsContext';
import { useItemSearch } from '../item/ItemSearch';
import ModeButton from '../item/header/ModeButton';
import LoadingScreen from '../layout/LoadingScreen';
import ItemsTable from '../main/ItemsTable';
import SortingSelect from '../table/SortingSelect';
import { SortingOptions } from '../table/types';
Expand All @@ -43,85 +42,70 @@ const PublishedItemsScreenContent = ({
ordering: Ordering.DESC,
});
const filteredData = publishedItems?.filter(
(d) => shouldDisplayItem(d.type) && d.name.includes(searchText),
(d) =>
shouldDisplayItem(d.type) &&
d.name.toLowerCase().includes(searchText.toLowerCase()),
);
filteredData?.sort(sortFn);

if (isError) {
return (
<Box mt={2}>
<ErrorAlert id={PUBLISHED_ITEMS_ERROR_ALERT_ID} />
</Box>
);
}

if (!publishedItems?.length) {
return (
<Alert severity="info">
{translateBuilder(BUILDER.PUBLISHED_ITEMS_EMPTY)}
</Alert>
);
}

if (filteredData) {
if (publishedItems?.length) {
return (
<>
<Stack alignItems="space-between" direction="column" gap={1} width="100%">
<Stack
alignItems="space-between"
direction="column"
mt={2}
gap={1}
width="100%"
spacing={1}
direction="row"
justifyContent="space-between"
alignItems="center"
>
<Stack
spacing={1}
direction="row"
justifyContent="space-between"
alignItems="center"
>
<SelectTypes />
<Stack direction="row" gap={1}>
{sortBy && setSortBy && (
<SortingSelect
sortBy={sortBy}
setSortBy={setSortBy}
ordering={ordering}
setOrdering={setOrdering}
options={options}
/>
)}
<ModeButton />
</Stack>
<SelectTypes />
<Stack direction="row" gap={1}>
{sortBy && setSortBy && (
<SortingSelect
sortBy={sortBy}
setSortBy={setSortBy}
ordering={ordering}
setOrdering={setOrdering}
options={options}
/>
)}
<ModeButton />
</Stack>
</Stack>
{filteredData.length ? (
{filteredData?.length ? (
<ItemsTable
id={PUBLISHED_ITEMS_ID}
items={filteredData ?? []}
canMove={false}
enableMoveInBetween={false}
/>
) : (
<Box mt={2}>
<Alert severity="info">
{translateBuilder(BUILDER.PUBLISHED_ITEMS_NOT_FOUND_SEARCH, {
search: searchText,
})}
</Alert>
</Box>
<Alert severity="info">
{translateBuilder(BUILDER.PUBLISHED_ITEMS_NOT_FOUND_SEARCH, {
search: searchText,
})}
</Alert>
)}
</>
</Stack>
);
}

if (isError) {
return <ErrorAlert id={PUBLISHED_ITEMS_ERROR_ALERT_ID} />;
}

if (isLoading) {
return <Loader />;
return <LoadingScreen />;
}

return (
<Box mt={2}>
<ErrorAlert id={PUBLISHED_ITEMS_ERROR_ALERT_ID} />;
</Box>
);
if (!publishedItems?.length) {
return (
<Alert severity="info">
{translateBuilder(BUILDER.PUBLISHED_ITEMS_EMPTY)}
</Alert>
);
}

return <ErrorAlert id={PUBLISHED_ITEMS_ERROR_ALERT_ID} />;
};

const PublishedItemsScreen = (): JSX.Element | null => {
Expand Down
Loading