From 7f97908e236fa528b7d03daa8fcf3ef47dfef240 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Wed, 11 Jan 2023 22:54:24 +0100 Subject: [PATCH] Fix bugs --- .../Timeline/Shared/HeaderShared/Replies.tsx | 8 +++++--- src/screens/AccountSelection.tsx | 2 +- src/screens/Compose/Root/Drafts.tsx | 2 +- src/screens/Tabs/Me/Root/Collections.tsx | 6 +++--- src/screens/Tabs/Notifications/Filters.tsx | 8 ++++---- src/screens/Tabs/Public/Root.tsx | 5 ++++- src/utils/queryHooks/search.ts | 2 +- src/utils/storage/actions.ts | 15 ++++++++------- 8 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/components/Timeline/Shared/HeaderShared/Replies.tsx b/src/components/Timeline/Shared/HeaderShared/Replies.tsx index 5cf8e9ab..52592763 100644 --- a/src/components/Timeline/Shared/HeaderShared/Replies.tsx +++ b/src/components/Timeline/Shared/HeaderShared/Replies.tsx @@ -14,9 +14,11 @@ const HeaderSharedReplies: React.FC = () => { const { t } = useTranslation(['common', 'componentTimeline']) const { colors } = useTheme() - const mentionsBeginning = rawContent?.current?.[0] - .match(new RegExp(/^(?:@\S+\s+)+/))?.[0] - ?.match(new RegExp(/@\S+/, 'g')) + const mentionsBeginning = rawContent?.current?.[0]?.length + ? rawContent?.current?.[0] + .match(new RegExp(/^(?:@\S+\s+)+/))?.[0] + ?.match(new RegExp(/@\S+/, 'g')) + : undefined excludeMentions && (excludeMentions.current = mentionsBeginning?.length && status?.mentions diff --git a/src/screens/AccountSelection.tsx b/src/screens/AccountSelection.tsx index 381882cb..5d59c270 100644 --- a/src/screens/AccountSelection.tsx +++ b/src/screens/AccountSelection.tsx @@ -92,7 +92,7 @@ const ScreenAccountSelection = ({ const { colors } = useTheme() const { t } = useTranslation('screenAccountSelection') - const accounts = getReadableAccounts() + const accounts = getReadableAccounts(true) return ( = ({ accessibleRefDrafts }) => { const navigation = useNavigation() const { composeState } = useContext(ComposeContext) const [drafts] = useAccountStorage.object('drafts') - const draftsCount = drafts.filter(draft => draft.timestamp !== composeState.timestamp).length + const draftsCount = drafts?.filter(draft => draft.timestamp !== composeState.timestamp).length useEffect(() => { layoutAnimation() diff --git a/src/screens/Tabs/Me/Root/Collections.tsx b/src/screens/Tabs/Me/Root/Collections.tsx index b836f42c..8e99c785 100644 --- a/src/screens/Tabs/Me/Root/Collections.tsx +++ b/src/screens/Tabs/Me/Root/Collections.tsx @@ -60,7 +60,7 @@ const Collections: React.FC = () => { title={t('screenTabs:me.stacks.favourites.name')} onPress={() => navigation.navigate('Tab-Me-Favourites')} /> - {pageMe.lists.shown ? ( + {pageMe.lists?.shown ? ( { onPress={() => navigation.navigate('Tab-Me-List-List')} /> ) : null} - {pageMe.followedTags.shown ? ( + {pageMe.followedTags?.shown ? ( { onPress={() => navigation.navigate('Tab-Me-FollowedTags')} /> ) : null} - {pageMe.announcements.shown ? ( + {pageMe.announcements?.shown ? ( setFilters({ ...filters, [type]: !filters[type] })} + switchValue={filters?.[type]} + switchOnValueChange={() => setFilters({ ...filters, [type]: !filters?.[type] })} /> ))} @@ -80,8 +80,8 @@ const TabNotificationsFilters: React.FC< setFilters({ ...filters, [type]: !filters[type] })} + switchValue={filters?.[type]} + switchOnValueChange={() => setFilters({ ...filters, [type]: !filters?.[type] })} /> ))} diff --git a/src/screens/Tabs/Public/Root.tsx b/src/screens/Tabs/Public/Root.tsx index ef5054ec..9633aa41 100644 --- a/src/screens/Tabs/Public/Root.tsx +++ b/src/screens/Tabs/Public/Root.tsx @@ -38,7 +38,10 @@ const Root: React.FC( - segments.findIndex(segment => segment === previousSegment) + Math.min( + 0, + segments.findIndex(segment => segment === previousSegment) + ) ) const [routes] = useState([ { key: 'Local', title: t('tabs.public.segments.local') }, diff --git a/src/utils/queryHooks/search.ts b/src/utils/queryHooks/search.ts index 2812fa86..0f75cdc9 100644 --- a/src/utils/queryHooks/search.ts +++ b/src/utils/queryHooks/search.ts @@ -52,7 +52,7 @@ export const searchLocalStatus = async (uri: Mastodon.Status['uri']): Promise - res.statuses[0].uri === uri || res.statuses[0].url === uri + res.statuses[0]?.uri === uri || res.statuses[0]?.url === uri ? res.statuses[0] : Promise.reject() ) diff --git a/src/utils/storage/actions.ts b/src/utils/storage/actions.ts index 919f0854..584c4005 100644 --- a/src/utils/storage/actions.ts +++ b/src/utils/storage/actions.ts @@ -233,14 +233,15 @@ export type ReadableAccountType = { key: string active: boolean } -export const getReadableAccounts = (): ReadableAccountType[] => { - const accountActive = getGlobalStorage.string('account.active') +export const getReadableAccounts = (withoutActive: boolean = false): ReadableAccountType[] => { + const accountActive = !withoutActive && getGlobalStorage.string('account.active') const accounts = getGlobalStorage.object('accounts')?.sort((a, b) => a.localeCompare(b)) - accounts?.splice( - accounts.findIndex(a => a === accountActive), - 1 - ) - accounts?.unshift(accountActive || '') + !withoutActive && + accounts?.splice( + accounts.findIndex(a => a === accountActive), + 1 + ) + !withoutActive && accounts?.unshift(accountActive || '') return ( accounts?.map(account => { const details = getAccountDetails(