mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Properly clean and reset navigators
This commit is contained in:
@ -178,8 +178,6 @@ const Root: React.FC<NativeStackScreenProps<TabLocalStackParamList, 'Tab-Local-R
|
|||||||
})
|
})
|
||||||
}, [mode, queryKey[1], pageLocal, lists])
|
}, [mode, queryKey[1], pageLocal, lists])
|
||||||
|
|
||||||
usePopToTop()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Timeline
|
<Timeline
|
||||||
queryKey={queryKey}
|
queryKey={queryKey}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
||||||
import { TabLocalStackParamList } from '@utils/navigation/navigators'
|
import { TabLocalStackParamList } from '@utils/navigation/navigators'
|
||||||
|
import usePopToTop from '@utils/navigation/usePopToTop'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import TabShared from '../Shared'
|
import TabShared from '../Shared'
|
||||||
import Root from './Root'
|
import Root from './Root'
|
||||||
@ -7,6 +8,7 @@ import Root from './Root'
|
|||||||
const Stack = createNativeStackNavigator<TabLocalStackParamList>()
|
const Stack = createNativeStackNavigator<TabLocalStackParamList>()
|
||||||
|
|
||||||
const TabLocal: React.FC = () => {
|
const TabLocal: React.FC = () => {
|
||||||
|
usePopToTop()
|
||||||
return (
|
return (
|
||||||
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
||||||
<Stack.Screen name='Tab-Local-Root' component={Root} />
|
<Stack.Screen name='Tab-Local-Root' component={Root} />
|
||||||
|
@ -4,7 +4,6 @@ import TimelineDefault from '@components/Timeline/Default'
|
|||||||
import SegmentedControl from '@react-native-community/segmented-control'
|
import SegmentedControl from '@react-native-community/segmented-control'
|
||||||
import { NativeStackScreenProps } from '@react-navigation/native-stack'
|
import { NativeStackScreenProps } from '@react-navigation/native-stack'
|
||||||
import { TabPublicStackParamList } from '@utils/navigation/navigators'
|
import { TabPublicStackParamList } from '@utils/navigation/navigators'
|
||||||
import usePopToTop from '@utils/navigation/usePopToTop'
|
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||||
import { getGlobalStorage, setGlobalStorage } from '@utils/storage/actions'
|
import { getGlobalStorage, setGlobalStorage } from '@utils/storage/actions'
|
||||||
import { StorageGlobal } from '@utils/storage/global'
|
import { StorageGlobal } from '@utils/storage/global'
|
||||||
@ -75,8 +74,6 @@ const Root: React.FC<NativeStackScreenProps<TabPublicStackParamList, 'Tab-Public
|
|||||||
})
|
})
|
||||||
}, [mode, segment])
|
}, [mode, segment])
|
||||||
|
|
||||||
usePopToTop()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabView
|
<TabView
|
||||||
lazy
|
lazy
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
import { createNativeStackNavigator } from '@react-navigation/native-stack'
|
||||||
import { TabPublicStackParamList } from '@utils/navigation/navigators'
|
import { TabPublicStackParamList } from '@utils/navigation/navigators'
|
||||||
|
import usePopToTop from '@utils/navigation/usePopToTop'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import TabShared from '../Shared'
|
import TabShared from '../Shared'
|
||||||
import Root from './Root'
|
import Root from './Root'
|
||||||
@ -7,6 +8,7 @@ import Root from './Root'
|
|||||||
const Stack = createNativeStackNavigator<TabPublicStackParamList>()
|
const Stack = createNativeStackNavigator<TabPublicStackParamList>()
|
||||||
|
|
||||||
const TabPublic: React.FC = () => {
|
const TabPublic: React.FC = () => {
|
||||||
|
usePopToTop()
|
||||||
return (
|
return (
|
||||||
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
||||||
<Stack.Screen name='Tab-Public-Root' component={Root} />
|
<Stack.Screen name='Tab-Public-Root' component={Root} />
|
||||||
|
@ -145,24 +145,16 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
|||||||
useQuery(
|
useQuery(
|
||||||
queryKey.remote,
|
queryKey.remote,
|
||||||
async () => {
|
async () => {
|
||||||
let context:
|
|
||||||
| {
|
|
||||||
ancestors: Mastodon.Status[]
|
|
||||||
descendants: Mastodon.Status[]
|
|
||||||
}
|
|
||||||
| undefined
|
|
||||||
|
|
||||||
try {
|
|
||||||
const domain = getHost(toot.url || toot.uri)
|
const domain = getHost(toot.url || toot.uri)
|
||||||
if (!domain?.length) {
|
if (!domain?.length) {
|
||||||
throw new Error()
|
return Promise.reject('Cannot parse remote doamin')
|
||||||
}
|
}
|
||||||
const id = (toot.url || toot.uri).match(new RegExp(/\/([0-9]+)$/))?.[1]
|
const id = (toot.url || toot.uri).match(new RegExp(/\/([0-9]+)$/))?.[1]
|
||||||
if (!id?.length) {
|
if (!id?.length) {
|
||||||
throw new Error()
|
return Promise.reject('Cannot parse remote toot id')
|
||||||
}
|
}
|
||||||
|
|
||||||
context = await apiGeneral<{
|
const context = await apiGeneral<{
|
||||||
ancestors: Mastodon.Status[]
|
ancestors: Mastodon.Status[]
|
||||||
descendants: Mastodon.Status[]
|
descendants: Mastodon.Status[]
|
||||||
}>({
|
}>({
|
||||||
@ -170,10 +162,9 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
|||||||
domain,
|
domain,
|
||||||
url: `api/v1/statuses/${id}/context`
|
url: `api/v1/statuses/${id}/context`
|
||||||
}).then(res => res.body)
|
}).then(res => res.body)
|
||||||
} catch {}
|
|
||||||
|
|
||||||
if (!context) {
|
if (!context) {
|
||||||
throw new Error()
|
return Promise.reject('Cannot retrieve remote context')
|
||||||
}
|
}
|
||||||
|
|
||||||
const statuses: (Mastodon.Status & { _level?: number })[] = [
|
const statuses: (Mastodon.Status & { _level?: number })[] = [
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useNavigation } from '@react-navigation/native'
|
import { StackActions, useFocusEffect, useNavigation } from '@react-navigation/native'
|
||||||
import { useGlobalStorage } from '@utils/storage/actions'
|
import { useGlobalStorage } from '@utils/storage/actions'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
@ -8,8 +8,8 @@ const usePopToTop = () => {
|
|||||||
const navigation = useNavigation()
|
const navigation = useNavigation()
|
||||||
const [accountActive] = useGlobalStorage.string('account.active')
|
const [accountActive] = useGlobalStorage.string('account.active')
|
||||||
|
|
||||||
return useEffect(() => {
|
useEffect(() => {
|
||||||
// navigation.dispatch(StackActions.popToTop())
|
navigation.dispatch(StackActions.popToTop())
|
||||||
}, [accountActive])
|
}, [accountActive])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ const updateStatusProperty = ({
|
|||||||
if (!key) continue
|
if (!key) continue
|
||||||
|
|
||||||
queryClient.setQueryData<InfiniteData<TimelineData> | undefined>(key, old => {
|
queryClient.setQueryData<InfiniteData<TimelineData> | undefined>(key, old => {
|
||||||
console.log('key', key)
|
|
||||||
if (old) {
|
if (old) {
|
||||||
let foundToot: Mastodon.Status | undefined = undefined
|
let foundToot: Mastodon.Status | undefined = undefined
|
||||||
old.pages = old.pages.map(page => {
|
old.pages = old.pages.map(page => {
|
||||||
@ -42,7 +41,6 @@ const updateStatusProperty = ({
|
|||||||
|
|
||||||
if (foundToot) {
|
if (foundToot) {
|
||||||
const toot = foundToot as Mastodon.Status
|
const toot = foundToot as Mastodon.Status
|
||||||
console.log('updating', toot.id)
|
|
||||||
enum MapPropertyToCount {
|
enum MapPropertyToCount {
|
||||||
favourited = 'favourites_count',
|
favourited = 'favourites_count',
|
||||||
reblogged = 'reblogs_count'
|
reblogged = 'reblogs_count'
|
||||||
@ -53,9 +51,7 @@ const updateStatusProperty = ({
|
|||||||
toot.poll = poll
|
toot.poll = poll
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
console.log('11', toot[payload.type])
|
|
||||||
toot[payload.type] = payload.to
|
toot[payload.type] = payload.to
|
||||||
console.log('22', toot[payload.type])
|
|
||||||
switch (payload.type) {
|
switch (payload.type) {
|
||||||
case 'favourited':
|
case 'favourited':
|
||||||
case 'reblogged':
|
case 'reblogged':
|
||||||
|
@ -212,6 +212,7 @@ export const generateAccountKey = ({
|
|||||||
export const setAccount = async (account: string) => {
|
export const setAccount = async (account: string) => {
|
||||||
storage.account = new MMKV({ id: account })
|
storage.account = new MMKV({ id: account })
|
||||||
setGlobalStorage('account.active', account)
|
setGlobalStorage('account.active', account)
|
||||||
|
await queryClient.resetQueries()
|
||||||
queryClient.clear()
|
queryClient.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user