chore: sync main to dev (#1535)

This commit is contained in:
Innei
2024-11-09 21:32:56 +08:00
committed by GitHub
15 changed files with 151 additions and 101 deletions
@@ -44,3 +44,6 @@ export const [
setSelectedFeedIds,
useSelectedFeedIdsSelector,
] = createAtomHooks(atom<string[]>([]))
export const [, , useFeedAreaScrollProgressValue, , , setFeedAreaScrollProgressValue] =
createAtomHooks(atom(0))
@@ -0,0 +1,10 @@
import { useDndContext } from "@dnd-kit/core"
import { useFeedAreaScrollProgressValue } from "./atom"
export function useShouldFreeUpSpace() {
const dndContext = useDndContext()
const isDragging = !!dndContext.active
const scrollProgress = useFeedAreaScrollProgressValue()
return isDragging && scrollProgress === 0
}
+42 -63
View File
@@ -1,6 +1,5 @@
import { DndContext, pointerWithin, useDroppable } from "@dnd-kit/core"
import { useDroppable } from "@dnd-kit/core"
import { ActionButton } from "@follow/components/ui/button/index.js"
import type { FeedViewType } from "@follow/constants"
import { Routes, views } from "@follow/constants"
import { useTypeScriptHappyCallback } from "@follow/hooks"
import { useRegisterGlobalContext } from "@follow/shared/bridge"
@@ -21,15 +20,15 @@ import { shortcuts } from "~/constants/shortcuts"
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
import { useReduceMotion } from "~/hooks/biz/useReduceMotion"
import { getRouteParams } from "~/hooks/biz/useRouteParams"
import { useBatchUpdateSubscription } from "~/hooks/biz/useSubscriptionActions"
import { useAuthQuery } from "~/hooks/common"
import { Queries } from "~/queries"
import { useSubscriptionStore } from "~/store/subscription"
import { useFeedUnreadStore } from "~/store/unread"
import { WindowUnderBlur } from "../../components/ui/background"
import { getSelectedFeedIds, setSelectedFeedIds, useSelectedFeedIds } from "./atom"
import { getSelectedFeedIds, setSelectedFeedIds } from "./atom"
import { FeedColumnHeader } from "./header"
import { useShouldFreeUpSpace } from "./hook"
import { FeedList } from "./list"
const lethargy = new Lethargy()
@@ -138,72 +137,52 @@ export function FeedColumn({ children, className }: PropsWithChildren<{ classNam
window.router.navigate(Routes.Discover)
})
const [selectedIds, setSelectedIds] = useSelectedFeedIds()
const { mutate } = useBatchUpdateSubscription()
const shouldFreeUpSpace = useShouldFreeUpSpace()
return (
<DndContext
collisionDetection={pointerWithin}
onDragEnd={(event) => {
if (!event.over) {
return
}
const { category, view } = event.over.data.current as {
category: string
view: FeedViewType
}
mutate({ category, view, feedIdList: selectedIds })
setSelectedIds([])
}}
<WindowUnderBlur
className={cn("relative flex h-full flex-col space-y-3 pt-2.5", className)}
onClick={useCallback(() => navigateBackHome(), [navigateBackHome])}
>
<WindowUnderBlur
className={cn("relative flex h-full flex-col space-y-3 pt-2.5", className)}
onClick={useCallback(() => navigateBackHome(), [navigateBackHome])}
<FeedColumnHeader />
<div
className="flex w-full justify-between px-3 text-xl text-theme-vibrancyFg"
onClick={stopPropagation}
>
<FeedColumnHeader />
<div
className="flex w-full justify-between px-3 text-xl text-theme-vibrancyFg"
onClick={stopPropagation}
>
{views.map((item, index) => (
<ViewSwitchButton
key={item.name}
item={item}
index={index}
active={active}
setActive={setActive}
useHotkeysSwitch={useHotkeysSwitch}
setUseHotkeysSwitch={setUseHotkeysSwitch}
/>
))}
</div>
<div
className={cn("relative flex size-full", !shouldFreeUpSpace && "overflow-hidden")}
ref={carouselRef}
onPointerDown={useTypeScriptHappyCallback((e) => {
if (!(e.target instanceof HTMLElement) || !e.target.closest("[data-feed-id]")) {
const nextSelectedFeedIds = getSelectedFeedIds()
setSelectedFeedIds(nextSelectedFeedIds.length === 0 ? nextSelectedFeedIds : [])
}
}, [])}
>
<SwipeWrapper active={active}>
{views.map((item, index) => (
<ViewSwitchButton
key={item.name}
item={item}
index={index}
active={active}
setActive={setActive}
useHotkeysSwitch={useHotkeysSwitch}
setUseHotkeysSwitch={setUseHotkeysSwitch}
/>
<section key={item.name} className="h-full w-feed-col shrink-0 snap-center">
<FeedList className="flex size-full flex-col text-sm" view={index} />
</section>
))}
</div>
<div
className="relative flex size-full"
ref={carouselRef}
onPointerDown={useTypeScriptHappyCallback((e) => {
if (!(e.target instanceof HTMLElement) || !e.target.closest("[data-feed-id]")) {
const nextSelectedFeedIds = getSelectedFeedIds()
setSelectedFeedIds(nextSelectedFeedIds.length === 0 ? nextSelectedFeedIds : [])
}
}, [])}
>
<SwipeWrapper active={active}>
{views.map((item, index) => (
<section key={item.name} className="h-full w-feed-col shrink-0 snap-center">
<FeedList className="flex size-full flex-col text-sm" view={index} />
</section>
))}
</SwipeWrapper>
</div>
</SwipeWrapper>
</div>
{children}
</WindowUnderBlur>
</DndContext>
{children}
</WindowUnderBlur>
)
}
+31 -2
View File
@@ -10,6 +10,7 @@ import { memo, useMemo, useRef, useState } from "react"
import { useTranslation } from "react-i18next"
import { Link } from "react-router-dom"
import Selecto from "react-selecto"
import { useEventListener } from "usehooks-ts"
import { IconOpacityTransition } from "~/components/ux/transition/icon"
import { FEED_COLLECTION_LIST } from "~/constants"
@@ -26,12 +27,14 @@ import { useFeedUnreadStore } from "~/store/unread"
import {
getFeedListSort,
setFeedAreaScrollProgressValue,
setFeedListSortBy,
setFeedListSortOrder,
useFeedListSort,
useSelectedFeedIds,
} from "./atom"
import { DraggableContext } from "./context"
import { useShouldFreeUpSpace } from "./hook"
import { SortableFeedList, SortByAlphabeticalInbox, SortByAlphabeticalList } from "./sort-by"
import { feedColumnStyles } from "./styles"
import { UnreadNumber } from "./unread-number"
@@ -161,6 +164,32 @@ function FeedListImpl({ className, view }: { className?: string; view: number })
[attributes, listeners, style],
)
useEventListener(
"scroll",
() => {
const round = (num: number) => Math.round(num * 1e2) / 1e2
const getPositions = () => {
const el = scrollerRef.current
if (!el) return
return {
x: round(el.scrollLeft / (el.scrollWidth - el.clientWidth)),
y: round(el.scrollTop / (el.scrollHeight - el.clientHeight)),
}
}
const newScrollValues = getPositions()
if (!newScrollValues) return
const { y } = newScrollValues
setFeedAreaScrollProgressValue(y)
},
scrollerRef,
{ capture: false, passive: true },
)
const shouldFreeUpSpace = useShouldFreeUpSpace()
return (
<div className={cn(className, "font-medium")}>
<ListHeader view={view} />
@@ -207,8 +236,8 @@ function FeedListImpl({ className, view }: { className?: string; view: number })
}}
mask={false}
flex
viewportClassName={cn("!px-3", isDragging && "!overflow-visible")}
rootClassName={cn("h-full", isDragging && "overflow-visible")}
viewportClassName={cn("!px-3", shouldFreeUpSpace && "!overflow-visible")}
rootClassName={cn("h-full", shouldFreeUpSpace && "overflow-visible")}
>
<div
data-active={feedId === FEED_COLLECTION_LIST}