-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3078047
commit e9717bd
Showing
13 changed files
with
197 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
72 changes: 72 additions & 0 deletions
72
packages/notion/src/sidebar-2/_components/favorite-list.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,72 @@ | ||
import React from "react"; | ||
|
||
import { | ||
buildTree, | ||
TreeGroup, | ||
TreeItem, | ||
TreeList, | ||
TreeNode, | ||
} from "@swy/ui/shared"; | ||
|
||
import { usePlatformStore } from "../../slices"; | ||
import type { Page, UpdatePageParams } from "../../types"; | ||
import { ActionGroup } from "./action-group"; | ||
import { MenuType } from "./types"; | ||
|
||
interface FavoriteListProps { | ||
isLoading?: boolean; | ||
getPageLink?: (group: string, id: string) => string; | ||
onSelect: (group: string, id: string) => void; | ||
onUpdate: (id: string, data: UpdatePageParams) => void; | ||
} | ||
|
||
export const FavoriteList: React.FC<FavoriteListProps> = ({ | ||
isLoading, | ||
getPageLink, | ||
onSelect, | ||
onUpdate, | ||
}) => { | ||
const pages = usePlatformStore((state) => Object.values(state.pages)); | ||
const favorites = pages.filter((page) => page.isFavorite); | ||
const activePage = usePlatformStore((state) => state.activePage); | ||
const setActivePage = usePlatformStore((state) => state.setActivePage); | ||
|
||
const nodes = favorites.map<TreeNode<Page>>((fav) => ({ | ||
...fav, | ||
parentId: null, | ||
children: buildTree(pages, fav.id), | ||
})); | ||
|
||
const select = (node: Page) => { | ||
setActivePage(node.id); | ||
onSelect(node.type, node.id); | ||
}; | ||
|
||
return ( | ||
<TreeGroup title="Favorites" isLoading={isLoading}> | ||
<TreeList | ||
nodes={nodes} | ||
defaultIcon={{ type: "lucide", name: "file" }} | ||
selectedId={activePage} | ||
Item={({ node, ...props }) => ( | ||
<TreeItem | ||
{...props} | ||
node={node} | ||
className="group" | ||
onSelect={() => select(node)} | ||
expandable={node.type === "document"} | ||
> | ||
<ActionGroup | ||
type={node.isFavorite ? MenuType.Favorites : MenuType.Normal} | ||
pageLink={getPageLink?.(node.type, node.id) ?? "/"} | ||
isFavorite={node.isFavorite} | ||
lastEditedBy={node.lastEditedBy} | ||
lastEditedAt={node.lastEditedAt} | ||
onUpdate={(data) => onUpdate(node.id, data)} | ||
/> | ||
</TreeItem> | ||
)} | ||
/> | ||
</TreeGroup> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./doc-list"; | ||
export * from "./favorite-list"; | ||
export * from "./hint-item"; | ||
export * from "./trash-box"; |
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,4 @@ | ||
export enum MenuType { | ||
Normal = "normal", | ||
Favorites = "favorites", | ||
} |
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.