1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
This commit is contained in:
Zhiyuan Zheng
2021-02-10 00:40:44 +01:00
parent c46888acab
commit a40a645337
31 changed files with 593 additions and 558 deletions

View File

@ -4,7 +4,7 @@ import {
updateLocalNotification
} from '@utils/slices/instancesSlice'
import { useEffect, useRef } from 'react'
import { InfiniteData, useQueryClient } from 'react-query'
import { useQueryClient } from 'react-query'
import { useDispatch, useSelector } from 'react-redux'
import ReconnectingWebSocket from 'reconnecting-websocket'
@ -17,7 +17,12 @@ const useWebsocket = ({
}) => {
const queryClient = useQueryClient()
const dispatch = useDispatch()
const localInstance = useSelector(getLocalInstance)
const localInstance = useSelector(
getLocalInstance,
(prev, next) =>
prev?.urls.streaming_api === next?.urls.streaming_api &&
prev?.token === next?.token
)
const rws = useRef<ReconnectingWebSocket>()
useEffect(() => {
@ -40,16 +45,7 @@ const useWebsocket = ({
'Timeline',
{ page: 'Notifications' }
]
const queryData = queryClient.getQueryData(queryKey)
queryData !== undefined &&
queryClient.setQueryData<
InfiniteData<Mastodon.Notification[]> | undefined
>(queryKey, old => {
if (old) {
old.pages[0].unshift(payload)
return old
}
})
queryClient.invalidateQueries(queryKey)
break
}
}