From 26a9a56e5254c770dfbdf89614eea8b50ebb4ab1 Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Tue, 1 Jun 2021 22:27:27 +0200 Subject: [PATCH 1/2] Improve account page --- package.json | 2 +- src/i18n/en/screens/tabs.json | 4 ++ src/screens/Tabs/Me/Root/MyInfo.tsx | 2 +- src/screens/Tabs/Shared/Account.tsx | 71 +++++++++++++++---- .../Tabs/Shared/Account/Information.tsx | 9 ++- .../Tabs/Shared/Account/Information/Stats.tsx | 9 ++- src/utils/queryHooks/translate.ts | 2 +- 7 files changed, 78 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index de994fe4..9e17935e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "native": "210511", "major": 2, "minor": 0, - "patch": 2, + "patch": 3, "expo": "41.0.0" }, "description": "tooot app for Mastodon", diff --git a/src/i18n/en/screens/tabs.json b/src/i18n/en/screens/tabs.json index c87a7904..ddb1cbfb 100644 --- a/src/i18n/en/screens/tabs.json +++ b/src/i18n/en/screens/tabs.json @@ -265,6 +265,10 @@ "statuses_count": "{{count}} toots", "following_count": "$t(shared.users.accounts.following)", "followers_count": "$t(shared.users.accounts.followers)" + }, + "toots": { + "default": "Toots", + "all": "Toots and replies" } }, "attachments": { diff --git a/src/screens/Tabs/Me/Root/MyInfo.tsx b/src/screens/Tabs/Me/Root/MyInfo.tsx index 9a29eaef..b15839e0 100644 --- a/src/screens/Tabs/Me/Root/MyInfo.tsx +++ b/src/screens/Tabs/Me/Root/MyInfo.tsx @@ -10,7 +10,7 @@ const MyInfo: React.FC = ({ account }) => { return ( <> - + ) } diff --git a/src/screens/Tabs/Shared/Account.tsx b/src/screens/Tabs/Shared/Account.tsx index f105ed16..97e1161f 100644 --- a/src/screens/Tabs/Shared/Account.tsx +++ b/src/screens/Tabs/Shared/Account.tsx @@ -2,13 +2,16 @@ import analytics from '@components/analytics' import { HeaderRight } from '@components/Header' import Timeline from '@components/Timeline' import TimelineDefault from '@components/Timeline/Default' +import SegmentedControl from '@react-native-community/segmented-control' import { useAccountQuery } from '@utils/queryHooks/account' import { QueryKeyTimeline } from '@utils/queryHooks/timeline' +import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' -import React, { useCallback, useEffect, useMemo } from 'react' +import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { StyleSheet, View } from 'react-native' import { useSharedValue } from 'react-native-reanimated' +import { useIsFetching } from 'react-query' import AccountAttachments from './Account/Attachments' import AccountHeader from './Account/Header' import AccountInformation from './Account/Information' @@ -22,7 +25,7 @@ const TabSharedAccount: React.FC = ({ navigation }) => { const { t, i18n } = useTranslation('screenTabs') - const { theme } = useTheme() + const { mode, theme } = useTheme() const { data } = useAccountQuery({ id: account.id }) @@ -59,24 +62,60 @@ const TabSharedAccount: React.FC = ({ scrollY.value = nativeEvent.contentOffset.y }, []) - const ListHeaderComponent = useMemo(() => { - return ( - - - - - - ) - }, [data]) - - const queryKey: QueryKeyTimeline = [ + const [queryKey, setQueryKey] = useState([ 'Timeline', { page: 'Account_Default', account: account.id } - ] + ]) const renderItem = useCallback( ({ item }) => , [] ) + const isFetchingTimeline = useIsFetching(queryKey) + const fetchedTimeline = useRef(false) + useEffect(() => { + if (!isFetchingTimeline && !fetchedTimeline.current) { + fetchedTimeline.current = true + } + }, [isFetchingTimeline, fetchedTimeline.current]) + + const ListHeaderComponent = useMemo(() => { + return ( + <> + + + + {fetchedTimeline.current ? ( + + ) : null} + + { + switch (nativeEvent.selectedSegmentIndex) { + case 0: + setQueryKey([ + queryKey[0], + { ...queryKey[1], page: 'Account_Default' } + ]) + break + case 1: + setQueryKey([ + queryKey[0], + { ...queryKey[1], page: 'Account_All' } + ]) + break + } + }} + style={styles.segmentsContainer} + /> + + ) + }, [data, fetchedTimeline.current, i18n.language, mode]) return ( <> @@ -98,6 +137,10 @@ const TabSharedAccount: React.FC = ({ const styles = StyleSheet.create({ header: { borderBottomWidth: 1 + }, + segmentsContainer: { + marginTop: StyleConstants.Spacing.M, + marginHorizontal: StyleConstants.Spacing.Global.PagePadding } }) diff --git a/src/screens/Tabs/Shared/Account/Information.tsx b/src/screens/Tabs/Shared/Account/Information.tsx index 13a3c6ae..b754374b 100644 --- a/src/screens/Tabs/Shared/Account/Information.tsx +++ b/src/screens/Tabs/Shared/Account/Information.tsx @@ -1,3 +1,4 @@ +import { useRoute } from '@react-navigation/native' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React, { useCallback } from 'react' @@ -14,13 +15,15 @@ import AccountInformationStats from './Information/Stats' export interface Props { account: Mastodon.Account | undefined - myInfo?: boolean // Showing from my info page } const AccountInformation = React.memo( - ({ account, myInfo = false }: Props) => { + ({ account }: Props) => { const { mode, theme } = useTheme() + const { name } = useRoute() + const myInfo = name !== 'Tab-Shared-Account' + const animation = useCallback( props => ( @@ -46,7 +49,7 @@ const AccountInformation = React.memo(