fix: feed list

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-07-17 19:48:17 +08:00
parent 19ea8a606a
commit af3f47e89d
3 changed files with 83 additions and 55 deletions
@@ -70,15 +70,27 @@ export const Viewport = React.forwardRef<
React.useLayoutEffect(() => {
const $el = ref.current
if (!$el) return
const canScroll = $el.scrollHeight > $el.clientHeight
setCanScroll(canScroll)
}, [rest.children])
const handler = () => {
const canScroll = $el.scrollHeight > $el.clientHeight
setCanScroll(canScroll)
}
const observer = new ResizeObserver(handler)
handler()
observer.observe($el)
return () => observer.disconnect()
}, [])
React.useImperativeHandle(forwardedRef, () => ref.current as HTMLDivElement)
return (
<ScrollAreaBase.Viewport
{...rest}
ref={ref}
className={cn("block size-full", canScroll && styles["scroller"], className)}
className={cn(
"block size-full",
canScroll && styles["scroller"],
className,
)}
/>
)
})
@@ -105,12 +117,25 @@ export const ScrollArea = React.forwardRef<
rootClassName?: string
viewportClassName?: string
scrollbarClassName?: string
flex?: boolean
}
>(({ children, rootClassName, viewportClassName, scrollbarClassName }, ref) => (
<Root className={rootClassName}>
<Viewport ref={ref} onWheel={stopPropagation} className={viewportClassName}>
{children}
</Viewport>
<Scrollbar className={scrollbarClassName} />
</Root>
))
>(
(
{ flex, children, rootClassName, viewportClassName, scrollbarClassName },
ref,
) => (
<Root className={rootClassName}>
<Viewport
ref={ref}
onWheel={stopPropagation}
className={cn(
flex ? "[&>div]:!flex [&>div]:!flex-col" : "",
viewportClassName,
)}
>
{children}
</Viewport>
<Scrollbar className={scrollbarClassName} />
</Root>
),
)
@@ -210,11 +210,11 @@ export function FeedColumn({ children }: PropsWithChildren) {
{views.map((item, index) => (
<section
key={item.name}
className="min-h-full w-64 shrink-0 snap-center overflow-y-auto pb-8"
className="h-full w-64 shrink-0 snap-center pb-8"
>
{active === index && (
<FeedList
className="flex min-h-full w-full flex-col px-3 text-sm"
className="flex size-full flex-col text-sm"
view={index}
/>
)}
+44 -41
View File
@@ -1,4 +1,5 @@
import { useUISettingKey } from "@renderer/atoms/settings/ui"
import { ScrollArea } from "@renderer/components/ui/scroll-area"
import { useNavigateEntry } from "@renderer/hooks/biz/useNavigateEntry"
import { useRouteFeedId } from "@renderer/hooks/biz/useRouteParams"
import { useAuthQuery } from "@renderer/hooks/common"
@@ -94,7 +95,7 @@ export function FeedList({
{!hideTitle && (
<div
onClick={stopPropagation}
className="mb-2 flex items-center justify-between px-2.5 py-1"
className="mx-3 mb-2 flex items-center justify-between px-2.5 py-1"
>
<div
className="font-bold"
@@ -127,47 +128,49 @@ export function FeedList({
</div>
</div>
)}
<div
className={cn(
"flex h-8 w-full shrink-0 items-center rounded-md px-2.5 transition-colors",
feedId === FEED_COLLECTION_LIST && "bg-native-active",
)}
onClick={(e) => {
e.stopPropagation()
if (view !== undefined) {
navigate({
entryId: null,
feedId: FEED_COLLECTION_LIST,
view,
})
}
}}
>
<i className="i-mgc-star-cute-fi mr-2 text-orange-500" />
Starred
</div>
{hasData ?
sortedByUnread?.map(([category, ids]) => (
<FeedCategory
showUnreadCount={showUnreadCount}
key={category}
data={ids}
view={view}
expansion={expansion}
/>
)) :
!hideTitle && (
<div className="flex h-full flex-1 items-center text-zinc-500">
<Link
to="/discover"
className="-mt-36 flex h-full flex-1 flex-col items-center justify-center gap-2"
onClick={stopPropagation}
>
<i className="i-mgc-add-cute-re text-3xl" />
Add some feeds
</Link>
</div>
<ScrollArea.ScrollArea flex viewportClassName="!px-3">
<div
className={cn(
"flex h-8 w-full shrink-0 items-center rounded-md px-2.5 transition-colors",
feedId === FEED_COLLECTION_LIST && "bg-native-active",
)}
onClick={(e) => {
e.stopPropagation()
if (view !== undefined) {
navigate({
entryId: null,
feedId: FEED_COLLECTION_LIST,
view,
})
}
}}
>
<i className="i-mgc-star-cute-fi mr-2 text-orange-500" />
Starred
</div>
{hasData ?
sortedByUnread?.map(([category, ids]) => (
<FeedCategory
showUnreadCount={showUnreadCount}
key={category}
data={ids}
view={view}
expansion={expansion}
/>
)) :
!hideTitle && (
<div className="flex h-full flex-1 items-center text-zinc-500">
<Link
to="/discover"
className="-mt-36 flex h-full flex-1 flex-col items-center justify-center gap-2"
onClick={stopPropagation}
>
<i className="i-mgc-add-cute-re text-3xl" />
Add some feeds
</Link>
</div>
)}
</ScrollArea.ScrollArea>
</div>
)
}