mirror of https://github.com/tooot-app/app
Better lookback update
This commit is contained in:
parent
45ba984ea3
commit
bd49caa52a
|
@ -3,7 +3,7 @@
|
||||||
"versions": {
|
"versions": {
|
||||||
"native": "220102",
|
"native": "220102",
|
||||||
"major": 3,
|
"major": 3,
|
||||||
"minor": 1,
|
"minor": 2,
|
||||||
"patch": 0,
|
"patch": 0,
|
||||||
"expo": "44.0.0"
|
"expo": "44.0.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,6 +9,7 @@ import ScreenAnnouncements from '@screens/Announcements'
|
||||||
import ScreenCompose from '@screens/Compose'
|
import ScreenCompose from '@screens/Compose'
|
||||||
import ScreenImagesViewer from '@screens/ImagesViewer'
|
import ScreenImagesViewer from '@screens/ImagesViewer'
|
||||||
import ScreenTabs from '@screens/Tabs'
|
import ScreenTabs from '@screens/Tabs'
|
||||||
|
import initQuery from '@utils/initQuery'
|
||||||
import { RootStackParamList } from '@utils/navigation/navigators'
|
import { RootStackParamList } from '@utils/navigation/navigators'
|
||||||
import pushUseConnect from '@utils/push/useConnect'
|
import pushUseConnect from '@utils/push/useConnect'
|
||||||
import pushUseReceive from '@utils/push/useReceive'
|
import pushUseReceive from '@utils/push/useReceive'
|
||||||
|
@ -17,11 +18,7 @@ import { updatePreviousTab } from '@utils/slices/contextsSlice'
|
||||||
import { updateAccountPreferences } from '@utils/slices/instances/updateAccountPreferences'
|
import { updateAccountPreferences } from '@utils/slices/instances/updateAccountPreferences'
|
||||||
import { updateConfiguration } from '@utils/slices/instances/updateConfiguration'
|
import { updateConfiguration } from '@utils/slices/instances/updateConfiguration'
|
||||||
import { updateFilters } from '@utils/slices/instances/updateFilters'
|
import { updateFilters } from '@utils/slices/instances/updateFilters'
|
||||||
import {
|
import { getInstanceActive, getInstances } from '@utils/slices/instancesSlice'
|
||||||
getInstanceActive,
|
|
||||||
getInstances,
|
|
||||||
updateInstanceActive
|
|
||||||
} from '@utils/slices/instancesSlice'
|
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import { themes } from '@utils/styles/themes'
|
import { themes } from '@utils/styles/themes'
|
||||||
import * as Analytics from 'expo-firebase-analytics'
|
import * as Analytics from 'expo-firebase-analytics'
|
||||||
|
@ -76,9 +73,9 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
|
||||||
(prev, next) => prev.length === next.length
|
(prev, next) => prev.length === next.length
|
||||||
)
|
)
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
pushUseConnect({ mode, t, instances, dispatch })
|
pushUseConnect({ t, instances })
|
||||||
pushUseReceive({ queryClient, instances })
|
pushUseReceive({ instances })
|
||||||
pushUseRespond({ queryClient, instances, dispatch })
|
pushUseRespond({ instances })
|
||||||
|
|
||||||
// Prevent screenshot alert
|
// Prevent screenshot alert
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -165,8 +162,10 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
|
||||||
instance => paths[0] === `@${instance.account.acct}@${instance.uri}`
|
instance => paths[0] === `@${instance.account.acct}@${instance.uri}`
|
||||||
)
|
)
|
||||||
if (instanceIndex !== -1 && instanceActive !== instanceIndex) {
|
if (instanceIndex !== -1 && instanceActive !== instanceIndex) {
|
||||||
dispatch(updateInstanceActive(instances[instanceIndex]))
|
initQuery({
|
||||||
queryClient.clear()
|
instance: instances[instanceIndex],
|
||||||
|
prefetch: { enabled: true }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,6 @@ const Timeline: React.FC<Props> = ({
|
||||||
lookback,
|
lookback,
|
||||||
customProps
|
customProps
|
||||||
}) => {
|
}) => {
|
||||||
// Switching account update timeline
|
|
||||||
useSelector(getInstanceActive)
|
|
||||||
|
|
||||||
const { theme } = useTheme()
|
const { theme } = useTheme()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -152,6 +149,13 @@ const Timeline: React.FC<Props> = ({
|
||||||
])
|
])
|
||||||
|
|
||||||
useScrollToTop(flRef)
|
useScrollToTop(flRef)
|
||||||
|
useSelector(getInstanceActive, (prev, next) => {
|
||||||
|
if (prev !== next) {
|
||||||
|
flRef.current?.scrollToOffset({ offset: 0, animated: false })
|
||||||
|
}
|
||||||
|
return prev === next
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<TimelineRefresh
|
<TimelineRefresh
|
||||||
|
@ -162,7 +166,6 @@ const Timeline: React.FC<Props> = ({
|
||||||
disableRefresh={disableRefresh}
|
disableRefresh={disableRefresh}
|
||||||
/>
|
/>
|
||||||
<AnimatedFlatList
|
<AnimatedFlatList
|
||||||
// @ts-ignore
|
|
||||||
ref={customFLRef || flRef}
|
ref={customFLRef || flRef}
|
||||||
scrollEventThrottle={16}
|
scrollEventThrottle={16}
|
||||||
onScroll={onScroll}
|
onScroll={onScroll}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
RootStackScreenProps
|
RootStackScreenProps
|
||||||
} from '@utils/navigation/navigators'
|
} from '@utils/navigation/navigators'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import { findIndex } from 'lodash'
|
|
||||||
import React, { RefObject, useCallback, useRef, useState } from 'react'
|
import React, { RefObject, useCallback, useRef, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { Platform, Share, StatusBar, View } from 'react-native'
|
import { Platform, Share, StatusBar, View } from 'react-native'
|
||||||
|
@ -120,7 +119,7 @@ const ScreenImagesViewer = ({
|
||||||
|
|
||||||
const { mode } = useTheme()
|
const { mode } = useTheme()
|
||||||
|
|
||||||
const initialIndex = findIndex(imageUrls, ['id', id])
|
const initialIndex = imageUrls.findIndex(image => image.id === id)
|
||||||
const [currentIndex, setCurrentIndex] = useState(initialIndex)
|
const [currentIndex, setCurrentIndex] = useState(initialIndex)
|
||||||
|
|
||||||
const messageRef = useRef<FlashMessage>(null)
|
const messageRef = useRef<FlashMessage>(null)
|
||||||
|
|
|
@ -3,11 +3,11 @@ import Button from '@components/Button'
|
||||||
import haptics from '@components/haptics'
|
import haptics from '@components/haptics'
|
||||||
import ComponentInstance from '@components/Instance'
|
import ComponentInstance from '@components/Instance'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
|
import initQuery from '@utils/initQuery'
|
||||||
import {
|
import {
|
||||||
getInstanceActive,
|
getInstanceActive,
|
||||||
getInstances,
|
getInstances,
|
||||||
Instance,
|
Instance
|
||||||
updateInstanceActive
|
|
||||||
} from '@utils/slices/instancesSlice'
|
} from '@utils/slices/instancesSlice'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
|
@ -21,8 +21,7 @@ import {
|
||||||
View
|
View
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import { ScrollView } from 'react-native-gesture-handler'
|
import { ScrollView } from 'react-native-gesture-handler'
|
||||||
import { useQueryClient } from 'react-query'
|
import { useSelector } from 'react-redux'
|
||||||
import { useDispatch, useSelector } from 'react-redux'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
instance: Instance
|
instance: Instance
|
||||||
|
@ -30,9 +29,7 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
const AccountButton: React.FC<Props> = ({ instance, selected = false }) => {
|
const AccountButton: React.FC<Props> = ({ instance, selected = false }) => {
|
||||||
const queryClient = useQueryClient()
|
|
||||||
const navigation = useNavigation()
|
const navigation = useNavigation()
|
||||||
const dispatch = useDispatch()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
|
@ -45,8 +42,7 @@ const AccountButton: React.FC<Props> = ({ instance, selected = false }) => {
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
haptics('Light')
|
haptics('Light')
|
||||||
analytics('switch_existing_press')
|
analytics('switch_existing_press')
|
||||||
dispatch(updateInstanceActive(instance))
|
initQuery({ instance, prefetch: { enabled: true } })
|
||||||
queryClient.clear()
|
|
||||||
navigation.goBack()
|
navigation.goBack()
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -3,7 +3,6 @@ import TimelineDefault from '@components/Timeline/Default'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||||
import { findIndex } from 'lodash'
|
|
||||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import { FlatList } from 'react-native'
|
import { FlatList } from 'react-native'
|
||||||
import { InfiniteQueryObserver, useQueryClient } from 'react-query'
|
import { InfiniteQueryObserver, useQueryClient } from 'react-query'
|
||||||
|
@ -40,7 +39,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||||
}
|
}
|
||||||
if (!scrolled.current) {
|
if (!scrolled.current) {
|
||||||
scrolled.current = true
|
scrolled.current = true
|
||||||
const pointer = findIndex(flattenData, ['id', toot.id])
|
const pointer = flattenData.findIndex(({ id }) => id === toot.id)
|
||||||
try {
|
try {
|
||||||
pointer < flattenData.length &&
|
pointer < flattenData.length &&
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import apiInstance from '@api/instance'
|
import apiInstance from '@api/instance'
|
||||||
import NetInfo from '@react-native-community/netinfo'
|
import NetInfo from '@react-native-community/netinfo'
|
||||||
import { store } from '@root/store'
|
import { store } from '@root/store'
|
||||||
import { prefetchTimelineQuery } from '@utils/queryHooks/timeline'
|
import initQuery from '@utils/initQuery'
|
||||||
import { getPreviousTab } from '@utils/slices/contextsSlice'
|
import { getPreviousTab } from '@utils/slices/contextsSlice'
|
||||||
import removeInstance from '@utils/slices/instances/remove'
|
import removeInstance from '@utils/slices/instances/remove'
|
||||||
import {
|
import {
|
||||||
|
@ -62,43 +62,19 @@ const netInfo = async (): Promise<{
|
||||||
|
|
||||||
if (instance.timelinesLookback) {
|
if (instance.timelinesLookback) {
|
||||||
const previousTab = getPreviousTab(store.getState())
|
const previousTab = getPreviousTab(store.getState())
|
||||||
let loadPage: Extract<
|
let loadPage:
|
||||||
App.Pages,
|
| Extract<App.Pages, 'Following' | 'Local' | 'LocalPublic'>
|
||||||
'Following' | 'Local' | 'LocalPublic'
|
| undefined = undefined
|
||||||
> | void = undefined
|
|
||||||
if (previousTab === 'Tab-Local') {
|
if (previousTab === 'Tab-Local') {
|
||||||
loadPage = 'Following'
|
loadPage = 'Following'
|
||||||
} else if (previousTab === 'Tab-Public') {
|
} else if (previousTab === 'Tab-Public') {
|
||||||
loadPage = 'LocalPublic'
|
loadPage = 'LocalPublic'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loadPage) {
|
await initQuery({
|
||||||
if (instance.timelinesLookback?.[loadPage]?.ids.length > 0) {
|
instance,
|
||||||
log(
|
prefetch: { enabled: true, page: loadPage }
|
||||||
'log',
|
})
|
||||||
'netInfo',
|
|
||||||
`prefetching landing page ${instance.timelinesLookback[loadPage].queryKey[1].page} ids: ${instance.timelinesLookback[loadPage].ids}`
|
|
||||||
)
|
|
||||||
const prefetch = await prefetchTimelineQuery(
|
|
||||||
instance.timelinesLookback[loadPage]
|
|
||||||
)
|
|
||||||
if (prefetch) {
|
|
||||||
log('log', 'netInfo', `prefetched from status id ${prefetch}`)
|
|
||||||
} else {
|
|
||||||
log('error', 'netInfo', 'failed to prefetch')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const page of Object.keys(instance.timelinesLookback)) {
|
|
||||||
if (page !== loadPage) {
|
|
||||||
log(
|
|
||||||
'log',
|
|
||||||
'netInfo',
|
|
||||||
`prefetching other page ${instance.timelinesLookback[page].queryKey[1].page} ids: ${instance.timelinesLookback[page].ids}`
|
|
||||||
)
|
|
||||||
prefetchTimelineQuery(instance.timelinesLookback[page])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({ connected: true })
|
return Promise.resolve({ connected: true })
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
import queryClient from '@helpers/queryClient'
|
||||||
|
import { store } from '@root/store'
|
||||||
|
import { prefetchTimelineQuery } from './queryHooks/timeline'
|
||||||
|
import { Instance, updateInstanceActive } from './slices/instancesSlice'
|
||||||
|
|
||||||
|
const initQuery = async ({
|
||||||
|
instance,
|
||||||
|
prefetch
|
||||||
|
}: {
|
||||||
|
instance: Instance
|
||||||
|
prefetch?: { enabled: boolean; page?: 'Following' | 'LocalPublic' }
|
||||||
|
}) => {
|
||||||
|
store.dispatch(updateInstanceActive(instance))
|
||||||
|
await queryClient.resetQueries()
|
||||||
|
|
||||||
|
if (prefetch?.enabled && instance.timelinesLookback) {
|
||||||
|
if (
|
||||||
|
prefetch.page &&
|
||||||
|
instance.timelinesLookback[prefetch.page]?.ids?.length > 0
|
||||||
|
) {
|
||||||
|
await prefetchTimelineQuery(instance.timelinesLookback[prefetch.page])
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const page of Object.keys(instance.timelinesLookback)) {
|
||||||
|
if (page !== prefetch.page) {
|
||||||
|
prefetchTimelineQuery(instance.timelinesLookback[page])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default initQuery
|
|
@ -2,30 +2,32 @@ import apiGeneral from '@api/general'
|
||||||
import apiTooot from '@api/tooot'
|
import apiTooot from '@api/tooot'
|
||||||
import { displayMessage } from '@components/Message'
|
import { displayMessage } from '@components/Message'
|
||||||
import navigationRef from '@helpers/navigationRef'
|
import navigationRef from '@helpers/navigationRef'
|
||||||
import { Dispatch } from '@reduxjs/toolkit'
|
|
||||||
import { isDevelopment } from '@utils/checkEnvironment'
|
import { isDevelopment } from '@utils/checkEnvironment'
|
||||||
import { disableAllPushes, Instance } from '@utils/slices/instancesSlice'
|
import { disableAllPushes, Instance } from '@utils/slices/instancesSlice'
|
||||||
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import * as Notifications from 'expo-notifications'
|
import * as Notifications from 'expo-notifications'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { TFunction } from 'react-i18next'
|
import { TFunction } from 'react-i18next'
|
||||||
|
import { useDispatch } from 'react-redux'
|
||||||
|
|
||||||
export interface Params {
|
export interface Params {
|
||||||
mode: 'light' | 'dark'
|
|
||||||
t: TFunction<'screens'>
|
t: TFunction<'screens'>
|
||||||
instances: Instance[]
|
instances: Instance[]
|
||||||
dispatch: Dispatch<any>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const pushUseConnect = ({ mode, t, instances, dispatch }: Params) => {
|
const pushUseConnect = ({ t, instances }: Params) => {
|
||||||
|
const dispatch = useDispatch()
|
||||||
|
const { mode } = useTheme()
|
||||||
|
|
||||||
return useEffect(() => {
|
return useEffect(() => {
|
||||||
const connect = async () => {
|
const connect = async () => {
|
||||||
const expoToken = isDevelopment
|
const expoToken = isDevelopment
|
||||||
? 'DEVELOPMENT_TOKEN_1'
|
? 'DEVELOPMENT_TOKEN_1'
|
||||||
: (
|
: (
|
||||||
await Notifications.getExpoPushTokenAsync({
|
await Notifications.getExpoPushTokenAsync({
|
||||||
experienceId: '@xmflsct/tooot'
|
experienceId: '@xmflsct/tooot'
|
||||||
})
|
})
|
||||||
).data
|
).data
|
||||||
|
|
||||||
apiTooot({
|
apiTooot({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
import { displayMessage } from '@components/Message'
|
import { displayMessage } from '@components/Message'
|
||||||
|
import queryClient from '@helpers/queryClient'
|
||||||
|
import initQuery from '@utils/initQuery'
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||||
import { Instance, updateInstanceActive } from '@utils/slices/instancesSlice'
|
import { Instance, updateInstanceActive } from '@utils/slices/instancesSlice'
|
||||||
import * as Notifications from 'expo-notifications'
|
import * as Notifications from 'expo-notifications'
|
||||||
import { findIndex } from 'lodash'
|
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { QueryClient } from 'react-query'
|
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
import pushUseNavigate from './useNavigate'
|
import pushUseNavigate from './useNavigate'
|
||||||
|
|
||||||
export interface Params {
|
export interface Params {
|
||||||
queryClient: QueryClient
|
|
||||||
instances: Instance[]
|
instances: Instance[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const pushUseReceive = ({ queryClient, instances }: Params) => {
|
const pushUseReceive = ({ instances }: Params) => {
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
|
||||||
return useEffect(() => {
|
return useEffect(() => {
|
||||||
|
@ -30,8 +29,7 @@ const pushUseReceive = ({ queryClient, instances }: Params) => {
|
||||||
accountId: string
|
accountId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const notificationIndex = findIndex(
|
const notificationIndex = instances.findIndex(
|
||||||
instances,
|
|
||||||
instance =>
|
instance =>
|
||||||
instance.url === payloadData.instanceUrl &&
|
instance.url === payloadData.instanceUrl &&
|
||||||
instance.account.id === payloadData.accountId
|
instance.account.id === payloadData.accountId
|
||||||
|
@ -42,8 +40,10 @@ const pushUseReceive = ({ queryClient, instances }: Params) => {
|
||||||
description: notification.request.content.body!,
|
description: notification.request.content.body!,
|
||||||
onPress: () => {
|
onPress: () => {
|
||||||
if (notificationIndex !== -1) {
|
if (notificationIndex !== -1) {
|
||||||
dispatch(updateInstanceActive(instances[notificationIndex]))
|
initQuery({
|
||||||
queryClient.clear()
|
instance: instances[notificationIndex],
|
||||||
|
prefetch: { enabled: true }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
pushUseNavigate(payloadData.notification_id)
|
pushUseNavigate(payloadData.notification_id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
import { Dispatch } from '@reduxjs/toolkit'
|
import queryClient from '@helpers/queryClient'
|
||||||
|
import initQuery from '@utils/initQuery'
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||||
import { Instance, updateInstanceActive } from '@utils/slices/instancesSlice'
|
import { Instance } from '@utils/slices/instancesSlice'
|
||||||
import * as Notifications from 'expo-notifications'
|
import * as Notifications from 'expo-notifications'
|
||||||
import { findIndex } from 'lodash'
|
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { QueryClient } from 'react-query'
|
import { useDispatch } from 'react-redux'
|
||||||
import pushUseNavigate from './useNavigate'
|
import pushUseNavigate from './useNavigate'
|
||||||
|
|
||||||
export interface Params {
|
export interface Params {
|
||||||
queryClient: QueryClient
|
|
||||||
instances: Instance[]
|
instances: Instance[]
|
||||||
dispatch: Dispatch<any>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const pushUseRespond = ({ queryClient, instances, dispatch }: Params) => {
|
const pushUseRespond = ({ instances }: Params) => {
|
||||||
|
const dispatch = useDispatch()
|
||||||
|
|
||||||
return useEffect(() => {
|
return useEffect(() => {
|
||||||
const subscription = Notifications.addNotificationResponseReceivedListener(
|
const subscription = Notifications.addNotificationResponseReceivedListener(
|
||||||
({ notification }) => {
|
({ notification }) => {
|
||||||
|
@ -28,15 +28,16 @@ const pushUseRespond = ({ queryClient, instances, dispatch }: Params) => {
|
||||||
accountId: string
|
accountId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const notificationIndex = findIndex(
|
const notificationIndex = instances.findIndex(
|
||||||
instances,
|
|
||||||
instance =>
|
instance =>
|
||||||
instance.url === payloadData.instanceUrl &&
|
instance.url === payloadData.instanceUrl &&
|
||||||
instance.account.id === payloadData.accountId
|
instance.account.id === payloadData.accountId
|
||||||
)
|
)
|
||||||
if (notificationIndex !== -1) {
|
if (notificationIndex !== -1) {
|
||||||
dispatch(updateInstanceActive(instances[notificationIndex]))
|
initQuery({
|
||||||
queryClient.clear()
|
instance: instances[notificationIndex],
|
||||||
|
prefetch: { enabled: true }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
pushUseNavigate(payloadData.notification_id)
|
pushUseNavigate(payloadData.notification_id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import queryClient from '@helpers/queryClient'
|
import queryClient from '@helpers/queryClient'
|
||||||
import { findIndex } from 'lodash'
|
|
||||||
import { InfiniteData } from 'react-query'
|
import { InfiniteData } from 'react-query'
|
||||||
import {
|
import {
|
||||||
MutationVarsTimelineUpdateStatusProperty,
|
MutationVarsTimelineUpdateStatusProperty,
|
||||||
|
@ -37,7 +36,9 @@ const updateStatusProperty = ({
|
||||||
'boolean'
|
'boolean'
|
||||||
) {
|
) {
|
||||||
const items = page.body as Mastodon.Conversation[]
|
const items = page.body as Mastodon.Conversation[]
|
||||||
const tootIndex = findIndex(items, ['last_status.id', id])
|
const tootIndex = items.findIndex(
|
||||||
|
({ last_status }) => last_status?.id === id
|
||||||
|
)
|
||||||
if (tootIndex >= 0) {
|
if (tootIndex >= 0) {
|
||||||
foundToot = true
|
foundToot = true
|
||||||
updateConversation({ item: items[tootIndex], payload })
|
updateConversation({ item: items[tootIndex], payload })
|
||||||
|
@ -47,17 +48,18 @@ const updateStatusProperty = ({
|
||||||
typeof (page.body as Mastodon.Notification[])[0].type === 'string'
|
typeof (page.body as Mastodon.Notification[])[0].type === 'string'
|
||||||
) {
|
) {
|
||||||
const items = page.body as Mastodon.Notification[]
|
const items = page.body as Mastodon.Notification[]
|
||||||
const tootIndex = findIndex(items, ['status.id', id])
|
const tootIndex = items.findIndex(
|
||||||
|
({ status }) => status?.id === id
|
||||||
|
)
|
||||||
if (tootIndex >= 0) {
|
if (tootIndex >= 0) {
|
||||||
foundToot = true
|
foundToot = true
|
||||||
updateNotification({ item: items[tootIndex], payload })
|
updateNotification({ item: items[tootIndex], payload })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const items = page.body as Mastodon.Status[]
|
const items = page.body as Mastodon.Status[]
|
||||||
const tootIndex = findIndex(items, [
|
const tootIndex = reblog
|
||||||
reblog ? 'reblog.id' : 'id',
|
? items.findIndex(({ reblog }) => reblog?.id === id)
|
||||||
id
|
: items.findIndex(toot => toot.id === id)
|
||||||
])
|
|
||||||
// if favouriets page and notifications page, remove the item instead
|
// if favouriets page and notifications page, remove the item instead
|
||||||
if (tootIndex >= 0) {
|
if (tootIndex >= 0) {
|
||||||
foundToot = true
|
foundToot = true
|
||||||
|
@ -90,7 +92,9 @@ const updateStatusProperty = ({
|
||||||
'boolean'
|
'boolean'
|
||||||
) {
|
) {
|
||||||
const items = page.body as Mastodon.Conversation[]
|
const items = page.body as Mastodon.Conversation[]
|
||||||
const tootIndex = findIndex(items, ['last_status.id', id])
|
const tootIndex = items.findIndex(
|
||||||
|
({ last_status }) => last_status?.id === id
|
||||||
|
)
|
||||||
if (tootIndex >= 0) {
|
if (tootIndex >= 0) {
|
||||||
foundToot = true
|
foundToot = true
|
||||||
updateConversation({ item: items[tootIndex], payload })
|
updateConversation({ item: items[tootIndex], payload })
|
||||||
|
@ -101,17 +105,18 @@ const updateStatusProperty = ({
|
||||||
'string'
|
'string'
|
||||||
) {
|
) {
|
||||||
const items = page.body as Mastodon.Notification[]
|
const items = page.body as Mastodon.Notification[]
|
||||||
const tootIndex = findIndex(items, ['status.id', id])
|
const tootIndex = items.findIndex(
|
||||||
|
({ status }) => status?.id === id
|
||||||
|
)
|
||||||
if (tootIndex >= 0) {
|
if (tootIndex >= 0) {
|
||||||
foundToot = true
|
foundToot = true
|
||||||
updateNotification({ item: items[tootIndex], payload })
|
updateNotification({ item: items[tootIndex], payload })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const items = page.body as Mastodon.Status[]
|
const items = page.body as Mastodon.Status[]
|
||||||
const tootIndex = findIndex(items, [
|
const tootIndex = reblog
|
||||||
reblog ? 'reblog.id' : 'id',
|
? items.findIndex(({ reblog }) => reblog?.id === id)
|
||||||
id
|
: items.findIndex(toot => toot.id === id)
|
||||||
])
|
|
||||||
// if favouriets page and notifications page, remove the item instead
|
// if favouriets page and notifications page, remove the item instead
|
||||||
if (tootIndex >= 0) {
|
if (tootIndex >= 0) {
|
||||||
foundToot = true
|
foundToot = true
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||||
import { RootState } from '@root/store'
|
import { RootState } from '@root/store'
|
||||||
import { ComposeStateDraft } from '@screens/Compose/utils/types'
|
import { ComposeStateDraft } from '@screens/Compose/utils/types'
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||||
import { findIndex } from 'lodash'
|
|
||||||
import addInstance from './instances/add'
|
import addInstance from './instances/add'
|
||||||
import removeInstance from './instances/remove'
|
import removeInstance from './instances/remove'
|
||||||
import { updateAccountPreferences } from './instances/updateAccountPreferences'
|
import { updateAccountPreferences } from './instances/updateAccountPreferences'
|
||||||
|
@ -130,10 +129,9 @@ const instancesSlice = createSlice({
|
||||||
action: PayloadAction<ComposeStateDraft>
|
action: PayloadAction<ComposeStateDraft>
|
||||||
) => {
|
) => {
|
||||||
const activeIndex = findInstanceActive(instances)
|
const activeIndex = findInstanceActive(instances)
|
||||||
const draftIndex = findIndex(instances[activeIndex].drafts, [
|
const draftIndex = instances[activeIndex].drafts.findIndex(
|
||||||
'timestamp',
|
({ timestamp }) => timestamp === action.payload.timestamp
|
||||||
action.payload.timestamp
|
)
|
||||||
])
|
|
||||||
if (draftIndex === -1) {
|
if (draftIndex === -1) {
|
||||||
instances[activeIndex].drafts.unshift(action.payload)
|
instances[activeIndex].drafts.unshift(action.payload)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue