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

Partial fix #495

Add list
Edit list info
This commit is contained in:
xmflsct
2022-11-30 22:42:42 +01:00
parent de7498b218
commit bb3ddd2779
29 changed files with 506 additions and 224 deletions

View File

@ -63,17 +63,18 @@ export type RootStackParamList = {
share?: { text?: string; media?: { uri: string; mime: string }[] }
}
}
export type RootStackScreenProps<T extends keyof RootStackParamList> =
NativeStackScreenProps<RootStackParamList, T>
export type RootStackScreenProps<T extends keyof RootStackParamList> = NativeStackScreenProps<
RootStackParamList,
T
>
export type ScreenComposeStackParamList = {
'Screen-Compose-Root': undefined
'Screen-Compose-EditAttachment': { index: number }
'Screen-Compose-DraftsList': { timestamp: number }
}
export type ScreenComposeStackScreenProps<
T extends keyof ScreenComposeStackParamList
> = NativeStackScreenProps<ScreenComposeStackParamList, T>
export type ScreenComposeStackScreenProps<T extends keyof ScreenComposeStackParamList> =
NativeStackScreenProps<ScreenComposeStackParamList, T>
export type ScreenTabsStackParamList = {
'Tab-Local': NavigatorScreenParams<TabLocalStackParamList>
@ -82,8 +83,10 @@ export type ScreenTabsStackParamList = {
'Tab-Notifications': NavigatorScreenParams<TabNotificationsStackParamList>
'Tab-Me': NavigatorScreenParams<TabMeStackParamList>
}
export type ScreenTabsScreenProps<T extends keyof ScreenTabsStackParamList> =
BottomTabScreenProps<ScreenTabsStackParamList, T>
export type ScreenTabsScreenProps<T extends keyof ScreenTabsStackParamList> = BottomTabScreenProps<
ScreenTabsStackParamList,
T
>
export type TabSharedStackParamList = {
'Tab-Shared-Account': {
@ -135,11 +138,17 @@ export type TabMeStackParamList = {
'Tab-Me-Bookmarks': undefined
'Tab-Me-Conversations': undefined
'Tab-Me-Favourites': undefined
'Tab-Me-List': Mastodon.List
'Tab-Me-List-Edit':
| {
type: 'add'
}
| {
type: 'edit'
payload: Mastodon.List
key: string // To update title after successful mutation
}
'Tab-Me-Lists': undefined
'Tab-Me-Lists-List': {
list: Mastodon.List['id']
title: Mastodon.List['title']
}
'Tab-Me-Profile': undefined
'Tab-Me-Push': undefined
'Tab-Me-Settings': undefined
@ -147,11 +156,12 @@ export type TabMeStackParamList = {
'Tab-Me-Settings-Language': undefined
'Tab-Me-Switch': undefined
} & TabSharedStackParamList
export type TabMeStackScreenProps<T extends keyof TabMeStackParamList> =
NativeStackScreenProps<TabMeStackParamList, T>
export type TabMeStackNavigationProp<
RouteName extends keyof TabMeStackParamList
> = StackNavigationProp<TabMeStackParamList, RouteName>
export type TabMeStackScreenProps<T extends keyof TabMeStackParamList> = NativeStackScreenProps<
TabMeStackParamList,
T
>
export type TabMeStackNavigationProp<RouteName extends keyof TabMeStackParamList> =
StackNavigationProp<TabMeStackParamList, RouteName>
export type TabMeProfileStackParamList = {
'Tab-Me-Profile-Root': undefined
@ -165,6 +175,5 @@ export type TabMeProfileStackParamList = {
fields?: Mastodon.Source['fields']
}
}
export type TabMeProfileStackScreenProps<
T extends keyof TabMeProfileStackParamList
> = NativeStackScreenProps<TabMeProfileStackParamList, T>
export type TabMeProfileStackScreenProps<T extends keyof TabMeProfileStackParamList> =
NativeStackScreenProps<TabMeProfileStackParamList, T>

View File

@ -1,8 +1,8 @@
import apiInstance from '@api/instance'
import { AxiosError } from 'axios'
import { useQuery, UseQueryOptions } from 'react-query'
import { useMutation, UseMutationOptions, useQuery, UseQueryOptions } from 'react-query'
export type QueryKey = ['Lists']
export type QueryKeyLists = ['Lists']
const queryFunction = async () => {
const res = await apiInstance<Mastodon.List[]>({
@ -12,13 +12,49 @@ const queryFunction = async () => {
return res.body
}
const useListsQuery = ({
options
}: {
options?: UseQueryOptions<Mastodon.List[], AxiosError>
}) => {
const queryKey: QueryKey = ['Lists']
const useListsQuery = ({ options }: { options?: UseQueryOptions<Mastodon.List[], AxiosError> }) => {
const queryKey: QueryKeyLists = ['Lists']
return useQuery(queryKey, queryFunction, options)
}
export { useListsQuery }
type MutationVarsLists =
| {
type: 'add'
payload: Omit<Mastodon.List, 'id'>
}
| {
type: 'edit'
payload: Mastodon.List
}
const mutationFunction = async (params: MutationVarsLists) => {
const body = new FormData()
switch (params.type) {
case 'add':
body.append('title', params.payload.title)
body.append('replies_policy', params.payload.replies_policy)
return apiInstance<Mastodon.List>({
method: 'post',
url: 'lists',
body
}).then(res => res.body)
case 'edit':
body.append('title', params.payload.title)
body.append('replies_policy', params.payload.replies_policy)
return apiInstance<Mastodon.List>({
method: 'put',
url: `lists/${params.payload.id}`,
body
}).then(res => res.body)
}
}
const useListsMutation = (
options: UseMutationOptions<Mastodon.List, AxiosError, MutationVarsLists>
) => {
return useMutation(mutationFunction, options)
}
export { useListsQuery, useListsMutation }