diff --git a/web/app/components/sidebar/partials/journal-section.tsx b/web/app/components/sidebar/partials/journal-section.tsx index d12ea171..2efdcc94 100644 --- a/web/app/components/sidebar/partials/journal-section.tsx +++ b/web/app/components/sidebar/partials/journal-section.tsx @@ -7,8 +7,8 @@ import { Link } from "@tanstack/react-router" import { getFeatureFlag } from "~/actions" export const JournalSection: React.FC = () => { - const { me } = useAccount() - const journalEntries = me?.root?.journalEntries + const { me } = useAccount({ root: { journalEntries: [{}] } }) + const journalEntries = me?.root.journalEntries const [, setIsFetching] = useState(false) const [isFeatureActive, setIsFeatureActive] = useState(false) diff --git a/web/app/components/sidebar/partials/link-collection.tsx b/web/app/components/sidebar/partials/link-collection.tsx index eb2d75f6..c22bc80f 100644 --- a/web/app/components/sidebar/partials/link-collection.tsx +++ b/web/app/components/sidebar/partials/link-collection.tsx @@ -3,25 +3,16 @@ import { useAccount } from "@/lib/providers/jazz-provider" import { NavItem } from "~/components/custom/nav-item" export const LinkCollection: React.FC = () => { - const { me } = useAccount({ - root: { - personalLinks: [], - personalPages: [], - topicsWantToLearn: [], - topicsLearning: [], - topicsLearned: [], - tasks: [], - }, - }) + const { me } = useAccount() - const linkCount = me?.root.personalLinks?.length || 0 - const pageCount = me?.root.personalPages?.length || 0 - const taskCount = me?.root.tasks?.length || 0 + const linkCount = me?.root?.personalLinks?.length || 0 + const pageCount = me?.root?.personalPages?.length || 0 + const taskCount = me?.root?.tasks?.length || 0 const topicCount = - (me?.root.topicsWantToLearn?.length || 0) + - (me?.root.topicsLearning?.length || 0) + - (me?.root.topicsLearned?.length || 0) + (me?.root?.topicsWantToLearn?.length || 0) + + (me?.root?.topicsLearning?.length || 0) + + (me?.root?.topicsLearned?.length || 0) return (
diff --git a/web/app/components/sidebar/partials/link-section.tsx b/web/app/components/sidebar/partials/link-section.tsx deleted file mode 100644 index ee1be385..00000000 --- a/web/app/components/sidebar/partials/link-section.tsx +++ /dev/null @@ -1,140 +0,0 @@ -import * as React from "react" -import { Link } from "@tanstack/react-router" -import { useAccount } from "@/lib/providers/jazz-provider" -import { cn } from "@/lib/utils" -import { PersonalLinkLists } from "@/lib/schema/personal-link" -import { LearningStateValue } from "~/lib/constants" -import { LaIcon } from "~/components/custom/la-icon" - -export const LinkSection: React.FC = () => { - const { me } = useAccount({ root: { personalLinks: [] } }) - - if (!me) return null - - const linkCount = me.root.personalLinks?.length || 0 - - return ( -
- - -
- ) -} - -interface LinkSectionHeaderProps { - linkCount: number -} - -const LinkSectionHeader: React.FC = ({ linkCount }) => { - return ( - - {({ isActive }) => { - return ( - <> -
- - Links -
- - {linkCount > 0 && ( - - {linkCount} - - )} - - ) - }} - - ) -} - -interface LinkListProps { - personalLinks: PersonalLinkLists -} - -const LinkList: React.FC = ({ personalLinks }) => { - const linkStates: LearningStateValue[] = [ - "wantToLearn", - "learning", - "learned", - ] - const linkLabels: Record = { - wantToLearn: "To Learn", - learning: "Learning", - learned: "Learned", - } - - const linkCounts = linkStates.reduce( - (acc, state) => ({ - ...acc, - [state]: personalLinks.filter((link) => link?.learningState === state) - .length, - }), - {} as Record, - ) - - return ( -
- {linkStates.map((state) => ( - - ))} -
- ) -} - -interface LinkListItemProps { - label: string - state: LearningStateValue - count: number -} - -const LinkListItem: React.FC = ({ label, state, count }) => ( -
- - {({ isActive }) => ( - <> -
-

{label}

-
- {count > 0 && ( - - {count} - - )} - - )} - -
-) diff --git a/web/app/components/sidebar/partials/page-section.tsx b/web/app/components/sidebar/partials/page-section.tsx index eeb02999..1e5d32fc 100644 --- a/web/app/components/sidebar/partials/page-section.tsx +++ b/web/app/components/sidebar/partials/page-section.tsx @@ -1,7 +1,7 @@ import * as React from "react" import { useAtom } from "jotai" import { atomWithStorage } from "jotai/utils" -import { Link, useNavigate } from "@tanstack/react-router" +import { Link } from "@tanstack/react-router" import { useAccount } from "@/lib/providers/jazz-provider" import { cn } from "@/lib/utils" import { Button } from "@/components/ui/button" @@ -49,9 +49,14 @@ const isExpandedAtom = atomWithStorage("isPageSectionExpanded", true) export const PageSection: React.FC = () => { const { me } = useAccount({ root: { - personalPages: [{}], + personalPages: [ + { + topic: {}, + }, + ], }, }) + const [sort] = useAtom(pageSortAtom) const [show] = useAtom(pageShowAtom) const [isExpanded, setIsExpanded] = useAtom(isExpandedAtom) @@ -163,23 +168,13 @@ const PageSectionHeader: React.FC = ({ ) const NewPageButton: React.FC = () => { - const { me } = useAccount() - const navigate = useNavigate() const { newPage } = usePageActions() const handleClick = async (e: React.MouseEvent) => { e.preventDefault() e.stopPropagation() - const page = newPage(me) - - if (page.id) { - navigate({ - to: "/pages/$pageId", - params: { pageId: page.id }, - replace: true, - }) - } + newPage() } return ( diff --git a/web/app/components/sidebar/sidebar.tsx b/web/app/components/sidebar/sidebar.tsx index 2619dd8a..4d7795ba 100644 --- a/web/app/components/sidebar/sidebar.tsx +++ b/web/app/components/sidebar/sidebar.tsx @@ -38,44 +38,48 @@ const useSidebarCollapse = ( return [isCollapsed, setIsCollapsed] } -const SidebarItem: React.FC = React.memo( - ({ label, url, icon, onClick, children }) => { - const { pathname } = useLocation() - const isActive = pathname === url +const SidebarItem: React.FC = ({ + label, + url, + icon, + onClick, + children, +}) => { + const { pathname } = useLocation() + const isActive = pathname === url - return ( -
+ - - {icon && ( - - {icon} - - )} - {label} - {children} - -
- ) - }, -) + {icon && ( + + {icon} + + )} + {label} + {children} + +
+ ) +} SidebarItem.displayName = "SidebarItem" -const LogoAndSearch: React.FC = React.memo(() => { +const LogoAndSearch: React.FC = () => { const { pathname } = useLocation() return ( @@ -105,11 +109,11 @@ const LogoAndSearch: React.FC = React.memo(() => { ) -}) +} LogoAndSearch.displayName = "LogoAndSearch" -const SidebarContent: React.FC = React.memo(() => { +const SidebarContent: React.FC = () => { const { me } = useAccountOrGuest() return ( @@ -119,15 +123,15 @@ const SidebarContent: React.FC = React.memo(() => {
- {me._type === "Account" && } - {me._type === "Account" && } - {me._type === "Account" && } + {me?._type === "Account" && } + {me?._type === "Account" && } + {me?._type === "Account" && }
) -}) +} SidebarContent.displayName = "SidebarContent"