mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Using react-query 3
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
import client from '@api/client'
|
||||
|
||||
export const accountFetch = async (
|
||||
key: string,
|
||||
{ id }: { id: string }
|
||||
): Promise<Mastodon.Account> => {
|
||||
export const accountFetch = async ({
|
||||
queryKey
|
||||
}: {
|
||||
queryKey: QueryKey.Account
|
||||
}): Promise<Mastodon.Account> => {
|
||||
const [_, { id }] = queryKey
|
||||
|
||||
const res = await client({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
|
@ -1,9 +1,12 @@
|
||||
import client from '@api/client'
|
||||
|
||||
export const applicationFetch = async (
|
||||
key: string,
|
||||
{ instanceDomain }: { instanceDomain: string }
|
||||
): Promise<Mastodon.AppOauth> => {
|
||||
export const applicationFetch = async ({
|
||||
queryKey
|
||||
}: {
|
||||
queryKey: QueryKey.Application
|
||||
}): Promise<Mastodon.AppOauth> => {
|
||||
const [_, { instanceDomain }] = queryKey
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append('client_name', 'test_dudu')
|
||||
formData.append('redirect_uris', 'exp://127.0.0.1:19000')
|
||||
|
@ -1,9 +1,12 @@
|
||||
import client from '@api/client'
|
||||
|
||||
export const instanceFetch = async (
|
||||
key: string,
|
||||
{ instanceDomain }: { instanceDomain: string }
|
||||
): Promise<Mastodon.Instance> => {
|
||||
export const instanceFetch = async ({
|
||||
queryKey
|
||||
}: {
|
||||
queryKey: QueryKey.Instance
|
||||
}): Promise<Mastodon.Instance> => {
|
||||
const [_, { instanceDomain }] = queryKey
|
||||
|
||||
const res = await client({
|
||||
method: 'get',
|
||||
instance: 'remote',
|
||||
|
@ -1,9 +1,12 @@
|
||||
import client from '@api/client'
|
||||
|
||||
export const relationshipFetch = async (
|
||||
key: string,
|
||||
{ id }: { id: string }
|
||||
): Promise<Mastodon.Relationship> => {
|
||||
export const relationshipFetch = async ({
|
||||
queryKey
|
||||
}: {
|
||||
queryKey: QueryKey.Relationship
|
||||
}): Promise<Mastodon.Relationship> => {
|
||||
const [_, { id }] = queryKey
|
||||
|
||||
const res = await client({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
|
@ -1,17 +1,10 @@
|
||||
import client from '@api/client'
|
||||
|
||||
export const searchFetch = async (
|
||||
{} = {},
|
||||
{
|
||||
type,
|
||||
term,
|
||||
limit = 20
|
||||
}: {
|
||||
type?: 'accounts' | 'hashtags' | 'statuses'
|
||||
term: string
|
||||
limit?: number
|
||||
}
|
||||
): Promise<
|
||||
export const searchFetch = async ({
|
||||
queryKey
|
||||
}: {
|
||||
queryKey: QueryKey.Search
|
||||
}): Promise<
|
||||
| Mastodon.Account[]
|
||||
| Mastodon.Tag[]
|
||||
| Mastodon.Status[]
|
||||
@ -21,6 +14,7 @@ export const searchFetch = async (
|
||||
statuses: Mastodon.Status[]
|
||||
}
|
||||
> => {
|
||||
const [_, { type, term, limit = 20 }] = queryKey
|
||||
const res = await client({
|
||||
version: 'v2',
|
||||
method: 'get',
|
||||
|
@ -2,43 +2,28 @@ import { uniqBy } from 'lodash'
|
||||
|
||||
import client from '@api/client'
|
||||
|
||||
export const timelineFetch = async (
|
||||
key: string,
|
||||
{
|
||||
page,
|
||||
params = {},
|
||||
account,
|
||||
hashtag,
|
||||
list,
|
||||
toot
|
||||
}: {
|
||||
page: App.Pages
|
||||
params?: {
|
||||
[key: string]: string | number | boolean
|
||||
}
|
||||
hashtag?: Mastodon.Tag['name']
|
||||
list?: Mastodon.List['id']
|
||||
toot?: Mastodon.Status
|
||||
account?: Mastodon.Account['id']
|
||||
},
|
||||
pagination: {
|
||||
direction: 'prev' | 'next'
|
||||
id: string
|
||||
}
|
||||
): Promise<{
|
||||
export const timelineFetch = async ({
|
||||
queryKey,
|
||||
pageParam
|
||||
}: {
|
||||
queryKey: QueryKey.Timeline
|
||||
pageParam?: { direction: 'prev' | 'next'; id: Mastodon.Status['id'] }
|
||||
}): Promise<{
|
||||
toots: Mastodon.Status[]
|
||||
pointer?: number
|
||||
pinnedLength?: number
|
||||
}> => {
|
||||
const [page, { account, hashtag, list, toot }] = queryKey
|
||||
let res
|
||||
let params: { [key: string]: string } = {}
|
||||
|
||||
if (pagination && pagination.id) {
|
||||
switch (pagination.direction) {
|
||||
if (pageParam) {
|
||||
switch (pageParam.direction) {
|
||||
case 'prev':
|
||||
params.min_id = pagination.id
|
||||
params.min_id = pageParam.id
|
||||
break
|
||||
case 'next':
|
||||
params.max_id = pagination.id
|
||||
params.max_id = pageParam.id
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -91,8 +76,8 @@ export const timelineFetch = async (
|
||||
return Promise.resolve({ toots: res.body })
|
||||
|
||||
case 'Account_Default':
|
||||
if (pagination && pagination.id) {
|
||||
if (pagination.direction === 'prev') {
|
||||
if (pageParam) {
|
||||
if (pageParam.direction === 'prev') {
|
||||
res = await client({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
@ -175,10 +160,10 @@ export const timelineFetch = async (
|
||||
url: `conversations`,
|
||||
params
|
||||
})
|
||||
if (pagination) {
|
||||
if (pageParam) {
|
||||
// Bug in pull to refresh in conversations
|
||||
res.body = res.body.filter(
|
||||
(b: Mastodon.Conversation) => b.id !== pagination.id
|
||||
(b: Mastodon.Conversation) => b.id !== pageParam.id
|
||||
)
|
||||
}
|
||||
return Promise.resolve({ toots: res.body })
|
||||
@ -220,5 +205,7 @@ export const timelineFetch = async (
|
||||
toots: [...res.body.ancestors, toot, ...res.body.descendants],
|
||||
pointer: res.body.ancestors.length
|
||||
})
|
||||
default:
|
||||
return Promise.reject()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user