diff --git a/apps/mobile/src/components/ui/icon/fallback-icon.tsx b/apps/mobile/src/components/ui/icon/fallback-icon.tsx index 198907151..ab4400b6b 100644 --- a/apps/mobile/src/components/ui/icon/fallback-icon.tsx +++ b/apps/mobile/src/components/ui/icon/fallback-icon.tsx @@ -1,8 +1,9 @@ import { getBackgroundGradient, isCJKChar } from "@follow/utils" +import { Image } from "expo-image" import { LinearGradient } from "expo-linear-gradient" -import { useMemo } from "react" +import { useMemo, useState } from "react" import type { StyleProp, ViewStyle } from "react-native" -import { StyleSheet, Text } from "react-native" +import { StyleSheet, Text, View } from "react-native" export const FallbackIcon = ({ title, @@ -39,6 +40,31 @@ export const FallbackIcon = ({ ) } +export const IconWithFallback = (props: { + url?: string | undefined | null + size: number + title?: string + className?: string + style?: StyleProp +}) => { + const { url, size, title = "", className, style } = props + const [hasError, setHasError] = useState(false) + + if (!url || hasError) { + return + } + + return ( + + setHasError(true)} + /> + + ) +} + const styles = StyleSheet.create({ container: { display: "flex", diff --git a/apps/mobile/src/modules/discover/constants.ts b/apps/mobile/src/modules/discover/constants.ts index 0c2f22c96..96e009248 100644 --- a/apps/mobile/src/modules/discover/constants.ts +++ b/apps/mobile/src/modules/discover/constants.ts @@ -2,12 +2,10 @@ export enum SearchType { Feed = "feed", List = "list", User = "user", - RSSHub = "rsshub", } export const SearchTabs = [ { name: "Feed", value: SearchType.Feed }, { name: "List", value: SearchType.List }, { name: "User", value: SearchType.User }, - { name: "RSSHub", value: SearchType.RSSHub }, ] diff --git a/apps/mobile/src/modules/discover/search-tabs/SearchFeed.tsx b/apps/mobile/src/modules/discover/search-tabs/SearchFeed.tsx index 6f9c43063..6ff35362e 100644 --- a/apps/mobile/src/modules/discover/search-tabs/SearchFeed.tsx +++ b/apps/mobile/src/modules/discover/search-tabs/SearchFeed.tsx @@ -1,24 +1,21 @@ import { FeedViewType } from "@follow/constants" -import { withOpacity } from "@follow/utils" import { useQuery } from "@tanstack/react-query" import { Image } from "expo-image" import { router } from "expo-router" import { useAtomValue } from "jotai" -import { memo } from "react" +import type { ListRenderItem } from "react-native" import { Text, useWindowDimensions, View } from "react-native" import { ScrollView } from "react-native-gesture-handler" import Animated, { FadeInUp } from "react-native-reanimated" import { FeedIcon } from "@/src/components/ui/icon/feed-icon" -import { LoadingIndicator } from "@/src/components/ui/loading" import { ItemPressable } from "@/src/components/ui/pressable/item-pressable" -import { SadCuteReIcon } from "@/src/icons/sad_cute_re" import { apiClient } from "@/src/lib/api-fetch" import { useSubscriptionByFeedId } from "@/src/store/subscription/hooks" -import { useColor } from "@/src/theme/colors" import { useSearchPageContext } from "../ctx" -import { BaseSearchPageFlatList, BaseSearchPageRootView, BaseSearchPageScrollView } from "./__base" +import { BaseSearchPageFlatList, ItemSeparator, RenderScrollComponent } from "./__base" +import { useDataSkeleton } from "./hooks" type SearchResultItem = Awaited>["data"][number] @@ -39,50 +36,34 @@ export const SearchFeed = () => { enabled: !!searchValue, }) - const textColor = useColor("text") - - if (isLoading) { - return ( - - - - - ) - } - - if (data?.data.length === 0) { - return ( - - - - No results found - - ) - } + const skeleton = useDataSkeleton(isLoading, data) + if (skeleton) return skeleton return ( } + contentContainerClassName={"-mt-4"} + renderScrollComponent={RenderScrollComponent} data={data?.data} renderItem={renderItem} + ItemSeparatorComponent={ItemSeparator} /> ) } const keyExtractor = (item: SearchResultItem) => item.feed?.id ?? Math.random().toString() -const renderItem = ({ item }: { item: SearchResultItem }) => ( +const renderItem: ListRenderItem = ({ item }) => ( ) -const SearchFeedItem = memo(({ item }: { item: SearchResultItem }) => { +const SearchFeedItem = ({ item }: { item: SearchResultItem }) => { const isSubscribed = useSubscriptionByFeedId(item.feed?.id ?? "") return ( { if (item.feed?.id) { router.push(`/follow?id=${item.feed.id}`) @@ -146,7 +127,7 @@ const SearchFeedItem = memo(({ item }: { item: SearchResultItem }) => { ) -}) +} const formatter = new Intl.DateTimeFormat("en-US", { year: "numeric", month: "short", diff --git a/apps/mobile/src/modules/discover/search-tabs/SearchList.tsx b/apps/mobile/src/modules/discover/search-tabs/SearchList.tsx index 244064eb6..90da4e7d8 100644 --- a/apps/mobile/src/modules/discover/search-tabs/SearchList.tsx +++ b/apps/mobile/src/modules/discover/search-tabs/SearchList.tsx @@ -1,16 +1,111 @@ +import { useQuery } from "@tanstack/react-query" +import { Image } from "expo-image" +import { router } from "expo-router" import { useAtomValue } from "jotai" -import { Text } from "react-native" +import { memo } from "react" +import { Text, View } from "react-native" +import Animated, { FadeInUp } from "react-native-reanimated" + +import { FallbackIcon } from "@/src/components/ui/icon/fallback-icon" +import { ItemPressable } from "@/src/components/ui/pressable/item-pressable" +import { apiClient } from "@/src/lib/api-fetch" +import { useSubscriptionByListId } from "@/src/store/subscription/hooks" import { useSearchPageContext } from "../ctx" -import { BaseSearchPageScrollView } from "./__base" +import { BaseSearchPageFlatList, ItemSeparator, RenderScrollComponent } from "./__base" +import { useDataSkeleton } from "./hooks" + +type SearchResultItem = Awaited>["data"][number] export const SearchList = () => { const { searchValueAtom } = useSearchPageContext() const searchValue = useAtomValue(searchValueAtom) + const { data, isLoading, refetch } = useQuery({ + queryKey: ["searchFeed", searchValue], + queryFn: () => { + return apiClient.discover.$post({ + json: { + keyword: searchValue, + target: "lists", + }, + }) + }, + enabled: !!searchValue, + }) + + const skeleton = useDataSkeleton(isLoading, data) + if (skeleton) return skeleton + return ( - - {searchValue} - + ) } + +const keyExtractor = (item: SearchResultItem) => item.list?.id ?? Math.random().toString() + +const renderItem = ({ item }: { item: SearchResultItem }) => ( + +) + +const SearchListCard = memo(({ item }: { item: SearchResultItem }) => { + const isSubscribed = useSubscriptionByListId(item.list?.id ?? "") + return ( + + { + if (item.list?.id) { + router.push(`/follow?id=${item.list.id}&type=list`) + } + }} + > + {/* Headline */} + + + {item.list?.image ? ( + + ) : ( + !!item.list?.title && + )} + + + + {item.list?.title} + + {!!item.list?.description && ( + + {item.list?.description} + + )} + + {/* Subscribe */} + {isSubscribed && ( + + + Subscribed + + + )} + + + + ) +}) diff --git a/apps/mobile/src/modules/discover/search-tabs/SearchRSSHub.tsx b/apps/mobile/src/modules/discover/search-tabs/SearchRSSHub.tsx deleted file mode 100644 index 7083fa8ae..000000000 --- a/apps/mobile/src/modules/discover/search-tabs/SearchRSSHub.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { Text } from "react-native" - -import { BaseSearchPageScrollView } from "./__base" - -export const SearchRSSHub = () => { - return ( - - RSSHub - - ) -} diff --git a/apps/mobile/src/modules/discover/search-tabs/__base.tsx b/apps/mobile/src/modules/discover/search-tabs/__base.tsx index e1b9d52d8..fc45c623e 100644 --- a/apps/mobile/src/modules/discover/search-tabs/__base.tsx +++ b/apps/mobile/src/modules/discover/search-tabs/__base.tsx @@ -1,7 +1,7 @@ import { cn } from "@follow/utils/src/utils" import { forwardRef } from "react" import type { ScrollViewProps } from "react-native" -import { RefreshControl, ScrollView, useWindowDimensions, View } from "react-native" +import { RefreshControl, ScrollView, StyleSheet, useWindowDimensions, View } from "react-native" import type { FlatListPropsWithLayout } from "react-native-reanimated" import Animated, { LinearTransition } from "react-native-reanimated" import { useSafeAreaInsets } from "react-native-safe-area-context" @@ -70,10 +70,18 @@ export function BaseSearchPageFlatList({ } {...props} /> ) } +const itemSeparator = ( + +) +export const ItemSeparator = () => itemSeparator + +export const RenderScrollComponent = (props: ScrollViewProps) => ( + +) diff --git a/apps/mobile/src/modules/discover/search-tabs/hooks.tsx b/apps/mobile/src/modules/discover/search-tabs/hooks.tsx new file mode 100644 index 000000000..0c3e72ab1 --- /dev/null +++ b/apps/mobile/src/modules/discover/search-tabs/hooks.tsx @@ -0,0 +1,35 @@ +import { withOpacity } from "@follow/utils" +import { useMemo } from "react" +import { Text, View } from "react-native" + +import { LoadingIndicator } from "@/src/components/ui/loading" +import { SadCuteReIcon } from "@/src/icons/sad_cute_re" +import { useColor } from "@/src/theme/colors" + +import { BaseSearchPageRootView } from "./__base" + +export const useDataSkeleton = (isLoading: boolean, data: any) => { + const textColor = useColor("text") + return useMemo(() => { + if (isLoading) { + return ( + + + + + ) + } + + if (data?.data.length === 0) { + return ( + + + + No results found + + ) + } + + return null + }, [isLoading, data, textColor]) +} diff --git a/apps/mobile/src/modules/discover/search.tsx b/apps/mobile/src/modules/discover/search.tsx index 4aa7e0b52..6b1347489 100644 --- a/apps/mobile/src/modules/discover/search.tsx +++ b/apps/mobile/src/modules/discover/search.tsx @@ -38,7 +38,7 @@ export const SearchHeader: FC<{ className="relative" onLayout={onLayout} > - {/* */} + diff --git a/apps/mobile/src/modules/feed/FollowFeed.tsx b/apps/mobile/src/modules/feed/FollowFeed.tsx new file mode 100644 index 000000000..af613aaae --- /dev/null +++ b/apps/mobile/src/modules/feed/FollowFeed.tsx @@ -0,0 +1,195 @@ +import { FeedViewType } from "@follow/constants" +import { zodResolver } from "@hookform/resolvers/zod" +import { StackActions } from "@react-navigation/native" +import { useQuery } from "@tanstack/react-query" +import { router, Stack, useLocalSearchParams, useNavigation } from "expo-router" +import { useState } from "react" +import { Controller, useForm } from "react-hook-form" +import { ScrollView, Text, View } from "react-native" +import { z } from "zod" + +import { + ModalHeaderCloseButton, + ModalHeaderShubmitButton, +} from "@/src/components/common/ModalSharedComponents" +import { FormProvider } from "@/src/components/ui/form/FormProvider" +import { FormLabel } from "@/src/components/ui/form/Label" +import { FormSwitch } from "@/src/components/ui/form/Switch" +import { TextField } from "@/src/components/ui/form/TextField" +import { FeedIcon } from "@/src/components/ui/icon/feed-icon" +import { LoadingIndicator } from "@/src/components/ui/loading" +import { useIsRouteOnlyOne } from "@/src/hooks/useIsRouteOnlyOne" +import { FeedViewSelector } from "@/src/modules/feed/view-selector" +import { useFeed } from "@/src/store/feed/hooks" +import { feedSyncServices } from "@/src/store/feed/store" +import { useSubscriptionByFeedId } from "@/src/store/subscription/hooks" +import { subscriptionSyncService } from "@/src/store/subscription/store" +import type { SubscriptionForm } from "@/src/store/subscription/types" + +const formSchema = z.object({ + view: z.string(), + category: z.string().nullable().optional(), + isPrivate: z.boolean().optional(), + title: z.string().optional(), +}) +const defaultValues = { view: FeedViewType.Articles.toString() } +export function FollowFeed(props: { id: string }) { + const { id } = props + const feed = useFeed(id as string) + const { isLoading } = useQuery({ + queryKey: ["feed", id], + queryFn: () => feedSyncServices.fetchFeedById({ id: id as string }), + enabled: !feed, + }) + + if (isLoading) { + return ( + + + + ) + } + + return +} +function FollowImpl() { + const { id } = useLocalSearchParams() + + const feed = useFeed(id as string) + const isSubscribed = useSubscriptionByFeedId(feed?.id || "") + + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues, + }) + + const [isLoading, setIsLoading] = useState(false) + const routeOnlyOne = useIsRouteOnlyOne() + const navigate = useNavigation() + const parentRoute = navigate.getParent() + const submit = async () => { + setIsLoading(true) + const values = form.getValues() + const body: SubscriptionForm = { + url: feed.url, + view: Number.parseInt(values.view), + category: values.category ?? "", + isPrivate: values.isPrivate ?? false, + title: values.title ?? "", + feedId: feed.id, + } + + await subscriptionSyncService.subscribe(body).finally(() => { + setIsLoading(false) + }) + + if (router.canDismiss()) { + router.dismissAll() + + if (!routeOnlyOne) { + parentRoute?.dispatch(StackActions.popToTop()) + } + } + } + + const { isValid, isDirty } = form.formState + + if (!feed?.id) { + return Feed ({id}) not found + } + + return ( + + ( + + ), + }} + /> + + {/* Group 1 */} + + + + + + + {feed?.title} + {feed?.description} + + + + {/* Group 2 */} + + + + ( + + )} + /> + + + + ( + + )} + /> + + + + ( + + )} + /> + + + + + + ( + + )} + /> + + + + + ) +} diff --git a/apps/mobile/src/modules/feed/view-selector.tsx b/apps/mobile/src/modules/feed/view-selector.tsx index 7c5f6858e..7ba834e44 100644 --- a/apps/mobile/src/modules/feed/view-selector.tsx +++ b/apps/mobile/src/modules/feed/view-selector.tsx @@ -4,23 +4,35 @@ import { Text, TouchableOpacity, View } from "react-native" import { Grid } from "@/src/components/ui/grid" import { views } from "@/src/constants/views" +import { useColor } from "@/src/theme/colors" interface Props { value: FeedViewType - onChange: (value: FeedViewType) => void + onChange?: (value: FeedViewType) => void className?: string + readOnly?: boolean } -export const FeedViewSelector = ({ value, onChange, className }: Props) => { +export const FeedViewSelector = ({ value, onChange, className, readOnly }: Props) => { + const secondaryLabelColor = useColor("secondaryLabel") return ( {views.map((view) => { const isSelected = +value === +view.view return ( - onChange(view.view)}> + onChange?.(view.view)} + disabled={readOnly} + className={readOnly ? "opacity-50" : undefined} + > - + { + const { id } = props + const list = useList(id as string) + const { isLoading } = useQuery({ + queryKey: ["list", id], + queryFn: () => listSyncServices.fetchListById({ id: id as string }), + enabled: !list, + }) + + if (isLoading) { + return ( + + + + ) + } + + return +} + +const formSchema = z.object({ + view: z.string(), + isPrivate: z.boolean().optional(), + title: z.string().optional(), +}) +const defaultValues = { view: FeedViewType.Articles.toString() } + +const Impl = (props: { id: string }) => { + const { id } = props + const list = useList(id as string)! + + const isSubscribed = useSubscriptionByListId(id as string) + + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues, + }) + const { isValid, isDirty } = form.formState + + const submit = async () => { + const payload = form.getValues() + // console.log("submit", payload) + void payload + + if (list.fee && !isSubscribed) { + Alert.alert( + `To follow this list, you must pay a fee to the list creator. Press OK to pay ${list.fee} power to follow this list.`, + "OK", + [ + { + text: "Cancel", + style: "cancel", + }, + { + text: "OK", + onPress: () => {}, + }, + ], + ) + } + } + + const isLoading = false + + return ( + + ( + + ), + }} + /> + + + + + + + + {list?.title} + {list?.description} + + + + + + + + + + + + + + ( + + )} + /> + + + + ( + + )} + /> + + + {!!list.fee && ( + + + + {list.fee} + + + To follow this list, you must pay a fee to the list creator. + + + )} + + + + ) +} diff --git a/apps/mobile/src/morph/hono.ts b/apps/mobile/src/morph/hono.ts index daba26a2d..c881ca0e3 100644 --- a/apps/mobile/src/morph/hono.ts +++ b/apps/mobile/src/morph/hono.ts @@ -79,6 +79,20 @@ class Morph { } return { subscriptions, ...collections } } + + toList({ list: data }: HonoApiClient.List_Get): ListModel { + return { + id: data.id, + title: data.title!, + userId: data.ownerUserId!, + description: data.description!, + view: data.view, + image: data.image!, + ownerUserId: data.ownerUserId!, + feedIds: data.feedIds!, + fee: data.fee!, + } + } } export const honoMorph = new Morph() diff --git a/apps/mobile/src/morph/types.ts b/apps/mobile/src/morph/types.ts index 7836b0b6b..4f06217f3 100644 --- a/apps/mobile/src/morph/types.ts +++ b/apps/mobile/src/morph/types.ts @@ -7,4 +7,5 @@ type ExtractData any> = export namespace HonoApiClient { export type Subscription_Get = ExtractData + export type List_Get = ExtractData } diff --git a/apps/mobile/src/screens/(headless)/search.tsx b/apps/mobile/src/screens/(headless)/search.tsx index f8d8989c9..fc8a46dbd 100644 --- a/apps/mobile/src/screens/(headless)/search.tsx +++ b/apps/mobile/src/screens/(headless)/search.tsx @@ -19,7 +19,6 @@ import { import { SearchHeader } from "@/src/modules/discover/search" import { SearchFeed } from "@/src/modules/discover/search-tabs/SearchFeed" import { SearchList } from "@/src/modules/discover/search-tabs/SearchList" -import { SearchRSSHub } from "@/src/modules/discover/search-tabs/SearchRSSHub" import { SearchUser } from "@/src/modules/discover/search-tabs/SearchUser" const Search = () => { @@ -41,7 +40,6 @@ const SearchType2RenderContent: Record = { [SearchType.Feed]: SearchFeed, [SearchType.List]: SearchList, [SearchType.User]: SearchUser, - [SearchType.RSSHub]: SearchRSSHub, } const PlaceholderLazyView = () => { const windowWidth = Dimensions.get("window").width diff --git a/apps/mobile/src/screens/(modal)/follow.tsx b/apps/mobile/src/screens/(modal)/follow.tsx index 2f6c0f261..6a4d549c0 100644 --- a/apps/mobile/src/screens/(modal)/follow.tsx +++ b/apps/mobile/src/screens/(modal)/follow.tsx @@ -1,195 +1,20 @@ -import { FeedViewType } from "@follow/constants" -import { zodResolver } from "@hookform/resolvers/zod" -import { StackActions } from "@react-navigation/native" -import { useQuery } from "@tanstack/react-query" -import { router, Stack, useLocalSearchParams, useNavigation } from "expo-router" -import { useState } from "react" -import { Controller, useForm } from "react-hook-form" -import { ScrollView, Text, View } from "react-native" -import { z } from "zod" +import { useLocalSearchParams } from "expo-router" -import { - ModalHeaderCloseButton, - ModalHeaderShubmitButton, -} from "@/src/components/common/ModalSharedComponents" -import { FormProvider } from "@/src/components/ui/form/FormProvider" -import { FormLabel } from "@/src/components/ui/form/Label" -import { FormSwitch } from "@/src/components/ui/form/Switch" -import { TextField } from "@/src/components/ui/form/TextField" -import { FeedIcon } from "@/src/components/ui/icon/feed-icon" -import { LoadingIndicator } from "@/src/components/ui/loading" -import { useIsRouteOnlyOne } from "@/src/hooks/useIsRouteOnlyOne" -import { FeedViewSelector } from "@/src/modules/feed/view-selector" -import { useFeed } from "@/src/store/feed/hooks" -import { feedSyncServices } from "@/src/store/feed/store" -import { useSubscriptionByFeedId } from "@/src/store/subscription/hooks" -import { subscriptionSyncService } from "@/src/store/subscription/store" -import type { SubscriptionForm } from "@/src/store/subscription/types" +import { FollowFeed } from "@/src/modules/feed/FollowFeed" +import { FollowList } from "@/src/modules/list/FollowList" -const formSchema = z.object({ - view: z.string(), - category: z.string().nullable().optional(), - isPrivate: z.boolean().optional(), - title: z.string().optional(), -}) -const defaultValues = { view: FeedViewType.Articles.toString() } export default function Follow() { - const { id } = useLocalSearchParams() - const feed = useFeed(id as string) - const { isLoading } = useQuery({ - queryKey: ["feed", id], - queryFn: () => feedSyncServices.fetchFeedById({ id: id as string }), - enabled: !feed, - }) + const { id, type = "feed" } = useLocalSearchParams() - if (isLoading) { - return ( - - - - ) - } - - return -} -function FollowImpl() { - const { id } = useLocalSearchParams() - - const feed = useFeed(id as string) - const isSubscribed = useSubscriptionByFeedId(feed?.id || "") - - const form = useForm>({ - resolver: zodResolver(formSchema), - defaultValues, - }) - - const [isLoading, setIsLoading] = useState(false) - const routeOnlyOne = useIsRouteOnlyOne() - const navigate = useNavigation() - const parentRoute = navigate.getParent() - const submit = async () => { - setIsLoading(true) - const values = form.getValues() - const body: SubscriptionForm = { - url: feed.url, - view: Number.parseInt(values.view), - category: values.category ?? "", - isPrivate: values.isPrivate ?? false, - title: values.title ?? "", - feedId: feed.id, + switch (type) { + case "feed": { + return } - - await subscriptionSyncService.subscribe(body).finally(() => { - setIsLoading(false) - }) - - if (router.canDismiss()) { - router.dismissAll() - - if (!routeOnlyOne) { - parentRoute?.dispatch(StackActions.popToTop()) - } + case "list": { + return + } + default: { + return } } - - const { isValid, isDirty } = form.formState - - if (!feed?.id) { - return Feed ({id}) not found - } - - return ( - - ( - - ), - }} - /> - - {/* Group 1 */} - - - - - - - {feed?.title} - {feed?.description} - - - - {/* Group 2 */} - - - - ( - - )} - /> - - - - ( - - )} - /> - - - - ( - - )} - /> - - - - - - ( - - )} - /> - - - - - ) } diff --git a/apps/mobile/src/screens/(stack)/(tabs)/_layout.tsx b/apps/mobile/src/screens/(stack)/(tabs)/_layout.tsx index 021e956ea..78a652818 100644 --- a/apps/mobile/src/screens/(stack)/(tabs)/_layout.tsx +++ b/apps/mobile/src/screens/(stack)/(tabs)/_layout.tsx @@ -1,7 +1,7 @@ import { FeedViewType } from "@follow/constants" import { PlatformPressable } from "@react-navigation/elements/src/PlatformPressable" import { router, Tabs } from "expo-router" -import { View } from "react-native" +import { Easing, View } from "react-native" import { Gesture, GestureDetector } from "react-native-gesture-handler" import { runOnJS } from "react-native-reanimated" @@ -33,6 +33,14 @@ export default function TabLayout() { tabBarStyle: { position: "absolute", }, + animation: "fade", + transitionSpec: { + animation: "timing", + config: { + duration: 50, + easing: Easing.ease, + }, + }, }} > { export const useSubscriptionByFeedId = (feedId: string) => useSubscriptionStore(useCallback((state) => state.data[feedId] || null, [feedId])) + +export const useSubscriptionByListId = (listId: string) => + useSubscriptionStore(useCallback((state) => state.data[listId] || null, [listId]))