-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FE) Add Retrieve Workspace List (#74)
* Add retrieve the workspace list * Add move to workspace handler * Change font size
- Loading branch information
Showing
7 changed files
with
177 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { | ||
Box, | ||
CircularProgress, | ||
ListItemSecondaryAction, | ||
ListItemText, | ||
MenuItem, | ||
MenuList, | ||
Popover, | ||
PopoverProps, | ||
} from "@mui/material"; | ||
import { useGetWorkspaceListQuery } from "../../hooks/api/workspace"; | ||
import InfiniteScroll from "react-infinite-scroller"; | ||
import { useMemo } from "react"; | ||
import { Workspace } from "../../hooks/api/types/workspace"; | ||
import { useNavigate, useParams } from "react-router-dom"; | ||
import CheckIcon from "@mui/icons-material/Check"; | ||
|
||
interface WorkspaceListPopoverProps extends PopoverProps { | ||
width?: number; | ||
} | ||
|
||
function WorkspaceListPopover(props: WorkspaceListPopoverProps) { | ||
const { width, ...popoverProps } = props; | ||
const navigate = useNavigate(); | ||
const params = useParams(); | ||
const { data: workspacePageList, hasNextPage, fetchNextPage } = useGetWorkspaceListQuery(); | ||
const workspaceList = useMemo(() => { | ||
return workspacePageList?.pages.reduce((prev: Array<Workspace>, page) => { | ||
return prev.concat(page.workspaces); | ||
}, [] as Array<Workspace>); | ||
}, [workspacePageList?.pages]); | ||
|
||
const handleMoveToSelectedWorkspace = (workspaceId: string) => { | ||
if (params.workspaceId === workspaceId) return; | ||
|
||
navigate(`/workspace/${workspaceId}`); | ||
}; | ||
|
||
return ( | ||
<Popover | ||
anchorOrigin={{ | ||
vertical: "bottom", | ||
horizontal: "center", | ||
}} | ||
transformOrigin={{ | ||
vertical: "top", | ||
horizontal: "center", | ||
}} | ||
{...popoverProps} | ||
> | ||
<Box | ||
style={{ | ||
height: 300, | ||
overflow: "auto", | ||
}} | ||
> | ||
<InfiniteScroll | ||
pageStart={0} | ||
loadMore={() => fetchNextPage()} | ||
hasMore={hasNextPage} | ||
loader={ | ||
<Box className="loader" key={0}> | ||
<CircularProgress size="sm" /> | ||
</Box> | ||
} | ||
useWindow={false} | ||
> | ||
<MenuList sx={{ width }}> | ||
{workspaceList?.map((workspace) => ( | ||
<MenuItem | ||
key={workspace.id} | ||
onClick={() => handleMoveToSelectedWorkspace(workspace.id)} | ||
> | ||
<ListItemText | ||
primaryTypographyProps={{ | ||
noWrap: true, | ||
variant: "body2", | ||
}} | ||
> | ||
{workspace.title} | ||
</ListItemText> | ||
{params.workspaceId === workspace.id && ( | ||
<ListItemSecondaryAction> | ||
<CheckIcon fontSize="small" /> | ||
</ListItemSecondaryAction> | ||
)} | ||
</MenuItem> | ||
))} | ||
</MenuList> | ||
</InfiniteScroll> | ||
</Box> | ||
</Popover> | ||
); | ||
} | ||
|
||
export default WorkspaceListPopover; |
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
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