refactor: remove view--1 (#4548)

This commit is contained in:
Stephen Zhou
2025-10-15 21:51:40 +08:00
committed by GitHub
parent 0f638f6c32
commit 35cd41e3fa
47 changed files with 359 additions and 321 deletions
@@ -7,6 +7,7 @@ export const QUERY_PERSIST_KEY = getStorageNS("REACT_QUERY_OFFLINE_CACHE")
export const I18N_LOCALE_KEY = getStorageNS("I18N_LOCALE")
/// Route Keys
export const ROUTE_VIEW_ALL = "all"
export const ROUTE_FEED_PENDING = "all"
export const ROUTE_ENTRY_PENDING = "pending"
export const ROUTE_FEED_IN_FOLDER = "folder-"
@@ -1,5 +1,5 @@
import { isMobile } from "@follow/components/hooks/useMobile.js"
import { FeedViewType, UserRole, views } from "@follow/constants"
import { FeedViewType, getView, UserRole } from "@follow/constants"
import { IN_ELECTRON } from "@follow/shared/constants"
import { useIsEntryStarred } from "@follow/store/collection/hooks"
import { useEntry } from "@follow/store/entry/hooks"
@@ -417,10 +417,7 @@ export const useEntryActions = ({ entryId, view }: { entryId: string; view: Feed
new EntryActionMenuItem({
id: COMMAND_ID.entry.readability,
onClick: runCmdFn(COMMAND_ID.entry.readability, [{ entryId, entryUrl: entry.url! }]),
hide:
!!entry.readability ||
(view && views.find((v) => v.view === view)?.wideMode) ||
!entry.url,
hide: !!entry.readability || (view && getView(view)?.wideMode) || !entry.url,
active: isEntryInReadability,
notice: !entry.doesContentContainsHTMLTags && !isEntryInReadability,
entryId,
@@ -1,7 +1,7 @@
import { getReadonlyRoute, getStableRouterNavigate } from "@follow/components/atoms/route.js"
import { useMobile } from "@follow/components/hooks/useMobile.js"
import { useSheetContext } from "@follow/components/ui/sheet/context.js"
import type { FeedViewType } from "@follow/constants"
import { FeedViewType } from "@follow/constants"
import { getEntry } from "@follow/store/entry/getter"
import { getSubscriptionByFeedId } from "@follow/store/subscription/getter"
import { tracker } from "@follow/tracker"
@@ -19,6 +19,7 @@ import {
ROUTE_FEED_IN_LIST,
ROUTE_FEED_PENDING,
ROUTE_TIMELINE_OF_VIEW,
ROUTE_VIEW_ALL,
} from "~/constants"
import { useRouteParamsSelector } from "./useRouteParams"
@@ -85,7 +86,8 @@ const parseNavigateEntryOptions = (options: NavigateEntryOptions): ParsedNavigat
finalFeedId = encodeURIComponent(finalFeedId)
if (finalView !== undefined && !timelineId) {
finalTimelineId = `${ROUTE_TIMELINE_OF_VIEW}${finalView}`
finalTimelineId =
finalView === FeedViewType.All ? ROUTE_VIEW_ALL : `${ROUTE_TIMELINE_OF_VIEW}${finalView}`
}
return {
@@ -17,6 +17,7 @@ import {
ROUTE_FEED_IN_LIST,
ROUTE_FEED_PENDING,
ROUTE_TIMELINE_OF_VIEW,
ROUTE_VIEW_ALL,
} from "~/constants"
export const useRouteEntryId = () => {
@@ -42,6 +43,16 @@ export interface BizRouteParams {
timelineId?: string
}
export function parseView(input: string | undefined): FeedViewType | undefined {
if (input === ROUTE_VIEW_ALL) return FeedViewType.All
if (input?.startsWith(ROUTE_TIMELINE_OF_VIEW)) {
const view = Number.parseInt(input?.slice(ROUTE_TIMELINE_OF_VIEW.length), 10)
if (Object.values(FeedViewType).includes(view)) {
return view as FeedViewType
}
}
}
const parseRouteParams = (params: Params<any>, _searchParams: URLSearchParams): BizRouteParams => {
const listId = params.feedId?.startsWith(ROUTE_FEED_IN_LIST)
? params.feedId.slice(ROUTE_FEED_IN_LIST.length)
@@ -49,12 +60,7 @@ const parseRouteParams = (params: Params<any>, _searchParams: URLSearchParams):
const list = listId ? getListById(listId) : undefined
return {
view: params.timelineId?.startsWith(ROUTE_TIMELINE_OF_VIEW)
? (Number.parseInt(
params.timelineId.slice(ROUTE_TIMELINE_OF_VIEW.length),
10,
) as FeedViewType)
: (list?.view ?? FeedViewType.Articles),
view: parseView(params.timelineId) ?? list?.view ?? FeedViewType.Articles,
entryId: params.entryId || undefined,
feedId: params.feedId || undefined,
// alias
@@ -1,22 +1,45 @@
import { FeedViewType } from "@follow/constants"
import { useViewWithSubscription } from "@follow/store/subscription/hooks"
import { useMemo } from "react"
import { useFeature } from "~/hooks/biz/useFeature"
import { useUISettingKey } from "~/atoms/settings/ui"
import { ROUTE_VIEW_ALL } from "~/constants/app"
export const useTimelineList = () => {
import { useFeature } from "./useFeature"
export const useTimelineList = (options?: {
ordered?: boolean
visible?: boolean
hidden?: boolean
withAll?: boolean
}) => {
const timelineTabs = useUISettingKey("timelineTabs")
const views = useViewWithSubscription()
// because the All view is highly tied to the AI
// so we need to filter it out if the AI is not enabled
const aiEnabled = useFeature("ai")
const filteredViews = useMemo(
() => (aiEnabled ? views : views.filter((v) => v !== FeedViewType.All)),
[views, aiEnabled],
)
const viewsIds = useMemo(() => {
const ids = views.map((view) => `view-${view}`)
if (!options?.ordered) {
return ids
}
const savedVisible = (timelineTabs?.visible ?? []).filter((id) => ids.includes(id))
const savedHidden = (timelineTabs?.hidden ?? []).filter((id) => ids.includes(id))
const extraHidden = ids.filter((id) => !savedVisible.includes(id) && !savedHidden.includes(id))
const viewsIds = useMemo(() => filteredViews.map((view) => `view-${view}`), [filteredViews])
if (options?.visible) return savedVisible
if (options?.hidden) return [...savedHidden, ...extraHidden]
return viewsIds
const ordered = [...savedVisible, ...savedHidden, ...extraHidden]
return ordered
}, [
options?.hidden,
options?.ordered,
options?.visible,
timelineTabs?.hidden,
timelineTabs?.visible,
views,
])
return useMemo(() => {
return options?.withAll && aiEnabled ? [ROUTE_VIEW_ALL, ...viewsIds] : viewsIds
}, [aiEnabled, options?.withAll, viewsIds])
}
@@ -1,4 +1,4 @@
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import { clsx, cn } from "@follow/utils/utils"
import type { FC, ReactNode } from "react"
import { memo } from "react"
@@ -78,21 +78,19 @@ type MainFeedBlock = ValueBlockOf<"mainFeed">
type UnreadOnlyBlock = ValueBlockOf<"unreadOnly">
export const CombinedContextBlock: FC<{
viewBlock: MainViewBlock
viewBlock?: MainViewBlock
feedBlock?: MainFeedBlock
unreadOnlyBlock?: UnreadOnlyBlock
}> = memo(({ viewBlock, feedBlock, unreadOnlyBlock }) => {
const { t } = useTranslation("common")
const blockActions = useChatBlockActions()
const viewIcon = views.find((v) => v.view === Number(viewBlock.value))?.icon.props.className
const canRemove =
!blockTypeCanNotBeRemoved.has(viewBlock.type) &&
(!feedBlock || !blockTypeCanNotBeRemoved.has(feedBlock.type))
const viewIcon = viewBlock && getView(Number(viewBlock.value))?.icon.props.className
const handleRemove = () => {
blockActions.removeBlock(viewBlock.id)
if (viewBlock) {
blockActions.removeBlock(viewBlock.id)
}
if (feedBlock) {
blockActions.removeBlock(feedBlock.id)
}
@@ -110,7 +108,8 @@ export const CombinedContextBlock: FC<{
) : (
<span className="flex items-center gap-1">
{(() => {
const viewName = views.find((v) => v.view === Number(viewBlock.value))?.name
if (!viewBlock) return null
const viewName = getView(Number(viewBlock.value))?.name
return viewName ? t(viewName) : viewBlock.value
})()}
{unreadOnlyBlock && <i className="i-mgc-round-cute-fi size-3" title="Unread Only" />}
@@ -120,7 +119,7 @@ export const CombinedContextBlock: FC<{
return (
<BlockContainer
icon={viewIcon}
canRemove={canRemove}
canRemove={true}
onRemove={handleRemove}
content={displayContent}
/>
@@ -135,7 +134,7 @@ export const ContextBlock: FC<{ block: AIChatContextBlock }> = memo(({ block })
const getBlockIcon = () => {
switch (block.type) {
case "mainView": {
const viewIcon = views.find((v) => v.view === Number(block.value))?.icon.props.className
const viewIcon = getView(Number(block.value))?.icon.props.className
return viewIcon
}
case "mainEntry": {
@@ -174,7 +173,7 @@ export const ContextBlock: FC<{ block: AIChatContextBlock }> = memo(({ block })
const getDisplayContent = () => {
switch (block.type) {
case "mainView": {
const viewName = views.find((v) => v.view === Number(block.value))?.name
const viewName = getView(Number(block.value))?.name
return viewName ? t(viewName) : block.value
}
case "mainEntry":
@@ -1,4 +1,4 @@
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import dayjs from "dayjs"
import { memo, useCallback } from "react"
import { useTranslation } from "react-i18next"
@@ -40,7 +40,7 @@ const Item = memo(
}) => {
const { feedId, title, image, siteUrl, category, subscribedAt, view } = sub
const { t } = useTranslation()
const currentView = views[view]
const currentView = getView(view)
if (currentView === undefined) {
return null
}
@@ -1,4 +1,5 @@
import { cn } from "@follow/utils/utils"
import { FeedViewType } from "@follow-app/client-sdk"
import { memo, useCallback, useEffect, useMemo, useRef } from "react"
import { useAISettingValue } from "~/atoms/settings/ai"
@@ -42,7 +43,7 @@ export const AIChatContextBar: Component<{ onSendShortcut?: (prompt: string) =>
return i.feedId
})
useEffect(() => {
if (typeof view === "number") {
if (typeof view === "number" && view !== FeedViewType.All) {
addOrUpdateBlock({
id: BlockSliceAction.SPECIAL_TYPES.mainView,
type: "mainView",
@@ -148,7 +149,7 @@ export const AIChatContextBar: Component<{ onSendShortcut?: (prompt: string) =>
if (item.kind === "combined") {
return (
<CombinedContextBlock
key={item.viewBlock.id}
key={`combined-${item.viewBlock?.id}-${item.feedBlock?.id}-${item.unreadOnlyBlock?.id}`}
viewBlock={item.viewBlock}
feedBlock={item.feedBlock}
unreadOnlyBlock={item.unreadOnlyBlock}
@@ -1,4 +1,4 @@
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import { cn } from "@follow/utils/utils"
import { t } from "i18next"
import * as React from "react"
@@ -25,7 +25,7 @@ type ValueBlockOf<Type extends ValueContextBlock["type"]> = Omit<ValueContextBlo
}
interface CombinedDataBlockItemProps {
viewBlock: ValueBlockOf<"mainView">
viewBlock?: ValueBlockOf<"mainView">
feedBlock?: ValueBlockOf<"mainFeed">
unreadOnlyBlock?: ValueBlockOf<"unreadOnly">
}
@@ -36,7 +36,7 @@ interface CombinedDataBlockItemProps {
const getDisplayContent = (block: AIChatContextBlock): React.ReactNode => {
switch (block.type) {
case "mainView": {
const viewName = views.find((v) => v.view === Number(block.value))?.name
const viewName = getView(Number(block.value))?.name
return viewName ? t(viewName, { ns: "common" }) : block.value
}
case "mainEntry":
@@ -162,23 +162,63 @@ AIDataBlockItem.displayName = "AIDataBlockItem"
*/
export const CombinedDataBlockItem: React.FC<CombinedDataBlockItemProps> = React.memo(
({ viewBlock, feedBlock, unreadOnlyBlock }) => {
const { styles, displayContent, title } = React.useMemo(() => {
const view = views.find((v) => v.view === Number(viewBlock.value))
const { styles, displayContent, title, block } = React.useMemo(() => {
const unreadOnlyText = unreadOnlyBlock ? " (Unread Only)" : ""
const unreadIcon = unreadOnlyBlock && (
<i className="i-mgc-round-cute-fi size-3" title="Unread Only" />
)
// Helper function to create content with optional unread indicator
const createContent = (mainContent: React.ReactNode) => (
<span className="flex items-center gap-1">
{mainContent}
{unreadIcon}
</span>
)
// Handle case when viewBlock is null/undefined
if (!viewBlock) {
// Prioritize feedBlock if available
if (feedBlock) {
return {
styles: getBlockStyles("mainFeed"),
displayContent: createContent(
<FeedTitle feedId={feedBlock.value} fallback={feedBlock.value} />,
),
title: `${feedBlock.value}${unreadOnlyText}`,
block: feedBlock,
}
}
// Handle unreadOnly-only case
if (unreadOnlyBlock) {
return {
styles: getBlockStyles("unreadOnly"),
displayContent: createContent("Unread Only"),
title: "Unread Only",
block: unreadOnlyBlock,
}
}
// Fallback case
const fallbackBlock = { id: "fallback", type: "mainView" as const, value: "" }
return {
styles: getBlockStyles("mainView"),
displayContent: createContent("No context"),
title: "No context",
block: fallbackBlock,
}
}
// Handle case when viewBlock exists
const view = getView(Number(viewBlock.value))
const viewName = view?.name ? t(view.name, { ns: "common" }) : viewBlock.value
const unreadOnlyText = unreadOnlyBlock ? " (Unread Only)" : ""
// Determine content based on whether feedBlock exists
const content = feedBlock ? (
<span className="flex items-center gap-1">
<FeedTitle feedId={feedBlock.value} fallback={feedBlock.value} />
{unreadOnlyBlock && <i className="i-mgc-round-cute-fi size-3" title="Unread Only" />}
</span>
// Determine primary content: feedBlock takes precedence over viewBlock
const primaryContent = feedBlock ? (
<FeedTitle feedId={feedBlock.value} fallback={feedBlock.value} />
) : (
<span className="flex items-center gap-1">
{viewName}
{unreadOnlyBlock && <i className="i-mgc-round-cute-fi size-3" title="Unread Only" />}
</span>
viewName
)
const titleText = feedBlock
@@ -187,18 +227,14 @@ export const CombinedDataBlockItem: React.FC<CombinedDataBlockItemProps> = React
return {
styles: getBlockStyles("mainView"),
displayContent: content,
displayContent: createContent(primaryContent),
title: titleText,
block: viewBlock,
}
}, [viewBlock.value, feedBlock, unreadOnlyBlock])
}, [viewBlock, feedBlock, unreadOnlyBlock])
return (
<BlockContainer
styles={styles}
block={viewBlock}
displayContent={displayContent}
title={title}
/>
<BlockContainer styles={styles} block={block} displayContent={displayContent} title={title} />
)
},
)
@@ -41,7 +41,7 @@ export const AIDataBlockPart: React.FC<AIDataBlockPartProps> = React.memo(({ blo
if (item.kind === "combined") {
return (
<CombinedDataBlockItem
key={item.viewBlock.id}
key={`combined-${item.viewBlock?.id}-${item.feedBlock?.id}-${item.unreadOnlyBlock?.id}`}
viewBlock={item.viewBlock}
feedBlock={item.feedBlock}
unreadOnlyBlock={item.unreadOnlyBlock}
@@ -1,4 +1,4 @@
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import type { AIChatContextBlock, FileAttachment } from "~/modules/ai-chat/store/types"
import {
@@ -103,7 +103,7 @@ export function getBlockIcon(block: AIChatContextBlock): string {
}
if (block.type === "mainView") {
const viewIcon = views.find((v) => v.view === Number(block.value))?.icon.props.className
const viewIcon = getView(Number(block.value))?.icon.props.className
return viewIcon
}
@@ -9,14 +9,14 @@ type ValueBlockOf<Type extends ValueContextBlock["type"]> = Omit<ValueContextBlo
export type DisplayBlockItem =
| {
kind: "combined"
viewBlock: ValueBlockOf<"mainView">
viewBlock?: ValueBlockOf<"mainView">
feedBlock?: ValueBlockOf<"mainFeed">
unreadOnlyBlock?: ValueBlockOf<"unreadOnly">
}
| { kind: "single"; block: AIChatContextBlock }
/**
* Custom hook to process blocks and merge mainView + mainFeed when both exist
* Custom hook to process blocks and merge mainView, mainFeed, and unreadOnly when any of them exist
* Returns an array of display items that can be either combined or single blocks
*/
export const useDisplayBlocks = (blocks: AIChatContextBlock[]): DisplayBlockItem[] => {
@@ -36,23 +36,22 @@ export const useDisplayBlocks = (blocks: AIChatContextBlock[]): DisplayBlockItem
(block): block is ValueBlockOf<"unreadOnly"> => block.type === "unreadOnly",
)
// Always filter out unreadOnly from single blocks since it should only appear in combined blocks
const filteredBlocks = blocks.filter((block) => block.type !== "unreadOnly")
if (mainViewBlock) {
// If any of the three special block types exist, create a combined block
if (mainViewBlock || mainFeedBlock || unreadOnlyBlock) {
const items: DisplayBlockItem[] = []
// Create combined block with optional feedBlock
// Create combined block with optional blocks
items.push({
kind: "combined",
viewBlock: mainViewBlock,
...(mainViewBlock && { viewBlock: mainViewBlock }),
...(mainFeedBlock && { feedBlock: mainFeedBlock }),
...(unreadOnlyBlock && { unreadOnlyBlock }),
})
// Add other blocks (excluding mainView, mainFeed, and unreadOnly)
const otherBlocks = filteredBlocks.filter(
(block) => block.id !== mainViewBlock.id && block.id !== mainFeedBlock?.id,
const otherBlocks = blocks.filter(
(block) =>
block.type !== "mainView" && block.type !== "mainFeed" && block.type !== "unreadOnly",
)
otherBlocks.forEach((block) => {
items.push({ kind: "single", block })
@@ -61,7 +60,7 @@ export const useDisplayBlocks = (blocks: AIChatContextBlock[]): DisplayBlockItem
return items
}
// If no mainView, show all blocks except unreadOnly
return filteredBlocks.map((block) => ({ kind: "single" as const, block }))
// If none of the special blocks exist, show all blocks as single blocks
return blocks.map((block) => ({ kind: "single" as const, block }))
}, [blocks])
}
@@ -1,5 +1,5 @@
import { PanelSplitter } from "@follow/components/ui/divider/index.js"
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import { defaultUISettings } from "@follow/shared/settings/defaults"
import { cn, isSafari } from "@follow/utils/utils"
import { useMemo, useRef } from "react"
@@ -39,7 +39,7 @@ export function TimelineEntryTwoColumnLayout() {
const entryColWidth = useMemo(() => getUISettings().entryColWidth, [])
const { view } = useRouteParams()
const inWideMode = (view ? views.find((v) => v.view === view)?.wideMode : false) || false
const inWideMode = (view ? getView(view)?.wideMode : false) || false
const feedColumnWidth = useUISettingKey("feedColWidth")
const startDragPosition = useRef(0)
const { position, separatorProps, isDragging, separatorCursor, setPosition } = useResizable({
@@ -1,4 +1,4 @@
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import { cn } from "@follow/utils/utils"
import { easeOut } from "motion/react"
import type { FC, PropsWithChildren } from "react"
@@ -24,10 +24,7 @@ const EntryLayoutContentLegacy = () => {
const settingWideMode = false
const realEntryId = entryId === ROUTE_ENTRY_PENDING ? "" : entryId
const showEntryContent = !(
views.find((v) => v.view === view)?.wideMode ||
(settingWideMode && !realEntryId)
)
const showEntryContent = !(getView(view)?.wideMode || (settingWideMode && !realEntryId))
const wideMode = !!(settingWideMode && realEntryId)
const feedColumnTempShow = useSubscriptionColumnTempShow()
const feedColumnShow = useSubscriptionColumnShow()
@@ -1,6 +1,6 @@
import { LoadingCircle } from "@follow/components/ui/loading/index.js"
import type { FeedViewType } from "@follow/constants"
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import { cn } from "@follow/utils/utils"
import type { FC } from "react"
import { memo } from "react"
@@ -28,11 +28,7 @@ export const EntryItemSkeleton: FC<{
}
return (
<div
className={cn(
views.find((v) => v.view === view)?.gridMode ? girdClassNames : "flex flex-col",
)}
>
<div className={cn(getView(view)?.gridMode ? girdClassNames : "flex flex-col")}>
{Array.from({ length: count }).map((_, index) => (
// eslint-disable-next-line @eslint-react/no-array-index-key -- index is unique
<div key={index}>{SkeletonItem}</div>
@@ -1,4 +1,4 @@
import { FeedViewType, views } from "@follow/constants"
import { FeedViewType, getView } from "@follow/constants"
import { readableContentMaxWidthClassName } from "~/constants/ui"
@@ -19,7 +19,7 @@ export const FooterMarkItem = ({
if (view === FeedViewType.SocialMedia) {
return <SocialMediaFooterMarkItem filter={filter} />
} else if (views.find((v) => v.view === view)?.gridMode || view === FeedViewType.All) {
} else if (getView(view)?.gridMode || view === FeedViewType.All) {
return <GridFooterMarkItem filter={filter} />
}
return <CommonFooterMarkItem filter={filter} />
@@ -1,5 +1,5 @@
import { ScrollArea } from "@follow/components/ui/scroll-area/ScrollArea.js"
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import { cn } from "@follow/utils/utils"
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
@@ -15,10 +15,7 @@ export const EntryColumnWrapper = ({ ref, children, onScroll }: EntryColumnWrapp
return (
<div className={cn(styles, animationStyles)}>
<ScrollArea
scrollbarClassName={cn(
!views.find((v) => v.view === view)?.wideMode ? "w-[5px] p-0" : "",
"z-[3]",
)}
scrollbarClassName={cn(!getView(view)?.wideMode ? "w-[5px] p-0" : "", "z-[3]")}
mask={false}
ref={ref}
rootClassName="h-full"
@@ -1,4 +1,4 @@
import { FeedViewType, views } from "@follow/constants"
import { FeedViewType, getView } from "@follow/constants"
import { useCollectionEntryList } from "@follow/store/collection/hooks"
import {
useEntriesQuery,
@@ -268,7 +268,7 @@ export const useEntriesByView = ({ onReset }: { onReset?: () => void }) => {
const groupByDate = useGeneralSettingKey("groupByDate")
const groupedCounts: number[] | undefined = useMemo(() => {
const viewDefinition = views.find((v) => v.view === view)
const viewDefinition = getView(view)
if (viewDefinition?.gridMode || view === FeedViewType.All) {
return
}
@@ -1,4 +1,4 @@
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import { entryActions } from "@follow/store/entry/store"
import { unreadSyncService } from "@follow/store/unread/store"
import type { Range } from "@tanstack/react-virtual"
@@ -33,7 +33,7 @@ export const useEntryMarkReadHandler = (entriesIds: string[]) => {
)
return useMemo(() => {
if (views.find((v) => v.view === feedView)?.wideMode && renderAsRead) {
if (getView(feedView)?.wideMode && renderAsRead) {
return handleRenderAsRead
}
@@ -1,5 +1,5 @@
import type { FeedViewType } from "@follow/constants"
import { getFolderFeedsByFeedId } from "@follow/store/subscription/getter"
import { getCategoryFeedIds } from "@follow/store/subscription/getter"
import { unreadSyncService } from "@follow/store/unread/store"
import { getGeneralSettings } from "~/atoms/settings/general"
@@ -25,10 +25,7 @@ export const markAllByRoute = async (
time?: MarkAllFilter,
) => {
const { feedId, view, inboxId, listId, isAllFeeds } = data
const folderIds = getFolderFeedsByFeedId({
feedId,
view,
})
const folderIds = getCategoryFeedIds(feedId, view)
if (!feedId) return
@@ -1,4 +1,4 @@
import { FeedViewType, views } from "@follow/constants"
import { FeedViewType, getView } from "@follow/constants"
import { useTitle } from "@follow/hooks"
import { useEntry } from "@follow/store/entry/hooks"
import { useFeedById } from "@follow/store/feed/hooks"
@@ -118,7 +118,7 @@ function EntryColumnContent() {
}
if (!renderAsRead) return
if (!views.find((v) => v.view === view)?.wideMode) {
if (!getView(view)?.wideMode) {
return
}
// For gird, render as mark read logic
@@ -133,7 +133,7 @@ function EntryColumnContent() {
}
}, [actions, state.hasNextPage, state.isFetchingNextPage])
const ListComponent = views.find((v) => v.view === view)?.gridMode ? EntryColumnGrid : EntryList
const ListComponent = getView(view)?.gridMode ? EntryColumnGrid : EntryList
return (
<Focusable
@@ -2,7 +2,7 @@ import { useGlobalFocusableScopeSelector } from "@follow/components/common/Focus
import { useMobile } from "@follow/components/hooks/useMobile.js"
import { getMousePosition } from "@follow/components/hooks/useMouse.js"
import { ActionButton } from "@follow/components/ui/button/action-button.js"
import { FeedViewType, views } from "@follow/constants"
import { FeedViewType, getView } from "@follow/constants"
import { useEntry } from "@follow/store/entry/hooks"
import { unreadSyncService } from "@follow/store/unread/store"
import { cn } from "@follow/utils/utils"
@@ -142,7 +142,7 @@ export const EntryItemWrapper: FC<
})
const aiEnabled = useFeature("ai")
const isWide = views.find((v) => v.view === view)?.wideMode || aiEnabled
const isWide = getView(view)?.wideMode || aiEnabled
const Link = view === FeedViewType.SocialMedia ? "article" : NavLink
const isAll = view === FeedViewType.All
@@ -2,7 +2,7 @@ import { ActionButton, MotionButtonBase } from "@follow/components/ui/button/ind
import { DividerVertical } from "@follow/components/ui/divider/index.js"
import { RotatingRefreshIcon } from "@follow/components/ui/loading/index.jsx"
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js"
import { FeedViewType, views } from "@follow/constants"
import { FeedViewType, getView } from "@follow/constants"
import { useIsOnline } from "@follow/hooks"
import { getFeedById } from "@follow/store/feed/getter"
import { useFeedById } from "@follow/store/feed/hooks"
@@ -108,17 +108,15 @@ export const EntryListHeader: FC<{
)}
onClick={stopPropagation}
>
{views.find((v) => v.view === view)?.wideMode &&
entryId &&
entryId !== ROUTE_ENTRY_PENDING && (
<>
<EntryHeader entryId={entryId} />
<DividerVertical className="mx-2 w-px" />
</>
)}
{getView(view)?.wideMode && entryId && entryId !== ROUTE_ENTRY_PENDING && (
<>
<EntryHeader entryId={entryId} />
<DividerVertical className="mx-2 w-px" />
</>
)}
<AppendTaildingDivider>
{!views.find((v) => v.view === view)?.wideMode && !aiEnabled && <WideModeButton />}
{!getView(view)?.wideMode && !aiEnabled && <WideModeButton />}
{view === FeedViewType.Pictures && <SwitchToMasonryButton />}
</AppendTaildingDivider>
@@ -1,5 +1,5 @@
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import { getEntry, getEntryIdsByFeedId } from "@follow/store/entry/getter"
import { useFeedById } from "@follow/store/feed/hooks"
import { useListById } from "@follow/store/list/hooks"
@@ -226,7 +226,7 @@ export function EntryHeaderBreadcrumb() {
const { t } = useTranslation()
const view = useRouteParamsSelector((s) => s.view)
const viewName = views.find((v) => v.view === view)?.name
const viewName = getView(view)?.name
return (
<div className="flex min-w-0 flex-1 overflow-hidden">
@@ -1,4 +1,4 @@
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import { cn } from "@follow/utils/utils"
import { memo } from "react"
@@ -14,7 +14,7 @@ function EntryHeaderReadHistoryImpl({ className }: { className?: string }) {
const { entryId } = useEntryHeaderContext()
const { view } = useRouteParams()
const isAtTop = useEntryContentScrollToTop()
const isWide = views[view]?.wideMode
const isWide = getView(view)?.wideMode
if (!isAtTop || hideRecentReader) return null
return (
@@ -1,5 +1,5 @@
import { SelectContent, SelectItem } from "@follow/components/ui/select/index.jsx"
import { FeedViewType, views } from "@follow/constants"
import { getViewList } from "@follow/constants"
import { cn } from "@follow/utils/utils"
import { useTranslation } from "react-i18next"
@@ -8,16 +8,14 @@ export const ViewSelectContent = () => {
return (
<SelectContent>
{views
.filter((view) => view.view !== FeedViewType.All)
.map((view, index) => (
<SelectItem key={view.name} value={`${index}`}>
<div className="flex items-center gap-2">
<span className={cn(view.className, "flex")}>{view.icon}</span>
<span>{t(view.name, { ns: "common" })}</span>
</div>
</SelectItem>
))}
{getViewList().map((view, index) => (
<SelectItem key={view.name} value={`${index}`}>
<div className="flex items-center gap-2">
<span className={cn(view.className, "flex")}>{view.icon}</span>
<span>{t(view.name, { ns: "common" })}</span>
</div>
</SelectItem>
))}
</SelectContent>
)
}
@@ -20,7 +20,7 @@ import {
TooltipTrigger,
} from "@follow/components/ui/tooltip/index.js"
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js"
import { views } from "@follow/constants"
import { getView, getViewList } from "@follow/constants"
import { getFeedById } from "@follow/store/feed/getter"
import { useFeedById, usePrefetchFeedAnalytics } from "@follow/store/feed/hooks"
import { getSubscriptionByFeedId } from "@follow/store/subscription/getter"
@@ -394,7 +394,7 @@ const ViewSelector: FC<{ selectedFeeds: Set<string> }> = ({ selectedFeeds }) =>
const { t: tCommon } = useTranslation("common")
const { mutate: batchUpdateSubscription } = useBatchUpdateSubscription()
const { ask } = useDialog()
return views.map((view) => {
return getViewList().map((view) => {
return (
<DropdownMenuItem
key={view.view}
@@ -480,8 +480,8 @@ const FeedListItem = memo(
</div>
<div className="text-text flex items-center gap-1 text-sm opacity-80">
{views.find((v) => v.view === subscription.view)!.icon}
<span>{tCommon(views.find((v) => v.view === subscription.view)!.name)}</span>
{getView(subscription.view)!.icon}
<span>{tCommon(getView(subscription.view)!.name)}</span>
</div>
{!!subscription.createdAt && (
<div className="whitespace-nowrap pr-1 text-center text-sm">
@@ -17,7 +17,7 @@ import {
TooltipPortal,
TooltipTrigger,
} from "@follow/components/ui/tooltip/index.jsx"
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import { useOwnedLists, usePrefetchLists } from "@follow/store/list/hooks"
import { listSyncServices } from "@follow/store/list/store"
import { cn, formatNumber } from "@follow/utils/utils"
@@ -157,15 +157,15 @@ export const SettingLists = () => {
<span
className={cn(
"inline-flex items-center",
views.find((v) => v.view === row.view)?.className,
getView(row.view)?.className,
)}
>
{views.find((v) => v.view === row.view)?.icon}
{getView(row.view)?.icon}
</span>
</TooltipTrigger>
<TooltipPortal>
<TooltipContent>
{t(views.find((v) => v.view === row.view)!.name, {
{t(getView(row.view)!.name, {
ns: "common",
})}
</TooltipContent>
@@ -20,7 +20,7 @@ import {
TableHeader,
TableRow,
} from "@follow/components/ui/table/index.jsx"
import { views } from "@follow/constants"
import { FeedViewType } from "@follow/constants"
import { getFeedById } from "@follow/store/feed/getter"
import { useFeedById } from "@follow/store/feed/hooks"
import { useListById } from "@follow/store/list/hooks"
@@ -62,7 +62,7 @@ export const ListCreationModalContent = ({ id }: { id?: string }) => {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
view: list?.view.toString() || views[0]?.view.toString(),
view: list?.view.toString() || FeedViewType.Articles.toString(),
fee: list?.fee || 0,
title: list?.title || "",
description: list?.description || "",
@@ -1,5 +1,5 @@
import { Card, CardContent, CardHeader } from "@follow/components/ui/card/index.jsx"
import { FeedViewType, views } from "@follow/constants"
import { FeedViewType, getView, getViewList } from "@follow/constants"
import type { FeedModel } from "@follow/store/feed/types"
import { cn } from "@follow/utils/utils"
import type { ParsedEntry } from "@follow-app/client-sdk"
@@ -32,7 +32,7 @@ export const ViewSelectorRadioGroup = ({
return (
<Card className={rest.disabled ? "pointer-events-none" : void 0}>
<CardHeader className={cn("grid grid-cols-6 space-y-0 px-2 py-3", className)}>
{views
{getViewList()
.filter((v) => v.switchable)
.map((view) => (
<div key={view.name}>
@@ -68,7 +68,7 @@ export const ViewSelectorRadioGroup = ({
{showPreview && (
<CardContent
className={
views[view || FeedViewType.Articles]?.gridMode
getView(view || FeedViewType.Articles)?.gridMode
? "relative grid w-full grid-cols-3 flex-col gap-2 pb-4"
: "relative flex w-full flex-col gap-2 pb-0"
}
@@ -5,7 +5,7 @@ import { LoadingCircle } from "@follow/components/ui/loading/index.jsx"
import { useScrollViewElement } from "@follow/components/ui/scroll-area/hooks.js"
import { ShrinkingFocusBorder } from "@follow/components/ui/shrinking-focus-border/index.js"
import type { FeedViewType } from "@follow/constants"
import { views } from "@follow/constants"
import { getViewList } from "@follow/constants"
import { useInputComposition, useRefValue } from "@follow/hooks"
import { useFeedStore } from "@follow/store/feed/store"
import { useOwnedListByView } from "@follow/store/list/hooks"
@@ -228,7 +228,7 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego
MenuItemSeparator.default,
new MenuItemText({
label: t("sidebar.feed_column.context_menu.change_to_other_view"),
submenu: views
submenu: getViewList()
.filter((v) => v.view !== view && v.switchable)
.map(
(v) =>
@@ -1,7 +1,6 @@
import { useDroppable } from "@dnd-kit/core"
import { ActionButton } from "@follow/components/ui/button/index.js"
import type { FeedViewType } from "@follow/constants"
import { views } from "@follow/constants"
import { FeedViewType, getView } from "@follow/constants"
import { useUnreadByView } from "@follow/store/unread/hooks"
import { cn } from "@follow/utils/utils"
import type { FC } from "react"
@@ -10,9 +9,8 @@ import { useTranslation } from "react-i18next"
import { useUISettingKey } from "~/atoms/settings/ui"
import { FocusablePresets } from "~/components/common/Focusable"
import { ROUTE_TIMELINE_OF_VIEW } from "~/constants"
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
import { parseView, useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
import { resetSelectedFeedIds } from "./atom"
@@ -36,14 +34,62 @@ export function SubscriptionTabButton({
resetSelectedFeedIds()
}, [navigate, timelineId])
if (timelineId.startsWith(ROUTE_TIMELINE_OF_VIEW)) {
const id = Number.parseInt(timelineId.slice(ROUTE_TIMELINE_OF_VIEW.length), 10) as FeedViewType
const view = parseView(timelineId)
if (view === FeedViewType.All) {
return <ViewAllSwitchButton isActive={isActive} setActive={setActive} shortcut={shortcut} />
} else if (typeof view === "number") {
return (
<ViewSwitchButton view={id} isActive={isActive} setActive={setActive} shortcut={shortcut} />
<ViewSwitchButton view={view} isActive={isActive} setActive={setActive} shortcut={shortcut} />
)
}
}
const ViewAllSwitchButton: FC<{
isActive: boolean
setActive: () => void
shortcut: string
}> = ({ isActive, setActive, shortcut }) => {
const unreadByView = useUnreadByView(FeedViewType.All)
const { t } = useTranslation()
const showSidebarUnreadCount = useUISettingKey("sidebarShowUnreadCount")
const item = getView(FeedViewType.All)
return (
<ActionButton
shortcutScope={FocusablePresets.isNotFloatingLayerScope}
key={item.name}
tooltip={t(item.name, { ns: "common" })}
shortcut={shortcut}
className={cn(
isActive && item.className,
"flex h-11 w-8 shrink-0 grow flex-col items-center gap-1 text-[1.375rem]",
ELECTRON ? "hover:!bg-theme-item-hover" : "",
)}
onClick={(e) => {
startTransition(() => {
setActive()
})
e.stopPropagation()
}}
>
{item.icon}
{showSidebarUnreadCount ? (
<div className="text-[0.625rem] font-medium leading-none">
{unreadByView > 99 ? <span className="-mr-0.5">99+</span> : unreadByView}
</div>
) : (
<i
className={cn(
"i-mgc-round-cute-fi text-[0.25rem]",
unreadByView ? (isActive ? "opacity-100" : "opacity-60") : "opacity-0",
)}
/>
)}
</ActionButton>
)
}
const ViewSwitchButton: FC<{
view: FeedViewType
isActive: boolean
@@ -53,7 +99,7 @@ const ViewSwitchButton: FC<{
const unreadByView = useUnreadByView(view)
const { t } = useTranslation()
const showSidebarUnreadCount = useUISettingKey("sidebarShowUnreadCount")
const item = views.find((item) => item.view === view)!
const item = getView(view)
const { isOver, setNodeRef } = useDroppable({
id: `view-${item.name}`,
@@ -17,14 +17,14 @@ import {
} from "@dnd-kit/sortable"
import { CSS } from "@dnd-kit/utilities"
import { Button } from "@follow/components/ui/button/index.js"
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import type { CSSProperties, ReactNode } from "react"
import { useCallback, useMemo } from "react"
import { useTranslation } from "react-i18next"
import { setUISetting, useUISettingKey } from "~/atoms/settings/ui"
import { setUISetting } from "~/atoms/settings/ui"
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
import { ROUTE_TIMELINE_OF_VIEW } from "~/constants"
import { parseView } from "~/hooks/biz/useRouteParams"
import { useTimelineList } from "~/hooks/biz/useTimelineList"
const MAX_VISIBLE = 5
@@ -44,9 +44,9 @@ function ContainerDroppable({ id, children }: { id: "visible" | "hidden"; childr
}
function getViewMeta(timelineId: string) {
if (!timelineId.startsWith(ROUTE_TIMELINE_OF_VIEW)) return { name: timelineId, icon: null }
const id = Number.parseInt(timelineId.slice(ROUTE_TIMELINE_OF_VIEW.length), 10)
const item = views.find((v) => v.view === id)
const id = parseView(timelineId)
if (typeof id !== "number") return { name: timelineId, icon: null }
const item = getView(id)
return { name: item?.name ?? String(id), icon: item?.icon ?? null }
}
@@ -88,22 +88,10 @@ function SortableTabItem({ id }: { id: UniqueIdentifier }) {
}
function useResolvedTimelineTabs() {
const timelineTabs = useUISettingKey("timelineTabs")
const timelineList = useTimelineList()
const first = timelineList[0]
const rest = timelineList.slice(1)
const timelineList = useTimelineList({ ordered: true, visible: true })
const timelineListHidden = useTimelineList({ ordered: true, hidden: true })
// Resolve visible: keep saved order, ensure they exist in rest, cap at MAX_VISIBLE
const savedVisible = (timelineTabs?.visible ?? []).filter((id) => rest.includes(id))
const filledVisible = [...savedVisible]
for (const id of rest) {
if (filledVisible.length >= MAX_VISIBLE) break
if (!filledVisible.includes(id)) filledVisible.push(id)
}
const hidden = rest.filter((id) => !filledVisible.includes(id))
return { first, visible: filledVisible, hidden }
return { visible: timelineList, hidden: timelineListHidden }
}
const TimelineTabsSettings = () => {
@@ -242,11 +230,9 @@ const TimelineTabsSettings = () => {
<Button
variant="outline"
onClick={() => {
// reset to current timeline order: first 4 visible, rest hidden
const rest = timelineListForReset.slice(1)
setUISetting("timelineTabs", {
visible: rest.slice(0, MAX_VISIBLE),
hidden: rest.slice(MAX_VISIBLE),
visible: timelineListForReset.slice(0, MAX_VISIBLE),
hidden: timelineListForReset.slice(MAX_VISIBLE),
})
}}
>
@@ -13,7 +13,7 @@ import { useWheel } from "@use-gesture/react"
import { Lethargy } from "lethargy"
import { AnimatePresence, m } from "motion/react"
import type { FC, PropsWithChildren } from "react"
import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"
import { memo, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react"
import { useRootContainerElement } from "~/atoms/dom"
import { useUISettingKey } from "~/atoms/settings/ui"
@@ -23,11 +23,10 @@ import {
useSubscriptionColumnShow,
} from "~/atoms/sidebar"
import { Focusable } from "~/components/common/Focusable"
import { HotkeyScope, ROUTE_TIMELINE_OF_VIEW } from "~/constants"
import { useFeature } from "~/hooks/biz/useFeature"
import { HotkeyScope } from "~/constants"
import { useBackHome } from "~/hooks/biz/useNavigateEntry"
import { useReduceMotion } from "~/hooks/biz/useReduceMotion"
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
import { parseView, useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
import { useTimelineList } from "~/hooks/biz/useTimelineList"
import { WindowUnderBlur } from "../../components/ui/background"
@@ -49,7 +48,11 @@ export function SubscriptionColumn({
usePrefetchUnread()
const carouselRef = useRef<HTMLDivElement>(null)
const timelineList = useTimelineList()
const timelineList = useTimelineList({
withAll: true,
ordered: true,
visible: true,
})
const routeParams = useRouteParamsSelector((s) => ({
timelineId: s.timelineId,
@@ -165,12 +168,7 @@ export function SubscriptionColumn({
<section key={timelineId} className="w-feed-col h-full shrink-0 snap-center">
<SubscriptionListGuard
key={timelineId}
view={
Number.parseInt(
timelineId.slice(ROUTE_TIMELINE_OF_VIEW.length),
10,
) as FeedViewType
}
view={parseView(timelineId) ?? FeedViewType.Articles}
isSubscriptionLoading={isSubscriptionLoading}
/>
</section>
@@ -192,24 +190,13 @@ const ApronNodeContainer: FC = () => {
const SwipeWrapper: FC<{ active: string; children: React.JSX.Element[] }> = memo(
({ children, active }) => {
const reduceMotion = useReduceMotion()
const timelineList = useTimelineList()
const timelineList = useTimelineList({ withAll: true, ordered: true, visible: true })
const viewIndex = timelineList.indexOf(active)
const feedColumnWidth = useUISettingKey("feedColWidth")
const timelineTabs = useUISettingKey("timelineTabs")
const containerRef = useRef<HTMLDivElement>(null)
// Use custom ordering for direction calculation
const orderedForDirection = useMemo(() => {
if (timelineList.length === 0) return [] as string[]
const first = timelineList[0]
const rest = timelineList.slice(1)
const savedVisible = (timelineTabs?.visible ?? []).filter((id) => rest.includes(id))
const ordered = [first, ...savedVisible, ...rest.filter((id) => !savedVisible.includes(id))]
return ordered
}, [timelineList, timelineTabs])
const orderIndex = orderedForDirection.indexOf(active)
const orderIndex = timelineList.indexOf(active)
const prevOrderIndexRef = useRef(-1)
const [isReady, setIsReady] = useState(false)
@@ -258,41 +245,11 @@ const SwipeWrapper: FC<{ active: string; children: React.JSX.Element[] }> = memo
)
const TabsRow: FC = () => {
const aiEnabled = useFeature("ai")
const timelineList = useTimelineList()
const timelineTabs = useUISettingKey("timelineTabs")
if (!aiEnabled) {
return (
<div className="text-text-secondary flex h-11 items-center gap-0 px-3 text-xl">
{timelineList.map((timelineId, index) => (
<SubscriptionTabButton
key={timelineId}
timelineId={timelineId}
shortcut={`${index + 1}`}
/>
))}
</div>
)
}
const first = timelineList[0]
const rest = timelineList.slice(1)
const savedVisible = (timelineTabs?.visible ?? []).filter((id) => rest.includes(id))
const visible: string[] = [...savedVisible]
for (const id of rest) {
if (visible.length >= 5) break
if (!visible.includes(id)) visible.push(id)
}
const timelineList = useTimelineList({ withAll: true, ordered: true, visible: true })
return (
<div className="text-text-secondary flex h-11 items-center px-1 text-xl">
<SubscriptionTabButton
shortcut="BackQuote"
key={first}
timelineId={`${ROUTE_TIMELINE_OF_VIEW}${FeedViewType.All}`}
/>
{visible.map((timelineId, index) => (
{timelineList.map((timelineId, index) => (
<SubscriptionTabButton key={timelineId} timelineId={timelineId} shortcut={`${index + 1}`} />
))}
</div>
@@ -1,5 +1,5 @@
import type { FeedViewType } from "@follow/constants"
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import { useCategoryOpenStateByView } from "@follow/store/subscription/hooks"
import { subscriptionActions } from "@follow/store/subscription/store"
import { useUnreadByView } from "@follow/store/unread/hooks"
@@ -36,7 +36,10 @@ export const ListHeader = ({ view }: { view: FeedViewType }) => {
}
}}
>
{view !== undefined && t(views.find((v) => v.view === view)!.name, { ns: "common" })}
{view !== undefined &&
t(getView(view).name, {
ns: "common",
})}
</div>
<div className="text-text-secondary ml-2 flex items-center gap-3 text-base lg:text-sm">
<SortButton />
@@ -1,7 +1,7 @@
import { useScrollElementUpdate } from "@follow/components/ui/scroll-area/hooks.js"
import { ResponsiveSelect } from "@follow/components/ui/select/responsive.js"
import { Skeleton } from "@follow/components/ui/skeleton/index.jsx"
import { FeedViewType, views } from "@follow/constants"
import { getViewList } from "@follow/constants"
import { cn } from "@follow/utils/utils"
import { useQuery } from "@tanstack/react-query"
import { useEffect, useState } from "react"
@@ -34,12 +34,10 @@ const viewOptions = [
label: "words.all",
value: "all",
},
...views
.filter((view) => view.view !== FeedViewType.All)
.map((view) => ({
label: view.name,
value: `${view.view}`,
})),
...getViewList().map((view) => ({
label: view.name,
value: `${view.view}`,
})),
]
type View = (typeof viewOptions)[number]["value"]
@@ -1,7 +1,12 @@
import { FeedViewType } from "@follow/constants"
import { redirect } from "react-router"
import { ROUTE_ENTRY_PENDING, ROUTE_FEED_PENDING } from "~/constants"
import {
ROUTE_ENTRY_PENDING,
ROUTE_FEED_PENDING,
ROUTE_TIMELINE_OF_VIEW,
ROUTE_VIEW_ALL,
} from "~/constants"
import { getFeature } from "~/hooks/biz/useFeature"
export function Component() {
@@ -10,6 +15,7 @@ export function Component() {
export const loader = () => {
const aiEnabled = getFeature("ai")
const view = aiEnabled ? FeedViewType.All : FeedViewType.Articles
return redirect(`/timeline/view-${view}/${ROUTE_FEED_PENDING}/${ROUTE_ENTRY_PENDING}`)
return redirect(
`/timeline/${aiEnabled ? ROUTE_VIEW_ALL : `${ROUTE_TIMELINE_OF_VIEW}${FeedViewType.Articles}`}/${ROUTE_FEED_PENDING}/${ROUTE_ENTRY_PENDING}`,
)
}
@@ -1,4 +1,4 @@
import { views } from "@follow/constants"
import { getView } from "@follow/constants"
import type { EntryModel } from "@follow/store/entry/types"
import { useFeedById, usePrefetchFeed } from "@follow/store/feed/hooks"
import { feedIconSelector } from "@follow/store/feed/selectors"
@@ -50,7 +50,9 @@ export const useFeedHeaderTitle = () => {
switch (currentFeedId) {
case ROUTE_FEED_PENDING: {
return t(views.find((v) => v.view === view)!.name, { ns: "common" })
return t(getView(view).name, {
ns: "common",
})
}
case FEED_COLLECTION_LIST: {
return t("words.starred")
+8 -10
View File
@@ -1,5 +1,5 @@
import type { ViewDefinition as ViewDefinitionBase } from "@follow/constants"
import { FeedViewType, views as viewsBase } from "@follow/constants"
import { FeedViewType, getViewList } from "@follow/constants"
import { AnnouncementCuteFiIcon } from "../icons/announcement_cute_fi"
import { BubbleCuteFiIcon } from "../icons/bubble_cute_fi"
@@ -39,12 +39,10 @@ const extendMap: Record<FeedViewType, ViewDefinitionExtended> = {
export interface ViewDefinition extends Omit<ViewDefinitionBase, "icon">, ViewDefinitionExtended {}
export const views: ViewDefinition[] = viewsBase
.filter((view) => view.view !== FeedViewType.All)
.map((view) => {
const extendedView = extendMap[view.view]
return {
...view,
...extendedView,
}
})
export const views: ViewDefinition[] = getViewList().map((view) => {
const extendedView = extendMap[view.view]
return {
...view,
...extendedView,
}
})
@@ -24,7 +24,7 @@ export function PagerList({
const selectedFeed = useSelectedFeed()
const viewId = selectedFeed?.type === "view" ? selectedFeed.viewId : undefined
const activeViews = useViewWithSubscription({ excludeAll: true })
const activeViews = useViewWithSubscription()
const activeViewIndex = useMemo(
() => activeViews.indexOf(viewId as FeedViewType),
[activeViews, viewId],
+1 -1
View File
@@ -32,7 +32,7 @@ export function PagerList({
const selectedFeed = useSelectedFeed()
const viewId = selectedFeed?.type === "view" ? selectedFeed.viewId : undefined
const activeViews = useViewWithSubscription({ excludeAll: true })
const activeViews = useViewWithSubscription()
const activeViewIndex = useMemo(
() => activeViews.indexOf(viewId as FeedViewType),
@@ -26,7 +26,7 @@ const ACTIVE_WIDTH = 180
const INACTIVE_WIDTH = 48
const ACTIVE_TEXT_WIDTH = 100
export function TimelineViewSelector() {
const activeViews = useViewWithSubscription({ excludeAll: true })
const activeViews = useViewWithSubscription()
const scrollViewRef = React.useRef<ScrollView | null>(null)
const selectedFeed = useSelectedFeed()
return (
@@ -77,7 +77,7 @@ function ItemWrapper({
style?: Exclude<StyleProp<ViewStyle>, number>
}) {
const { width: windowWidth } = useWindowDimensions()
const activeViews = useViewWithSubscription({ excludeAll: true })
const activeViews = useViewWithSubscription()
const dragProgress = useTimelineSelectorDragProgress()
const activeWidth = Math.max(
windowWidth - (INACTIVE_WIDTH + 12) * (activeViews.length - 1) - 8 * 2,
+1 -1
View File
@@ -400,7 +400,7 @@ export const TimelineSelectorDragProgressProvider = ({ children }: { children: R
const selectedFeed = useSelectedFeed()
const viewId = selectedFeed?.type === "view" ? selectedFeed.viewId : undefined
const activeViews = useViewWithSubscription({ excludeAll: true })
const activeViews = useViewWithSubscription()
const activeViewIndex = useMemo(
() => activeViews.indexOf(viewId as FeedViewType),
+28 -12
View File
@@ -22,17 +22,22 @@ export interface ViewDefinition {
/** if it's switchable from other views to this view by user */
switchable: boolean
}
export const views: ViewDefinition[] = [
{
name: "feed_view_type.all",
icon: <i className="i-mgc-bubble-cute-fi" />,
className: "text-folo",
peerClassName: "peer-checked:text-folo dark:peer-checked:text-folo",
translation: "title,description,content",
view: FeedViewType.All,
activeColor: "#FF5C00",
switchable: false,
},
const viewAll: ViewDefinition = {
name: "feed_view_type.all",
icon: <i className="i-mgc-bubble-cute-fi" />,
className: "text-folo",
peerClassName: "peer-checked:text-folo dark:peer-checked:text-folo",
translation: "title,description,content",
view: FeedViewType.All,
activeColor: "#FF5C00",
switchable: false,
}
/**
* Subscription views only
*/
const views: ViewDefinition[] = [
{
name: "feed_view_type.articles",
icon: <i className="i-mgc-paper-cute-fi" />,
@@ -105,4 +110,15 @@ export const views: ViewDefinition[] = [
},
]
export const viewList = views.map((view) => view.view)
const allViews = [viewAll, ...views]
export function getView(id: FeedViewType): ViewDefinition
export function getView(id: number): ViewDefinition | undefined
export function getView(id: FeedViewType | number): ViewDefinition | undefined {
return allViews.find((view) => view.view === id)
}
export function getViewList(options: { includeAll?: boolean } = {}): ViewDefinition[] {
const { includeAll = false } = options
return includeAll ? allViews : views
}
@@ -80,24 +80,8 @@ export const getSubscriptionByCategory = ({
return ids
}
export const getFolderFeedsByFeedId = ({ feedId, view }: { feedId?: string; view: FeedViewType }) =>
folderFeedsByFeedIdSelector({ feedId, view })(useSubscriptionStore.getState())
export const getCategoryFeedIds = (category: string, view: FeedViewType): string[] => {
const feedIds = [] as string[]
const state = useSubscriptionStore.getState()
for (const id of state.feedIdByView[view].keys()) {
const subscription = state.data[id]
if (!subscription) continue
if (
(subscription.view === view || view === FeedViewType.All) &&
(subscription.category === category || getDefaultCategory(subscription) === category)
) {
feedIds.push(id)
}
}
return feedIds
}
export const getCategoryFeedIds = (feedIdOrCategory: string | undefined, view: FeedViewType) =>
folderFeedsByFeedIdSelector({ feedIdOrCategory, view })(useSubscriptionStore.getState())
// Utility functions for creating getters
type StateType = ReturnType<typeof useSubscriptionStore.getState>
@@ -1,4 +1,4 @@
import { FeedViewType, views } from "@follow/constants"
import { FeedViewType, getViewList } from "@follow/constants"
import { useQuery } from "@tanstack/react-query"
import { useCallback, useMemo, useRef } from "react"
@@ -257,16 +257,11 @@ export const getSubscriptionCategory = (view?: FeedViewType) => {
return view === undefined ? [] : Array.from(state.categories[view])
}
export const useViewWithSubscription = (options?: { excludeAll?: boolean }) =>
export const useViewWithSubscription = () =>
useSubscriptionStore((state) => {
return views
return getViewList()
.filter((view) => {
if (options?.excludeAll && view.view === FeedViewType.All) {
return false
}
if (
view.view === FeedViewType.All ||
view.view === FeedViewType.Articles ||
view.view === FeedViewType.SocialMedia ||
view.view === FeedViewType.Pictures ||
@@ -320,7 +315,7 @@ export const useFolderFeedsByFeedId = ({
return useSubscriptionStore(
useCallback(
(state) => {
return folderFeedsByFeedIdSelector({ feedId, view })(state)
return folderFeedsByFeedIdSelector({ feedIdOrCategory: feedId, view })(state)
},
[feedId, view],
),
@@ -5,21 +5,21 @@ import type { SubscriptionState } from "./store"
import { getDefaultCategory } from "./utils"
export const folderFeedsByFeedIdSelector =
({ feedId, view }: { feedId?: string; view: FeedViewType }) =>
({ feedIdOrCategory, view }: { feedIdOrCategory: string | undefined; view: FeedViewType }) =>
(state: SubscriptionState): string[] => {
if (typeof feedId !== "string") return []
if (feedId === FEED_COLLECTION_LIST) {
return [feedId]
if (typeof feedIdOrCategory !== "string") return []
if (feedIdOrCategory === FEED_COLLECTION_LIST) {
return [feedIdOrCategory]
}
if (!feedId.startsWith(ROUTE_FEED_IN_FOLDER)) {
return []
}
const folderName = feedIdOrCategory.startsWith(ROUTE_FEED_IN_FOLDER)
? feedIdOrCategory.slice(ROUTE_FEED_IN_FOLDER.length)
: feedIdOrCategory
const folderName = feedId.replace(ROUTE_FEED_IN_FOLDER, "")
const feedIds: string[] = []
for (const feedId in state.data) {
const subscription = state.data[feedId]!
const subscription = state.data[feedId]
if (!subscription) continue
if (
(subscription.view === view || view === FeedViewType.All) &&
(subscription.category