feat: subscriptions in profile page

This commit is contained in:
DIYgod
2024-05-02 22:26:36 +08:00
parent c03d1359cd
commit 27b5f4a15c
4 changed files with 105 additions and 48 deletions
@@ -21,8 +21,8 @@ export function FeedColumn({
activedList,
setActivedList,
}: {
activedList: ActivedList
setActivedList: (value: ActivedList) => void
activedList?: ActivedList
setActivedList?: (value: ActivedList) => void
}) {
const carouselRef = useRef<HTMLDivElement>(null)
@@ -63,7 +63,7 @@ export function FeedColumn({
<div
className="h-full flex flex-col gap-3"
onClick={() =>
setActivedList({
setActivedList?.({
level: "view",
id: active,
name: views[active].name,
@@ -94,7 +94,7 @@ export function FeedColumn({
className={cn(active === index && "text-zinc-800")}
onClick={(e) => {
setActive(index)
setActivedList({
setActivedList?.({
level: "view",
id: index,
name: views[index].name,
@@ -118,6 +118,7 @@ export function FeedColumn({
{views.map((item, index) => (
<section key={item.name} className="snap-center shrink-0">
<FeedList
className="w-64 px-3"
view={index}
activedList={activedList}
setActivedList={setActivedList}
@@ -12,37 +12,46 @@ import { SiteIcon } from "../site-icon"
import { Response as SubscriptionsResponse } from "@renderer/lib/subscriptions"
export function FeedList({
className,
view,
activedList,
setActivedList,
hideTitle,
}: {
view: number
activedList: ActivedList
setActivedList: (value: ActivedList) => void
className?: string
view?: number
activedList?: ActivedList
setActivedList?: (value: ActivedList) => void
hideTitle?: boolean
}) {
const subscriptions = useSubscriptions(view)
return (
<div className="w-64 px-3">
<div
className={cn(
"flex items-center justify-between mb-2 px-2.5 py-1 cursor-pointer",
)}
onClick={(e) => {
e.stopPropagation()
setActivedList({
level: levels.view,
id: view,
name: views[view].name,
view,
})
}}
>
<div className="font-bold">{views[view].name}</div>
<div className="text-sm text-zinc-500 ml-2">
{subscriptions.data?.unread}
<div className={className}>
{!hideTitle && (
<div
className={cn(
"flex items-center justify-between mb-2 px-2.5 py-1 cursor-pointer",
)}
onClick={(e) => {
e.stopPropagation()
view !== undefined &&
setActivedList?.({
level: levels.view,
id: view,
name: views[view].name,
view,
})
}}
>
<div className="font-bold">
{view !== undefined && views[view].name}
</div>
<div className="text-sm text-zinc-500 ml-2">
{subscriptions.data?.unread}
</div>
</div>
</div>
)}
{subscriptions.data?.list.map((category) => (
<FeedCategory
key={category.name}
@@ -63,9 +72,9 @@ function FeedCategory({
view,
}: {
data: SubscriptionsResponse["list"][number]
activedList: ActivedList
setActivedList: (value: ActivedList) => void
view: number
activedList?: ActivedList
setActivedList?: (value: ActivedList) => void
view?: number
}) {
const [open, setOpen] = useState(false)
@@ -75,12 +84,13 @@ function FeedCategory({
onOpenChange={(o) => setOpen(o)}
onClick={(e) => {
e.stopPropagation()
setActivedList({
level: levels.folder,
id: data.name,
name: data.name,
view,
})
view !== undefined &&
setActivedList?.({
level: levels.folder,
id: data.name,
name: data.name,
view,
})
}}
>
<div
@@ -91,11 +101,17 @@ function FeedCategory({
"bg-[#C9C9C7]",
)}
>
<div className="flex items-center min-w-0">
<CollapsibleTrigger className="flex items-center h-7 [&_.i-mingcute-right-fill]:data-[state=open]:rotate-90">
<div className="flex items-center min-w-0 w-full">
<CollapsibleTrigger
className={cn(
"flex items-center h-7 [&_.i-mingcute-right-fill]:data-[state=open]:rotate-90",
!setActivedList && "flex-1",
)}
>
<i className="i-mingcute-right-fill mr-2 transition-transform" />
{!setActivedList && <span className="truncate">{data.name}</span>}
</CollapsibleTrigger>
<span className="truncate">{data.name}</span>
{setActivedList && <span className="truncate">{data.name}</span>}
</div>
{!!data.unread && (
<div className="text-xs text-zinc-500 ml-2">{data.unread}</div>
@@ -129,12 +145,13 @@ function FeedCategory({
)}
onClick={(e) => {
e.stopPropagation()
setActivedList({
level: levels.feed,
id: feed.feedId,
name: feed.feeds.title,
view,
})
view !== undefined &&
setActivedList?.({
level: levels.feed,
id: feed.feedId,
name: feed.feeds.title,
view,
})
}}
>
<div className="flex items-center min-w-0">
+3 -2
View File
@@ -10,14 +10,15 @@ export type Response = {
unread: number
}
export const useSubscriptions = (view: number) =>
export const useSubscriptions = (view?: number) =>
useQuery({
queryKey: ["subscriptions", view],
queryFn: async () => {
const subscriptions = (
await (
await fetch(
`${import.meta.env.VITE_ELECTRON_REMOTE_API_URL}/subscriptions?view=${view}`,
`${import.meta.env.VITE_ELECTRON_REMOTE_API_URL}/subscriptions` +
(view ? `?view=${view}` : ``),
{
credentials: "include",
},
@@ -1,7 +1,45 @@
import { useSession } from "@hono/auth-js/react"
import { FeedList } from "@renderer/components/feed-column/list"
import {
Avatar,
AvatarFallback,
AvatarImage,
} from "@renderer/components/ui/avatar"
import { views } from "@renderer/lib/constants"
export function Component() {
const { data: session } = useSession()
return (
<div className="flex flex-col gap-8 items-center justify-center w-full">
Profile
<div className="flex gap-10 w-full px-10 py-16">
<div className="flex flex-col gap-8 flex-1 pt-20 min-w-40">
<Avatar className="w-32 h-32 aspect-square">
<AvatarImage src={session?.user?.image || undefined} />
<AvatarFallback>{session?.user?.name?.slice(0, 2)}</AvatarFallback>
</Avatar>
<div className="font-bold text-4xl">{session?.user?.name}</div>
</div>
<div className="flex-[2] flex flex-col gap-8">
<div className="h-full flex flex-col gap-4">
<div className="font-bold text-2xl">Subscriptions</div>
<div className="overflow-y-auto">
{views.map((view, index) => (
<>
<div className="font-medium flex items-center gap-2 mb-1">
{view.icon}
{view.name}
</div>
<FeedList
key={index}
className="mb-4"
view={index}
hideTitle={true}
/>
</>
))}
</div>
</div>
</div>
</div>
)
}