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

@ -38,6 +38,16 @@ declare namespace Mastodon {
vapid_key?: string vapid_key?: string
} }
type AppOauth = {
id: string
name: string
website?: string
redirect_uri: string
client_id: string
client_secret: string
vapid_key: string
}
type Attachment = type Attachment =
| AttachmentImage | AttachmentImage
| AttachmentVideo | AttachmentVideo

View File

@ -64,12 +64,12 @@ const TimelineHeaderNotification: React.FC<Props> = ({ notification }) => {
? updateData.following || updateData.requested ? updateData.following || updateData.requested
? 'un' ? 'un'
: '' : ''
: data.following || data.requested : data!.following || data!.requested
? 'un' ? 'un'
: '' : ''
}follow` }follow`
}).then(res => { }).then(res => {
if (res.body.id === (updateData && updateData.id) || data.id) { if (res.body.id === (updateData && updateData.id) || data!.id) {
setUpdateData(res.body) setUpdateData(res.body)
return Promise.resolve() return Promise.resolve()
} else { } else {
@ -100,9 +100,9 @@ const TimelineHeaderNotification: React.FC<Props> = ({ notification }) => {
: updateData.requested : updateData.requested
? 'loader' ? 'loader'
: 'user-plus' : 'user-plus'
: data.following : data!.following
? 'user-check' ? 'user-check'
: data.requested : data!.requested
? 'loader' ? 'loader'
: 'user-plus' : 'user-plus'
} }
@ -111,7 +111,7 @@ const TimelineHeaderNotification: React.FC<Props> = ({ notification }) => {
? updateData.following ? updateData.following
? theme.primary ? theme.primary
: theme.secondary : theme.secondary
: data.following : data!.following
? theme.primary ? theme.primary
: theme.secondary : theme.secondary
} }

View File

@ -131,7 +131,7 @@ const Login: React.FC = () => {
parse parse
}: { }: {
header: string header: string
content: string content?: string
parse?: boolean parse?: boolean
}) => { }) => {
return ( return (
@ -140,7 +140,7 @@ const Login: React.FC = () => {
{header} {header}
</Text> </Text>
<ShimmerPlaceholder <ShimmerPlaceholder
visible={instanceQuery.data?.uri} visible={instanceQuery.data?.uri !== undefined}
stopAutoRun stopAutoRun
width={ width={
Dimensions.get('screen').width - Dimensions.get('screen').width -
@ -152,7 +152,7 @@ const Login: React.FC = () => {
style={[styles.instanceInfoContent, { color: theme.primary }]} style={[styles.instanceInfoContent, { color: theme.primary }]}
> >
{parse ? ( {parse ? (
<ParseContent content={content} size={'M'} numberOfLines={5} /> <ParseContent content={content!} size={'M'} numberOfLines={5} />
) : ( ) : (
content content
)} )}
@ -230,7 +230,7 @@ const Login: React.FC = () => {
</Text> </Text>
<ShimmerPlaceholder <ShimmerPlaceholder
visible={instanceQuery.data?.stats?.user_count} visible={instanceQuery.data?.stats?.user_count !== undefined}
stopAutoRun stopAutoRun
width={StyleConstants.Font.Size.M * 4} width={StyleConstants.Font.Size.M * 4}
height={StyleConstants.Font.Size.M} height={StyleConstants.Font.Size.M}
@ -249,7 +249,7 @@ const Login: React.FC = () => {
</Text> </Text>
<ShimmerPlaceholder <ShimmerPlaceholder
visible={instanceQuery.data?.stats?.user_count} visible={instanceQuery.data?.stats?.user_count !== undefined}
stopAutoRun stopAutoRun
width={StyleConstants.Font.Size.M * 4} width={StyleConstants.Font.Size.M * 4}
height={StyleConstants.Font.Size.M} height={StyleConstants.Font.Size.M}
@ -268,7 +268,7 @@ const Login: React.FC = () => {
</Text> </Text>
<ShimmerPlaceholder <ShimmerPlaceholder
visible={instanceQuery.data?.stats?.user_count} visible={instanceQuery.data?.stats?.user_count !== undefined}
stopAutoRun stopAutoRun
width={StyleConstants.Font.Size.M * 4} width={StyleConstants.Font.Size.M * 4}
height={StyleConstants.Font.Size.M} height={StyleConstants.Font.Size.M}

View File

@ -2,7 +2,7 @@ import React, { useEffect, useRef } from 'react'
import { Animated, Dimensions, Image, StyleSheet } from 'react-native' import { Animated, Dimensions, Image, StyleSheet } from 'react-native'
export interface Props { export interface Props {
uri: Mastodon.Account['header'] uri?: Mastodon.Account['header']
limitHeight?: boolean limitHeight?: boolean
} }

View File

@ -196,7 +196,7 @@ const ComposeRoot: React.FC = () => {
ListHeaderComponent={<ComposeRootHeader />} ListHeaderComponent={<ComposeRootHeader />}
ListFooterComponent={<ComposeRootFooter textInputRef={textInputRef} />} ListFooterComponent={<ComposeRootFooter textInputRef={textInputRef} />}
ListEmptyComponent={listEmpty} ListEmptyComponent={listEmpty}
data={data} data={data as Mastodon.Account[] & Mastodon.Tag[]}
keyExtractor={listKey} keyExtractor={listKey}
renderItem={listItem} renderItem={listItem}
/> />

View File

@ -1,6 +1,9 @@
import client from '@api/client' 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({ const res = await client({
method: 'get', method: 'get',
instance: 'local', instance: 'local',

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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