diff --git a/apps/mobile/src/constants/ui.ts b/apps/mobile/src/constants/ui.ts deleted file mode 100644 index caa3ddddd..000000000 --- a/apps/mobile/src/constants/ui.ts +++ /dev/null @@ -1 +0,0 @@ -export const bottomViewTabHeight = 35 diff --git a/apps/mobile/src/modules/subscription/CategoryGrouped.tsx b/apps/mobile/src/modules/subscription/CategoryGrouped.tsx new file mode 100644 index 000000000..c3b715e1e --- /dev/null +++ b/apps/mobile/src/modules/subscription/CategoryGrouped.tsx @@ -0,0 +1,69 @@ +import { memo, useState } from "react" +import { Text, TouchableOpacity, View } from "react-native" +import Animated, { useAnimatedStyle, useSharedValue, withSpring } from "react-native-reanimated" + +import { ItemPressable } from "@/src/components/ui/pressable/item-pressable" +import { MingcuteRightLine } from "@/src/icons/mingcute_right_line" +import { useUnreadCounts } from "@/src/store/unread/hooks" + +import { SubscriptionFeedCategoryContextMenu } from "../context-menu/feeds" +import { GroupedContext } from "./ctx" +import { UnGroupedList } from "./UnGroupedList" + +// const CategoryList: FC<{ +// grouped: Record +// }> = ({ grouped }) => { +// const sortedGrouped = useSortedGroupedSubscription(grouped, "alphabet") +// return sortedGrouped.map(({ category, subscriptionIds }) => { +// return +// }) +// } +export const CategoryGrouped = memo( + ({ category, subscriptionIds }: { category: string; subscriptionIds: string[] }) => { + const unreadCounts = useUnreadCounts(subscriptionIds) + const [expanded, setExpanded] = useState(false) + const rotateSharedValue = useSharedValue(0) + const rotateStyle = useAnimatedStyle(() => { + return { + transform: [{ rotate: `${rotateSharedValue.value}deg` }], + } + }, [rotateSharedValue]) + return ( + <> + + { + // TODO navigate to category + }} + className="border-item-pressed h-12 flex-row items-center border-b px-3" + > + { + rotateSharedValue.value = withSpring(expanded ? 0 : 90, {}) + setExpanded(!expanded) + }} + className="size-5 flex-row items-center justify-center" + > + + + + + {category} + {!!unreadCounts && ( + {unreadCounts} + )} + + + + {expanded && ( + + + + + + )} + + ) + }, +) diff --git a/apps/mobile/src/modules/subscription/SubscriptionLists.tsx b/apps/mobile/src/modules/subscription/SubscriptionLists.tsx index 5f1f647f2..a353c8620 100644 --- a/apps/mobile/src/modules/subscription/SubscriptionLists.tsx +++ b/apps/mobile/src/modules/subscription/SubscriptionLists.tsx @@ -1,32 +1,16 @@ import { FeedViewType } from "@follow/constants" -import { cn } from "@follow/utils" import { useBottomTabBarHeight } from "@react-navigation/bottom-tabs" import { useHeaderHeight } from "@react-navigation/elements" -import { router } from "expo-router" import { useAtom } from "jotai" -import { useColorScheme } from "nativewind" -import type { FC } from "react" -import { createContext, memo, useContext, useEffect, useMemo, useRef, useState } from "react" -import { Image, StyleSheet, Text, TouchableOpacity, View } from "react-native" +import { memo, useEffect, useMemo, useRef, useState } from "react" +import { RefreshControl, StyleSheet, Text, View } from "react-native" import PagerView from "react-native-pager-view" -import ReAnimated, { - FadeOutUp, - LinearTransition, - useAnimatedStyle, - useSharedValue, - withSpring, -} from "react-native-reanimated" +import ReAnimated, { LinearTransition } from "react-native-reanimated" import { useSafeAreaInsets } from "react-native-safe-area-context" +import { useEventCallback } from "usehooks-ts" -import { FallbackIcon } from "@/src/components/ui/icon/fallback-icon" -import { FeedIcon } from "@/src/components/ui/icon/feed-icon" import { ItemPressable } from "@/src/components/ui/pressable/item-pressable" -import { bottomViewTabHeight } from "@/src/constants/ui" -import { InboxCuteFiIcon } from "@/src/icons/inbox_cute_fi" -import { MingcuteRightLine } from "@/src/icons/mingcute_right_line" import { StarCuteFiIcon } from "@/src/icons/star_cute_fi" -import { useFeed } from "@/src/store/feed/hooks" -import { useList } from "@/src/store/list/hooks" import { useGroupedSubscription, useInboxSubscription, @@ -35,18 +19,16 @@ import { useSortedGroupedSubscription, useSortedListSubscription, useSortedUngroupedSubscription, - useSubscription, } from "@/src/store/subscription/hooks" -import { getInboxStoreId } from "@/src/store/subscription/utils" -import { useUnreadCount, useUnreadCounts } from "@/src/store/unread/hooks" +import { subscriptionSyncService } from "@/src/store/subscription/store" -import { - SubscriptionFeedCategoryContextMenu, - SubscriptionFeedItemContextMenu, -} from "../context-menu/feeds" -import { SubscriptionListItemContextMenu } from "../context-menu/lists" import { useFeedListSortMethod, useFeedListSortOrder, viewAtom } from "./atoms" +import { CategoryGrouped } from "./CategoryGrouped" +import { ViewTabHeight } from "./constants" import { useViewPageCurrentView, ViewPageCurrentViewProvider } from "./ctx" +import { InboxItem } from "./items/InboxItem" +import { ListSubscriptionItem } from "./items/ListSubscriptionItem" +import { SubscriptionItem } from "./items/SubscriptionItem" export const SubscriptionLists = memo(() => { const [currentView, setCurrentView] = useAtom(viewAtom) @@ -58,36 +40,32 @@ export const SubscriptionLists = memo(() => { }, [currentView]) return ( - <> - - - { - setCurrentView(nativeEvent.position) - }} - scrollEnabled - style={style.flex} - initialPage={0} - ref={pagerRef} - offscreenPageLimit={3} - > - {[ - FeedViewType.Articles, - FeedViewType.SocialMedia, - FeedViewType.Pictures, - FeedViewType.Videos, - FeedViewType.Audios, - FeedViewType.Notifications, - ].map((view) => { - return ( - - - - ) - })} - - + { + setCurrentView(nativeEvent.position) + }} + scrollEnabled + style={style.flex} + initialPage={0} + ref={pagerRef} + offscreenPageLimit={3} + > + {[ + FeedViewType.Articles, + FeedViewType.SocialMedia, + FeedViewType.Pictures, + FeedViewType.Videos, + FeedViewType.Audios, + FeedViewType.Notifications, + ].map((view) => { + return ( + + + + ) + })} + ) }) const keyExtractor = (item: string | { category: string; subscriptionIds: string[] }) => { @@ -113,15 +91,34 @@ const SubscriptionList = ({ view }: { view: FeedViewType }) => { [sortedGrouped, sortedUnGrouped], ) + const [refreshing, setRefreshing] = useState(false) + const onRefresh = useEventCallback(() => { + return subscriptionSyncService.fetch(view) + }) + + const offsetTop = headerHeight - insets.top + ViewTabHeight * 2 + 23 + return ( { + setRefreshing(true) + onRefresh().finally(() => { + setRefreshing(false) + }) + }} + refreshing={refreshing} + /> + } contentInsetAdjustmentBehavior="automatic" scrollIndicatorInsets={{ bottom: tabHeight - insets.bottom, - top: headerHeight - insets.top + bottomViewTabHeight, + top: offsetTop, }} contentContainerStyle={{ - paddingTop: headerHeight - insets.top + bottomViewTabHeight, + paddingTop: offsetTop, paddingBottom: tabHeight, }} data={data} @@ -173,23 +170,6 @@ const ListHeaderComponent = () => { ) } -// This not used FlashList -// const ViewPage = memo(({ view }: { view: FeedViewType }) => { -// const { grouped, unGrouped } = useGroupedSubscription(view) -// usePrefetchSubscription(view) - -// return ( -// -// -// {view === FeedViewType.Articles && } -// -// Feeds -// -// -// -// ) -// }) - const InboxList = () => { const inboxes = useInboxSubscription(FeedViewType.Articles) if (inboxes.length === 0) return null @@ -203,27 +183,6 @@ const InboxList = () => { ) } -const InboxItem = memo(({ id }: { id: string }) => { - const subscription = useSubscription(getInboxStoreId(id)) - const unreadCount = useUnreadCount(id) - const { colorScheme } = useColorScheme() - if (!subscription) return null - return ( - - - - - - {subscription.title} - {!!unreadCount && {unreadCount}} - - ) -}) - const StarItem = () => { return ( { ) } -const ListSubscriptionItem = memo(({ id }: { id: string; className?: string }) => { - const list = useList(id) - const unreadCount = useUnreadCount(id) - if (!list) return null - return ( - - - - {!!list.image && ( - - )} - {!list.image && } - - - {list.title} - {!!unreadCount && } - - - ) -}) - -const UnGroupedList: FC<{ - subscriptionIds: string[] -}> = ({ subscriptionIds }) => { - const sortBy = useFeedListSortMethod() - const sortOrder = useFeedListSortOrder() - const sortedSubscriptionIds = useSortedUngroupedSubscription(subscriptionIds, sortBy, sortOrder) - const lastSubscriptionId = sortedSubscriptionIds.at(-1) - - return sortedSubscriptionIds.map((id) => { - return ( - - ) - }) -} - -const GroupedContext = createContext(null) - -// const CategoryList: FC<{ -// grouped: Record -// }> = ({ grouped }) => { -// const sortedGrouped = useSortedGroupedSubscription(grouped, "alphabet") - -// return sortedGrouped.map(({ category, subscriptionIds }) => { -// return -// }) -// } - -const CategoryGrouped = memo( - ({ category, subscriptionIds }: { category: string; subscriptionIds: string[] }) => { - const unreadCounts = useUnreadCounts(subscriptionIds) - const [expanded, setExpanded] = useState(false) - const rotateSharedValue = useSharedValue(0) - const rotateStyle = useAnimatedStyle(() => { - return { - transform: [{ rotate: `${rotateSharedValue.value}deg` }], - } - }, [rotateSharedValue]) - return ( - <> - - { - // TODO navigate to category - }} - className="border-item-pressed h-12 flex-row items-center border-b px-3" - > - { - rotateSharedValue.value = withSpring(expanded ? 90 : 0, {}) - setExpanded(!expanded) - }} - style={style.accordionIcon} - > - - - - - {category} - {!!unreadCounts && ( - {unreadCounts} - )} - - - {/* */} - {expanded && ( - - - - - - )} - {/* */} - - ) - }, -) - -// const renderRightActions = () => { -// return ( -// -// { -// // TODO: Handle unsubscribe -// }} -// > -// Unsubscribe -// -// -// ) -// } - -// const renderLeftActions = () => { -// return ( -// -// { -// // TODO: Handle unsubscribe -// }} -// > -// Read -// -// -// ) -// } - -// let prevOpenedRow: SwipeableMethods | null = null -const SubscriptionItem = memo(({ id, className }: { id: string; className?: string }) => { - const subscription = useSubscription(id) - const unreadCount = useUnreadCount(id) - const feed = useFeed(id) - const inGrouped = !!useContext(GroupedContext) - const view = useViewPageCurrentView() - // const swipeableRef: SwipeableRef = useRef(null) - - if (!subscription || !feed) return null - - return ( - // FIXME: Here leads to very serious performance issues, the frame rate of both the UI and JS threads has dropped - // { - // if (prevOpenedRow && prevOpenedRow !== swipeableRef.current) { - // prevOpenedRow.close() - // } - // prevOpenedRow = swipeableRef.current - // }} - // > - // - - - { - router.push({ - pathname: `/feeds/[feedId]`, - params: { - feedId: id, - }, - }) - }} - > - - - - {subscription.title || feed.title} - {!!unreadCount && ( - {unreadCount} - )} - - - - // - ) -}) - const style = StyleSheet.create({ flex: { flex: 1, }, - accordionIcon: { - height: 20, - width: 20, - alignItems: "center", - justifyContent: "center", - }, }) diff --git a/apps/mobile/src/modules/subscription/UnGroupedList.tsx b/apps/mobile/src/modules/subscription/UnGroupedList.tsx new file mode 100644 index 000000000..129a7f294 --- /dev/null +++ b/apps/mobile/src/modules/subscription/UnGroupedList.tsx @@ -0,0 +1,25 @@ +import type { FC } from "react" + +import { useSortedUngroupedSubscription } from "@/src/store/subscription/hooks" + +import { useFeedListSortMethod, useFeedListSortOrder } from "./atoms" +import { SubscriptionItem } from "./items/SubscriptionItem" + +export const UnGroupedList: FC<{ + subscriptionIds: string[] +}> = ({ subscriptionIds }) => { + const sortBy = useFeedListSortMethod() + const sortOrder = useFeedListSortOrder() + const sortedSubscriptionIds = useSortedUngroupedSubscription(subscriptionIds, sortBy, sortOrder) + const lastSubscriptionId = sortedSubscriptionIds.at(-1) + + return sortedSubscriptionIds.map((id) => { + return ( + + ) + }) +} diff --git a/apps/mobile/src/modules/subscription/ViewTab.tsx b/apps/mobile/src/modules/subscription/ViewTab.tsx index 173d1d942..dab6189f6 100644 --- a/apps/mobile/src/modules/subscription/ViewTab.tsx +++ b/apps/mobile/src/modules/subscription/ViewTab.tsx @@ -8,13 +8,13 @@ import Animated, { useAnimatedStyle, useSharedValue, withSpring } from "react-na import { ThemedBlurView } from "@/src/components/common/ThemedBlurView" import { ContextMenu } from "@/src/components/ui/context-menu" -import { bottomViewTabHeight } from "@/src/constants/ui" import type { ViewDefinition } from "@/src/constants/views" import { views } from "@/src/constants/views" import { useUnreadCountByView } from "@/src/store/unread/hooks" import { unreadSyncService } from "@/src/store/unread/store" import { offsetAtom, setCurrentView, viewAtom } from "./atoms" +import { ViewTabHeight } from "./constants" const springConfig: WithSpringConfig = { damping: 20, @@ -65,10 +65,10 @@ export const ViewTab = () => { return ( - + { scrollOffsetX.current = event.nativeEvent.contentOffset.x diff --git a/apps/mobile/src/modules/subscription/constants.ts b/apps/mobile/src/modules/subscription/constants.ts new file mode 100644 index 000000000..73a0d731c --- /dev/null +++ b/apps/mobile/src/modules/subscription/constants.ts @@ -0,0 +1 @@ +export const ViewTabHeight = 35 diff --git a/apps/mobile/src/modules/subscription/ctx.ts b/apps/mobile/src/modules/subscription/ctx.ts index 70d178c99..7e7cb1a5b 100644 --- a/apps/mobile/src/modules/subscription/ctx.ts +++ b/apps/mobile/src/modules/subscription/ctx.ts @@ -4,3 +4,4 @@ import { createContext, useContext } from "react" const ViewPageCurrentViewContext = createContext(null!) export const ViewPageCurrentViewProvider = ViewPageCurrentViewContext.Provider export const useViewPageCurrentView = () => useContext(ViewPageCurrentViewContext) +export const GroupedContext = createContext(null) diff --git a/apps/mobile/src/modules/subscription/items/InboxItem.tsx b/apps/mobile/src/modules/subscription/items/InboxItem.tsx new file mode 100644 index 000000000..625ad1b1e --- /dev/null +++ b/apps/mobile/src/modules/subscription/items/InboxItem.tsx @@ -0,0 +1,35 @@ +import { useColorScheme } from "nativewind" +import { memo } from "react" +import { Text, View } from "react-native" +import Animated, { FadeOutUp } from "react-native-reanimated" + +import { ItemPressable } from "@/src/components/ui/pressable/item-pressable" +import { InboxCuteFiIcon } from "@/src/icons/inbox_cute_fi" +import { useSubscription } from "@/src/store/subscription/hooks" +import { getInboxStoreId } from "@/src/store/subscription/utils" +import { useUnreadCount } from "@/src/store/unread/hooks" + +export const InboxItem = memo(({ id }: { id: string }) => { + const subscription = useSubscription(getInboxStoreId(id)) + const unreadCount = useUnreadCount(id) + const { colorScheme } = useColorScheme() + if (!subscription) return null + return ( + + + + + + + {subscription.title} + {!!unreadCount && ( + {unreadCount} + )} + + + ) +}) diff --git a/apps/mobile/src/modules/subscription/items/ListSubscriptionItem.tsx b/apps/mobile/src/modules/subscription/items/ListSubscriptionItem.tsx new file mode 100644 index 000000000..5a77b06f0 --- /dev/null +++ b/apps/mobile/src/modules/subscription/items/ListSubscriptionItem.tsx @@ -0,0 +1,33 @@ +import { memo } from "react" +import { Image, Text, View } from "react-native" +import Animated, { FadeOutUp } from "react-native-reanimated" + +import { FallbackIcon } from "@/src/components/ui/icon/fallback-icon" +import { ItemPressable } from "@/src/components/ui/pressable/item-pressable" +import { useList } from "@/src/store/list/hooks" +import { useUnreadCount } from "@/src/store/unread/hooks" + +import { SubscriptionListItemContextMenu } from "../../context-menu/lists" + +export const ListSubscriptionItem = memo(({ id }: { id: string; className?: string }) => { + const list = useList(id) + const unreadCount = useUnreadCount(id) + if (!list) return null + return ( + + + + + {!!list.image && ( + + )} + {!list.image && } + + + {list.title} + {!!unreadCount && } + + + + ) +}) diff --git a/apps/mobile/src/modules/subscription/items/SubscriptionItem.tsx b/apps/mobile/src/modules/subscription/items/SubscriptionItem.tsx new file mode 100644 index 000000000..fba7c030d --- /dev/null +++ b/apps/mobile/src/modules/subscription/items/SubscriptionItem.tsx @@ -0,0 +1,100 @@ +import { cn } from "@follow/utils" +import { router } from "expo-router" +import { memo, useContext } from "react" +import { Text, View } from "react-native" +import Animated, { FadeOutUp } from "react-native-reanimated" + +import { FeedIcon } from "@/src/components/ui/icon/feed-icon" +import { ItemPressable } from "@/src/components/ui/pressable/item-pressable" +import { useFeed } from "@/src/store/feed/hooks" +import { useSubscription } from "@/src/store/subscription/hooks" +import { useUnreadCount } from "@/src/store/unread/hooks" + +import { SubscriptionFeedItemContextMenu } from "../../context-menu/feeds" +import { GroupedContext, useViewPageCurrentView } from "../ctx" + +// const renderRightActions = () => { +// return ( +// +// { +// // TODO: Handle unsubscribe +// }} +// > +// Unsubscribe +// +// +// ) +// } +// const renderLeftActions = () => { +// return ( +// +// { +// // TODO: Handle unsubscribe +// }} +// > +// Read +// +// +// ) +// } +// let prevOpenedRow: SwipeableMethods | null = null +export const SubscriptionItem = memo(({ id, className }: { id: string; className?: string }) => { + const subscription = useSubscription(id) + const unreadCount = useUnreadCount(id) + const feed = useFeed(id) + const inGrouped = !!useContext(GroupedContext) + const view = useViewPageCurrentView() + // const swipeableRef: SwipeableRef = useRef(null) + if (!subscription || !feed) return null + + return ( + // FIXME: Here leads to very serious performance issues, the frame rate of both the UI and JS threads has dropped + // { + // if (prevOpenedRow && prevOpenedRow !== swipeableRef.current) { + // prevOpenedRow.close() + // } + // prevOpenedRow = swipeableRef.current + // }} + // > + // + + + { + router.push({ + pathname: `/feeds/[feedId]`, + params: { + feedId: id, + }, + }) + }} + > + + + + {subscription.title || feed.title} + {!!unreadCount && ( + {unreadCount} + )} + + + + // + ) +}) diff --git a/apps/mobile/src/screens/(stack)/(tabs)/subscription.tsx b/apps/mobile/src/screens/(stack)/(tabs)/subscription.tsx index a2d51462e..7ce324b78 100644 --- a/apps/mobile/src/screens/(stack)/(tabs)/subscription.tsx +++ b/apps/mobile/src/screens/(stack)/(tabs)/subscription.tsx @@ -27,6 +27,7 @@ export default function FeedList() { headerTransparent: true, }} /> +