mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Rewrite timeline logic
This commit is contained in:
@ -1,24 +0,0 @@
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { useQuery, UseQueryOptions } from 'react-query'
|
||||
|
||||
export type QueryKey = ['Push']
|
||||
|
||||
const queryFunction = async () => {
|
||||
const res = await apiInstance<Mastodon.PushSubscription>({
|
||||
method: 'get',
|
||||
url: 'push/subscription'
|
||||
})
|
||||
return res.body
|
||||
}
|
||||
|
||||
const usePushQuery = <TData = Mastodon.PushSubscription>({
|
||||
options
|
||||
}: {
|
||||
options?: UseQueryOptions<Mastodon.PushSubscription, AxiosError, TData>
|
||||
}) => {
|
||||
const queryKey: QueryKey = ['Push']
|
||||
return useQuery(queryKey, queryFunction, options)
|
||||
}
|
||||
|
||||
export { usePushQuery }
|
@ -2,7 +2,7 @@ import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query'
|
||||
|
||||
export type QueryKey = [
|
||||
export type QueryKeyRelationships = [
|
||||
'Relationships',
|
||||
{ type: 'following' | 'followers'; id: Mastodon.Account['id'] }
|
||||
]
|
||||
@ -11,7 +11,7 @@ const queryFunction = ({
|
||||
queryKey,
|
||||
pageParam
|
||||
}: {
|
||||
queryKey: QueryKey
|
||||
queryKey: QueryKeyRelationships
|
||||
pageParam?: { [key: string]: string }
|
||||
}) => {
|
||||
const { type, id } = queryKey[1]
|
||||
@ -27,7 +27,7 @@ const queryFunction = ({
|
||||
const useRelationshipsQuery = <TData = Mastodon.Account[]>({
|
||||
options,
|
||||
...queryKeyParams
|
||||
}: QueryKey[1] & {
|
||||
}: QueryKeyRelationships[1] & {
|
||||
options?: UseInfiniteQueryOptions<
|
||||
{
|
||||
body: Mastodon.Account[]
|
||||
@ -37,7 +37,10 @@ const useRelationshipsQuery = <TData = Mastodon.Account[]>({
|
||||
TData
|
||||
>
|
||||
}) => {
|
||||
const queryKey: QueryKey = ['Relationships', { ...queryKeyParams }]
|
||||
const queryKey: QueryKeyRelationships = [
|
||||
'Relationships',
|
||||
{ ...queryKeyParams }
|
||||
]
|
||||
return useInfiniteQuery(queryKey, queryFunction, options)
|
||||
}
|
||||
|
||||
|
@ -362,7 +362,7 @@ const useTimelineMutation = ({
|
||||
let oldData
|
||||
params.queryKey && (oldData = queryClient.getQueryData(params.queryKey))
|
||||
|
||||
haptics('Success')
|
||||
haptics('Light')
|
||||
switch (params.type) {
|
||||
case 'updateStatusProperty':
|
||||
updateStatusProperty({ queryClient, ...params })
|
||||
|
@ -24,7 +24,10 @@ const updateStatus = ({
|
||||
? !payload.currentValue
|
||||
: true
|
||||
if (payload.propertyCount) {
|
||||
if (typeof payload.currentValue === 'boolean' && payload.currentValue) {
|
||||
if (
|
||||
typeof payload.currentValue === 'boolean' &&
|
||||
payload.currentValue
|
||||
) {
|
||||
item.reblog![payload.propertyCount] = payload.countValue - 1
|
||||
} else {
|
||||
item.reblog![payload.propertyCount] = payload.countValue + 1
|
||||
@ -36,7 +39,10 @@ const updateStatus = ({
|
||||
? !payload.currentValue
|
||||
: true
|
||||
if (payload.propertyCount) {
|
||||
if (typeof payload.currentValue === 'boolean' && payload.currentValue) {
|
||||
if (
|
||||
typeof payload.currentValue === 'boolean' &&
|
||||
payload.currentValue
|
||||
) {
|
||||
item[payload.propertyCount] = payload.countValue - 1
|
||||
} else {
|
||||
item[payload.propertyCount] = payload.countValue + 1
|
||||
|
Reference in New Issue
Block a user