1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Add promise type to fetches

This commit is contained in:
Zhiyuan Zheng
2020-12-15 00:01:48 +01:00
parent fe1ca72a3e
commit a3335a1f88
12 changed files with 50 additions and 24 deletions

View File

@ -1,6 +1,9 @@
import client from '@api/client'
export const accountFetch = async (key: string, { id }: { id: string }) => {
export const accountFetch = async (
key: string,
{ id }: { id: string }
): Promise<Mastodon.Account> => {
const res = await client({
method: 'get',
instance: 'local',

View File

@ -2,8 +2,8 @@ import client from '@api/client'
export const applicationFetch = async (
key: string,
{ instanceDomain, body }: { instanceDomain: string; body: FormData }
) => {
{ instanceDomain }: { instanceDomain: string }
): Promise<Mastodon.AppOauth> => {
const formData = new FormData()
formData.append('client_name', 'test_dudu')
formData.append('redirect_uris', 'exp://127.0.0.1:19000')

View File

@ -1,6 +1,6 @@
import client from '@api/client'
export const emojisFetch = async () => {
export const emojisFetch = async (): Promise<Mastodon.Emoji[]> => {
const res = await client({
method: 'get',
instance: 'local',

View File

@ -3,7 +3,7 @@ import client from '@api/client'
export const instanceFetch = async (
key: string,
{ instanceDomain }: { instanceDomain: string }
) => {
): Promise<Mastodon.Instance> => {
const res = await client({
method: 'get',
instance: 'remote',

View File

@ -1,6 +1,6 @@
import client from '@api/client'
export const listsFetch = async () => {
export const listsFetch = async (): Promise<Mastodon.List[]> => {
const res = await client({
method: 'get',
instance: 'local',

View File

@ -3,7 +3,7 @@ import client from '@api/client'
export const relationshipFetch = async (
key: string,
{ id }: { id: string }
) => {
): Promise<Mastodon.Relationship> => {
const res = await client({
method: 'get',
instance: 'local',

View File

@ -7,17 +7,30 @@ export const searchFetch = async (
term,
limit = 20
}: {
type: 'accounts' | 'hashtags' | 'statuses'
type?: 'accounts' | 'hashtags' | 'statuses'
term: string
limit?: number
}
) => {
): Promise<
| Mastodon.Account[]
| Mastodon.Tag[]
| Mastodon.Status[]
| {
accounts: Mastodon.Account[]
hashtags: Mastodon.Tag[]
statuses: Mastodon.Status[]
}
> => {
const res = await client({
version: 'v2',
method: 'get',
instance: 'local',
url: 'search',
params: { type, q: term, limit }
params: { ...(type && { type }), q: term, limit }
})
return Promise.resolve(res.body[type])
if (type) {
return Promise.resolve(res.body[type])
} else {
return Promise.resolve(res.body)
}
}