mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-23 16:58:38 +02:00
Merge branch 'main' of github.com:learn-anything/learn-anything.xyz
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { usePathname } from "next/navigation"
|
import { usePathname, useRouter } from "next/navigation"
|
||||||
import { useAccount } from "@/lib/providers/jazz-provider"
|
import { useAccount } from "@/lib/providers/jazz-provider"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { PersonalLinkLists } from "@/lib/schema/personal-link"
|
import { PersonalLinkLists } from "@/lib/schema/personal-link"
|
||||||
@@ -32,28 +32,31 @@ interface LinkSectionHeaderProps {
|
|||||||
isActive: boolean
|
isActive: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const LinkSectionHeader: React.FC<LinkSectionHeaderProps> = ({ linkCount, isActive }) => (
|
const LinkSectionHeader: React.FC<LinkSectionHeaderProps> = ({ linkCount, isActive }) => {
|
||||||
<div
|
const pathname = usePathname()
|
||||||
className={cn(
|
const [state] = useQueryState("state", parseAsStringLiteral(LEARNING_STATES.map(ls => ls.value)))
|
||||||
"flex min-h-[30px] items-center gap-px rounded-md",
|
const isLinksActive = pathname.startsWith("/links") && !state
|
||||||
isActive ? "bg-accent text-accent-foreground" : "hover:bg-accent hover:text-accent-foreground"
|
|
||||||
)}
|
return (
|
||||||
>
|
<div className="flex gap-px rounded-md">
|
||||||
<Link
|
<Link
|
||||||
href="/links"
|
href="/links"
|
||||||
className={cn(
|
className={cn(
|
||||||
"size-6 flex-1 items-center justify-start rounded-md px-2 py-1",
|
"flex size-6 flex-1 items-center justify-start rounded-md px-2 py-1",
|
||||||
"focus-visible:outline-none focus-visible:ring-0",
|
"focus-visible:outline-none focus-visible:ring-0",
|
||||||
isActive ? "bg-accent text-accent-foreground" : "hover:bg-accent hover:text-accent-foreground"
|
isLinksActive
|
||||||
)}
|
? "bg-accent text-accent-foreground items-center justify-center py-4"
|
||||||
>
|
: "hover:bg-accent hover:text-accent-foreground"
|
||||||
<p className="flex items-center text-xs font-medium">
|
)}
|
||||||
Links
|
>
|
||||||
{linkCount > 0 && <span className="text-muted-foreground ml-1">{linkCount}</span>}
|
<p className="flex w-full items-center text-xs font-medium">
|
||||||
</p>
|
Links
|
||||||
</Link>
|
{linkCount > 0 && <span className="text-muted-foreground ml-1">{linkCount}</span>}
|
||||||
</div>
|
</p>
|
||||||
)
|
</Link>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const ALL_STATES = ["all", ...LEARNING_STATES.map(ls => ls.value)]
|
const ALL_STATES = ["all", ...LEARNING_STATES.map(ls => ls.value)]
|
||||||
interface ListProps {
|
interface ListProps {
|
||||||
@@ -62,31 +65,26 @@ interface ListProps {
|
|||||||
|
|
||||||
const List: React.FC<ListProps> = ({ personalLinks }) => {
|
const List: React.FC<ListProps> = ({ personalLinks }) => {
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const [activeState] = useQueryState("state", parseAsStringLiteral(ALL_STATES))
|
const [state] = useQueryState("state", parseAsStringLiteral(LEARNING_STATES.map(ls => ls.value)))
|
||||||
|
|
||||||
const toLearnCount = personalLinks.filter(link => link?.learningState === "wantToLearn").length
|
const toLearnCount = personalLinks.filter(link => link?.learningState === "wantToLearn").length
|
||||||
const learningCount = personalLinks.filter(link => link?.learningState === "learning").length
|
const learningCount = personalLinks.filter(link => link?.learningState === "learning").length
|
||||||
const learnedCount = personalLinks.filter(link => link?.learningState === "learned").length
|
const learnedCount = personalLinks.filter(link => link?.learningState === "learned").length
|
||||||
|
|
||||||
|
const isActive = (checkState: string) => {
|
||||||
|
return pathname === "/links" && state === checkState
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-px">
|
<div className="flex flex-col gap-px">
|
||||||
<ListItem
|
<ListItem
|
||||||
label="To Learn"
|
label="To Learn"
|
||||||
href="/links?state=wantToLearn"
|
href="/links?state=wantToLearn"
|
||||||
count={toLearnCount}
|
count={toLearnCount}
|
||||||
isActive={pathname === "/links" && activeState === "wantToLearn"}
|
isActive={isActive("wantToLearn")}
|
||||||
/>
|
|
||||||
<ListItem
|
|
||||||
label="Learning"
|
|
||||||
href="/links?state=learning"
|
|
||||||
count={learningCount}
|
|
||||||
isActive={pathname === "/links" && activeState === "learning"}
|
|
||||||
/>
|
|
||||||
<ListItem
|
|
||||||
label="Learned"
|
|
||||||
href="/links?state=learned"
|
|
||||||
count={learnedCount}
|
|
||||||
isActive={pathname === "/links" && activeState === "learned"}
|
|
||||||
/>
|
/>
|
||||||
|
<ListItem label="Learning" href="/links?state=learning" count={learningCount} isActive={isActive("learning")} />
|
||||||
|
<ListItem label="Learned" href="/links?state=learned" count={learnedCount} isActive={isActive("learned")} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -104,7 +102,10 @@ const ListItem: React.FC<ListItemProps> = ({ label, href, count, isActive }) =>
|
|||||||
<div className="group/topic-link relative flex min-w-0 flex-1">
|
<div className="group/topic-link relative flex min-w-0 flex-1">
|
||||||
<Link
|
<Link
|
||||||
href={href}
|
href={href}
|
||||||
className="group-hover/topic-link:bg-accent relative flex h-8 w-full items-center gap-2 rounded-md p-1.5 font-medium"
|
className={cn(
|
||||||
|
"relative flex h-8 w-full items-center gap-2 rounded-md p-1.5 font-medium",
|
||||||
|
isActive ? "bg-accent text-accent-foreground" : "hover:bg-accent hover:text-accent-foreground"
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
<div className="flex max-w-full flex-1 items-center gap-1.5 truncate text-sm">
|
<div className="flex max-w-full flex-1 items-center gap-1.5 truncate text-sm">
|
||||||
<p className={cn("truncate opacity-95 group-hover/topic-link:opacity-100")}>{label}</p>
|
<p className={cn("truncate opacity-95 group-hover/topic-link:opacity-100")}>{label}</p>
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ export const PageSection: React.FC<{ pathname?: string }> = ({ pathname }) => {
|
|||||||
const [show, setShow] = useAtom(pageShowAtom)
|
const [show, setShow] = useAtom(pageShowAtom)
|
||||||
|
|
||||||
const pageCount = me?.root.personalPages?.length || 0
|
const pageCount = me?.root.personalPages?.length || 0
|
||||||
const isActive = pathname ? pathname.startsWith("/pages") : false
|
// const isActive = pathname ? pathname.startsWith("/pages") : false
|
||||||
|
const isActive = pathname === "/pages"
|
||||||
|
|
||||||
if (!me) return null
|
if (!me) return null
|
||||||
|
|
||||||
@@ -74,21 +75,24 @@ interface PageSectionHeaderProps {
|
|||||||
isActive: boolean
|
isActive: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const PageSectionHeader: React.FC<PageSectionHeaderProps> = ({ pageCount }) => (
|
const PageSectionHeader: React.FC<PageSectionHeaderProps> = ({ pageCount, isActive }) => (
|
||||||
<div
|
<div
|
||||||
className={cn("flex min-h-[30px] items-center gap-px rounded-md", "hover:bg-accent hover:text-accent-foreground")}
|
className={cn(
|
||||||
|
"flex min-h-[30px] items-center gap-px rounded-md",
|
||||||
|
isActive ? "bg-accent text-accent-foreground" : "hover:bg-accent hover:text-accent-foreground"
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
<Link
|
<Link
|
||||||
href="/pages"
|
href="/pages"
|
||||||
className="size-6 flex-1 items-center justify-start rounded-md px-2 py-1 focus-visible:outline-none focus-visible:ring-0"
|
className="flex flex-1 items-center justify-start rounded-md px-2 py-1 focus-visible:outline-none focus-visible:ring-0"
|
||||||
>
|
>
|
||||||
<p className="flex items-center text-xs font-medium">
|
<p className="text-xs">
|
||||||
Pages
|
Pages
|
||||||
{pageCount > 0 && <span className="text-muted-foreground ml-1">{pageCount}</span>}
|
{pageCount > 0 && <span className="text-muted-foreground ml-1">{pageCount}</span>}
|
||||||
</p>
|
</p>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<div className={cn("flex items-center gap-px pr-2")}>
|
<div className="flex items-center gap-px pr-2">
|
||||||
<ShowAllForm />
|
<ShowAllForm />
|
||||||
<NewPageButton />
|
<NewPageButton />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export const ColumnHeader: React.FC = () => {
|
|||||||
<Column.Wrapper style={columnStyles.topic}>
|
<Column.Wrapper style={columnStyles.topic}>
|
||||||
<Column.Text>Topic</Column.Text>
|
<Column.Text>Topic</Column.Text>
|
||||||
</Column.Wrapper>
|
</Column.Wrapper>
|
||||||
<Column.Wrapper style={columnStyles.updated} className="justify-end">
|
<Column.Wrapper style={columnStyles.updated}>
|
||||||
<Column.Text>Updated</Column.Text>
|
<Column.Text>Updated</Column.Text>
|
||||||
</Column.Wrapper>
|
</Column.Wrapper>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Badge } from "@/components/ui/badge"
|
|||||||
import { Column } from "./column"
|
import { Column } from "./column"
|
||||||
import { useMedia } from "react-use"
|
import { useMedia } from "react-use"
|
||||||
import { useColumnStyles } from "../hooks/use-column-styles"
|
import { useColumnStyles } from "../hooks/use-column-styles"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
|
||||||
interface PageItemProps {
|
interface PageItemProps {
|
||||||
page: PersonalPage
|
page: PersonalPage
|
||||||
@@ -47,8 +48,8 @@ export const PageItem = React.forwardRef<HTMLAnchorElement, PageItemProps>(({ pa
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Column.Wrapper style={columnStyles.updated} className="justify-end">
|
<Column.Wrapper style={columnStyles.updated} className="flex justify-end">
|
||||||
<Column.Text className="text-[13px]">{page.updatedAt.toLocaleDateString()}</Column.Text>
|
<Column.Text className="text-[13px]">{format(new Date(page.updatedAt), "d MMM yyyy")}</Column.Text>
|
||||||
</Column.Wrapper>
|
</Column.Wrapper>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
Reference in New Issue
Block a user