mirror of https://github.com/tooot-app/app
Add promise type to fetches
This commit is contained in:
parent
fe1ca72a3e
commit
a3335a1f88
|
@ -38,6 +38,16 @@ declare namespace Mastodon {
|
|||
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 =
|
||||
| AttachmentImage
|
||||
| AttachmentVideo
|
||||
|
|
|
@ -64,12 +64,12 @@ const TimelineHeaderNotification: React.FC<Props> = ({ notification }) => {
|
|||
? updateData.following || updateData.requested
|
||||
? 'un'
|
||||
: ''
|
||||
: data.following || data.requested
|
||||
: data!.following || data!.requested
|
||||
? 'un'
|
||||
: ''
|
||||
}follow`
|
||||
}).then(res => {
|
||||
if (res.body.id === (updateData && updateData.id) || data.id) {
|
||||
if (res.body.id === (updateData && updateData.id) || data!.id) {
|
||||
setUpdateData(res.body)
|
||||
return Promise.resolve()
|
||||
} else {
|
||||
|
@ -100,9 +100,9 @@ const TimelineHeaderNotification: React.FC<Props> = ({ notification }) => {
|
|||
: updateData.requested
|
||||
? 'loader'
|
||||
: 'user-plus'
|
||||
: data.following
|
||||
: data!.following
|
||||
? 'user-check'
|
||||
: data.requested
|
||||
: data!.requested
|
||||
? 'loader'
|
||||
: 'user-plus'
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ const TimelineHeaderNotification: React.FC<Props> = ({ notification }) => {
|
|||
? updateData.following
|
||||
? theme.primary
|
||||
: theme.secondary
|
||||
: data.following
|
||||
: data!.following
|
||||
? theme.primary
|
||||
: theme.secondary
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ const Login: React.FC = () => {
|
|||
parse
|
||||
}: {
|
||||
header: string
|
||||
content: string
|
||||
content?: string
|
||||
parse?: boolean
|
||||
}) => {
|
||||
return (
|
||||
|
@ -140,7 +140,7 @@ const Login: React.FC = () => {
|
|||
{header}
|
||||
</Text>
|
||||
<ShimmerPlaceholder
|
||||
visible={instanceQuery.data?.uri}
|
||||
visible={instanceQuery.data?.uri !== undefined}
|
||||
stopAutoRun
|
||||
width={
|
||||
Dimensions.get('screen').width -
|
||||
|
@ -152,7 +152,7 @@ const Login: React.FC = () => {
|
|||
style={[styles.instanceInfoContent, { color: theme.primary }]}
|
||||
>
|
||||
{parse ? (
|
||||
<ParseContent content={content} size={'M'} numberOfLines={5} />
|
||||
<ParseContent content={content!} size={'M'} numberOfLines={5} />
|
||||
) : (
|
||||
content
|
||||
)}
|
||||
|
@ -230,7 +230,7 @@ const Login: React.FC = () => {
|
|||
用户总数
|
||||
</Text>
|
||||
<ShimmerPlaceholder
|
||||
visible={instanceQuery.data?.stats?.user_count}
|
||||
visible={instanceQuery.data?.stats?.user_count !== undefined}
|
||||
stopAutoRun
|
||||
width={StyleConstants.Font.Size.M * 4}
|
||||
height={StyleConstants.Font.Size.M}
|
||||
|
@ -249,7 +249,7 @@ const Login: React.FC = () => {
|
|||
嘟嘟总数
|
||||
</Text>
|
||||
<ShimmerPlaceholder
|
||||
visible={instanceQuery.data?.stats?.user_count}
|
||||
visible={instanceQuery.data?.stats?.user_count !== undefined}
|
||||
stopAutoRun
|
||||
width={StyleConstants.Font.Size.M * 4}
|
||||
height={StyleConstants.Font.Size.M}
|
||||
|
@ -268,7 +268,7 @@ const Login: React.FC = () => {
|
|||
连结总数
|
||||
</Text>
|
||||
<ShimmerPlaceholder
|
||||
visible={instanceQuery.data?.stats?.user_count}
|
||||
visible={instanceQuery.data?.stats?.user_count !== undefined}
|
||||
stopAutoRun
|
||||
width={StyleConstants.Font.Size.M * 4}
|
||||
height={StyleConstants.Font.Size.M}
|
||||
|
|
|
@ -2,7 +2,7 @@ import React, { useEffect, useRef } from 'react'
|
|||
import { Animated, Dimensions, Image, StyleSheet } from 'react-native'
|
||||
|
||||
export interface Props {
|
||||
uri: Mastodon.Account['header']
|
||||
uri?: Mastodon.Account['header']
|
||||
limitHeight?: boolean
|
||||
}
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ const ComposeRoot: React.FC = () => {
|
|||
ListHeaderComponent={<ComposeRootHeader />}
|
||||
ListFooterComponent={<ComposeRootFooter textInputRef={textInputRef} />}
|
||||
ListEmptyComponent={listEmpty}
|
||||
data={data}
|
||||
data={data as Mastodon.Account[] & Mastodon.Tag[]}
|
||||
keyExtractor={listKey}
|
||||
renderItem={listItem}
|
||||
/>
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue