feat(mobile): add mark as read action button for feed list

This commit is contained in:
DIYgod
2025-04-09 17:28:13 +08:00
parent 22d642a3fb
commit 53b2136889
2 changed files with 58 additions and 60 deletions
@@ -1,22 +1,17 @@
import { useMemo } from "react"
import { useTranslation } from "react-i18next"
import { Share, View } from "react-native"
import { useColor } from "react-native-uikit-colors"
import { View } from "react-native"
import { DefaultHeaderBackButton } from "@/src/components/layouts/header/NavigationHeader"
import { NavigationBlurEffectHeader } from "@/src/components/layouts/views/SafeNavigationScrollView"
import { UIBarButton } from "@/src/components/ui/button/UIBarButton"
import { TIMELINE_VIEW_SELECTOR_HEIGHT } from "@/src/constants/ui"
import { Share3CuteReIcon } from "@/src/icons/share_3_cute_re"
import { proxyEnv } from "@/src/lib/proxy-env"
import {
ActionGroup,
FeedShareActionButton,
HomeLeftAction,
HomeSharedRightAction,
MarkAllAsReadActionButton,
UnreadOnlyActionButton,
} from "@/src/modules/screen/action"
import { TimelineViewSelector } from "@/src/modules/screen/TimelineViewSelector"
import { getFeed } from "@/src/store/feed/getter"
import { useEntryListContext, useFetchEntriesControls, useSelectedFeedTitle } from "./atoms"
@@ -50,19 +45,18 @@ export function TimelineSelectorProvider({
)}
headerRight={useMemo(() => {
const Component = (() => {
const buttonVariant = isFeed ? "secondary" : "primary"
if (isTimeline)
return () => (
<HomeSharedRightAction>
<UnreadOnlyActionButton variant={buttonVariant} />
</HomeSharedRightAction>
)
if (isSubscriptions) return () => <HomeSharedRightAction />
if (isFeed)
if (isTimeline || isFeed)
return () => (
<ActionGroup>
<UnreadOnlyActionButton variant={buttonVariant} />
<FeedShareAction feedId={feedId} />
<UnreadOnlyActionButton />
<MarkAllAsReadActionButton />
<FeedShareActionButton feedId={feedId} />
</ActionGroup>
)
if (isSubscriptions)
return () => (
<ActionGroup>
<MarkAllAsReadActionButton />
</ActionGroup>
)
})()
@@ -78,26 +72,3 @@ export function TimelineSelectorProvider({
</>
)
}
function FeedShareAction({ feedId }: { feedId?: string }) {
const { t } = useTranslation()
const label = useColor("label")
if (!feedId) return null
return (
<UIBarButton
label={t("operation.share")}
normalIcon={<Share3CuteReIcon height={24} width={24} color={label} />}
onPress={() => {
const feed = getFeed(feedId)
if (!feed) return
const url = `${proxyEnv.WEB_URL}/share/feeds/${feedId}`
Share.share({
message: `Check out ${feed.title} on Folo: ${url}`,
title: feed.title!,
url,
})
}}
/>
)
}
+45 -18
View File
@@ -3,7 +3,7 @@ import * as Haptics from "expo-haptics"
import type { PropsWithChildren } from "react"
import { useCallback } from "react"
import { useTranslation } from "react-i18next"
import { TouchableOpacity, View } from "react-native"
import { Share, TouchableOpacity, View } from "react-native"
import { setGeneralSetting, useGeneralSettingKey } from "@/src/atoms/settings/general"
import { UserAvatar } from "@/src/components/ui/avatar/UserAvatar"
@@ -12,11 +12,14 @@ import { AddCuteReIcon } from "@/src/icons/add_cute_re"
import { CheckCircleCuteReIcon } from "@/src/icons/check_circle_cute_re"
import { RoundCuteFiIcon } from "@/src/icons/round_cute_fi"
import { RoundCuteReIcon } from "@/src/icons/round_cute_re"
import { Share3CuteReIcon } from "@/src/icons/share_3_cute_re"
import { Dialog } from "@/src/lib/dialog"
import { useNavigation } from "@/src/lib/navigation/hooks"
import { proxyEnv } from "@/src/lib/proxy-env"
import { toast } from "@/src/lib/toast"
import { LoginScreen } from "@/src/screens/(modal)/login"
import { ProfileScreen } from "@/src/screens/(modal)/profile"
import { getFeed } from "@/src/store/feed/getter"
import { useWhoami } from "@/src/store/user/hooks"
import { accentColor, useColor } from "@/src/theme/colors"
@@ -54,27 +57,25 @@ export function HomeLeftAction() {
)
}
export function HomeSharedRightAction(props: PropsWithChildren) {
const { t } = useTranslation()
return (
<ActionGroup>
{props.children}
<UIBarButton
label={t("operation.mark_all_as_read")}
normalIcon={<CheckCircleCuteReIcon height={24} width={24} color={accentColor} />}
onPress={() => {
Dialog.show(MarkAllAsReadDialog)
}}
/>
</ActionGroup>
)
}
interface HeaderActionButtonProps {
variant?: "primary" | "secondary"
}
export const MarkAllAsReadActionButton = ({ variant = "primary" }: HeaderActionButtonProps) => {
const { t } = useTranslation()
const { size, color } = useButtonVariant({ variant })
return (
<UIBarButton
label={t("operation.mark_all_as_read")}
normalIcon={<CheckCircleCuteReIcon height={size} width={size} color={color} />}
onPress={() => {
Dialog.show(MarkAllAsReadDialog)
}}
/>
)
}
const useButtonVariant = ({ variant = "primary" }: HeaderActionButtonProps) => {
const label = useColor("label")
const size = 24
@@ -121,3 +122,29 @@ export const AddFeedButton = () => {
/>
)
}
export const FeedShareActionButton = ({
feedId,
variant = "primary",
}: { feedId?: string } & HeaderActionButtonProps) => {
const { t } = useTranslation()
const { size, color } = useButtonVariant({ variant })
if (!feedId) return null
return (
<UIBarButton
label={t("operation.share")}
normalIcon={<Share3CuteReIcon height={size} width={size} color={color} />}
onPress={() => {
const feed = getFeed(feedId)
if (!feed) return
const url = `${proxyEnv.WEB_URL}/share/feeds/${feedId}`
Share.share({
message: `Check out ${feed.title} on Folo: ${url}`,
title: feed.title!,
url,
})
}}
/>
)
}