-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use newer Learning Resource list cards in Learning Paths lists (#1256)
* Refactor ListDetailsPage ListDetailsComponent to page-component ItemsListing * Condensed flag for reuse between user list and learning path items * Remove no items empty message while loading * Update test path. Variable spacing. * Margin around ItemsListingComponent
- Loading branch information
Showing
7 changed files
with
180 additions
and
140 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
frontends/mit-open/src/page-components/ItemsListing/ItemsListingComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import React from "react" | ||
import { Grid, Button, Typography, styled } from "ol-components" | ||
import { RiPencilFill, RiArrowUpDownLine } from "@remixicon/react" | ||
import { useUserMe } from "api/hooks/user" | ||
import { useToggle, pluralize } from "ol-utilities" | ||
import { GridColumn, GridContainer } from "@/components/GridLayout/GridLayout" | ||
import ItemsListing from "./ItemsListing" | ||
import type { LearningResourceListItem } from "./ItemsListing" | ||
|
||
const Container = styled(GridContainer)` | ||
margin-top: 30px; | ||
margin-bottom: 100px; | ||
` | ||
|
||
const TitleContainer = styled(Grid)` | ||
margin-top: 10px; | ||
margin-bottom: 20px; | ||
` | ||
|
||
type OnEdit = () => void | ||
type ListData = { | ||
title: string | ||
description?: string | null | ||
item_count: number | ||
} | ||
|
||
type ItemsListingComponentProps = { | ||
listType: string | ||
list?: ListData | ||
items: LearningResourceListItem[] | ||
isLoading: boolean | ||
isFetching: boolean | ||
handleEdit: OnEdit | ||
condensed?: boolean | ||
} | ||
|
||
const ItemsListingComponent: React.FC<ItemsListingComponentProps> = ({ | ||
listType, | ||
list, | ||
items, | ||
isLoading, | ||
isFetching, | ||
handleEdit, | ||
condensed = false, | ||
}) => { | ||
const { data: user } = useUserMe() | ||
const [isSorting, toggleIsSorting] = useToggle(false) | ||
|
||
const canEdit = user?.is_learning_path_editor | ||
const showSort = canEdit && !!items.length | ||
const count = list?.item_count | ||
|
||
return ( | ||
<Container> | ||
<GridColumn variant="single-full"> | ||
<Grid container> | ||
<TitleContainer item xs={12}> | ||
<Typography variant="h3" component="h1"> | ||
{list?.title} | ||
</Typography> | ||
{list?.description && <p>{list.description}</p>} | ||
</TitleContainer> | ||
<Grid | ||
item | ||
xs={6} | ||
container | ||
alignItems="center" | ||
justifyContent="space-between" | ||
> | ||
{showSort && ( | ||
<Button | ||
variant="text" | ||
disabled={count === 0} | ||
startIcon={isSorting ? undefined : <RiArrowUpDownLine />} | ||
onClick={toggleIsSorting.toggle} | ||
> | ||
{isSorting ? "Done ordering" : "Reorder"} | ||
</Button> | ||
)} | ||
{count !== undefined && count > 0 | ||
? `${count} ${pluralize("item", count)}` | ||
: null} | ||
</Grid> | ||
<Grid | ||
item | ||
xs={6} | ||
container | ||
justifyContent="flex-end" | ||
alignItems="center" | ||
display="flex" | ||
> | ||
{canEdit ? ( | ||
<Button | ||
variant="text" | ||
startIcon={<RiPencilFill />} | ||
onClick={handleEdit} | ||
> | ||
Edit | ||
</Button> | ||
) : null} | ||
</Grid> | ||
</Grid> | ||
<ItemsListing | ||
listType={listType} | ||
items={items} | ||
isLoading={isLoading} | ||
isRefetching={isFetching} | ||
sortable={isSorting} | ||
emptyMessage="There are no items in this list yet." | ||
condensed={condensed} | ||
/> | ||
</GridColumn> | ||
</Container> | ||
) | ||
} | ||
|
||
export default ItemsListingComponent | ||
export type { ItemsListingComponentProps } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
frontends/mit-open/src/pages/DashboardPage/UserListDetailsTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { useMemo } from "react" | ||
import { | ||
useInfiniteUserListItems, | ||
useUserListsDetail, | ||
} from "api/hooks/learningResources" | ||
import { ListType } from "api/constants" | ||
import { manageListDialogs } from "@/page-components/ManageListDialogs/ManageListDialogs" | ||
import ItemsListingComponent from "@/page-components/ItemsListing/ItemsListingComponent" | ||
|
||
interface UserListDetailsTabProps { | ||
userListId: number | ||
} | ||
|
||
const UserListDetailsTab: React.FC<UserListDetailsTabProps> = (props) => { | ||
const { userListId } = props | ||
const listQuery = useUserListsDetail(userListId) | ||
const itemsQuery = useInfiniteUserListItems({ userlist_id: userListId }) | ||
|
||
const items = useMemo(() => { | ||
const pages = itemsQuery.data?.pages | ||
return pages?.flatMap((p) => p.results ?? []) ?? [] | ||
}, [itemsQuery.data]) | ||
|
||
return ( | ||
<ItemsListingComponent | ||
listType={ListType.UserList} | ||
list={listQuery.data} | ||
items={items} | ||
isLoading={itemsQuery.isLoading} | ||
isFetching={itemsQuery.isFetching} | ||
handleEdit={() => manageListDialogs.upsertUserList(listQuery.data)} | ||
/> | ||
) | ||
} | ||
|
||
export default UserListDetailsTab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.