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

Basic attachment done

Switch from ky to axios
This commit is contained in:
Zhiyuan Zheng
2020-12-05 01:55:53 +01:00
parent 82d9cdf702
commit b274aef31a
21 changed files with 284 additions and 213 deletions

View File

@ -4,7 +4,7 @@ export const accountFetch = async (key: string, { id }: { id: string }) => {
const res = await client({
method: 'get',
instance: 'local',
endpoint: `accounts/${id}`
url: `accounts/${id}`
})
return Promise.resolve(res.body)
}

View File

@ -4,7 +4,7 @@ export const emojisFetch = async () => {
const res = await client({
method: 'get',
instance: 'local',
endpoint: 'custom_emojis'
url: 'custom_emojis'
})
return Promise.resolve(res.body)
}

View File

@ -7,8 +7,8 @@ export const instanceFetch = async (
const res = await client({
method: 'get',
instance: 'remote',
instanceUrl: instance,
endpoint: `instance`
instanceDomain: instance,
url: `instance`
})
return Promise.resolve(res.body)
}

View File

@ -4,7 +4,7 @@ export const listsFetch = async () => {
const res = await client({
method: 'get',
instance: 'local',
endpoint: 'lists'
url: 'lists'
})
return Promise.resolve(res.body)
}

View File

@ -16,8 +16,8 @@ export const searchFetch = async (
version: 'v2',
method: 'get',
instance: 'local',
endpoint: 'search',
query: { type, q: term, limit }
url: 'search',
params: { type, q: term, limit }
})
return Promise.resolve(res.body)
}

View File

@ -6,14 +6,14 @@ export const timelineFetch = async (
key: string,
{
page,
query = {},
params = {},
account,
hashtag,
list,
toot
}: {
page: string
query?: {
params?: {
[key: string]: string | number | boolean
}
account?: string
@ -31,10 +31,10 @@ export const timelineFetch = async (
if (pagination && pagination.id) {
switch (pagination.direction) {
case 'prev':
query.min_id = pagination.id
params.min_id = pagination.id
break
case 'next':
query.max_id = pagination.id
params.max_id = pagination.id
break
}
}
@ -44,18 +44,18 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: 'timelines/home',
query
url: 'timelines/home',
params
})
return Promise.resolve({ toots: res.body, pointer: null })
case 'Local':
query.local = 'true'
params.local = 'true'
res = await client({
method: 'get',
instance: 'local',
endpoint: 'timelines/public',
query
url: 'timelines/public',
params
})
return Promise.resolve({ toots: res.body, pointer: null })
@ -63,8 +63,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: 'timelines/public',
query
url: 'timelines/public',
params
})
return Promise.resolve({ toots: res.body, pointer: null })
@ -72,8 +72,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'remote',
endpoint: 'timelines/public',
query
url: 'timelines/public',
params
})
return Promise.resolve({ toots: res.body, pointer: null })
@ -81,8 +81,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: 'notifications',
query
url: 'notifications',
params
})
return Promise.resolve({ toots: res.body, pointer: null })
@ -90,8 +90,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: `accounts/${account}/statuses`,
query: {
url: `accounts/${account}/statuses`,
params: {
pinned: 'true'
}
})
@ -99,8 +99,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: `accounts/${account}/statuses`,
query: {
url: `accounts/${account}/statuses`,
params: {
exclude_replies: 'true'
}
})
@ -111,8 +111,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: `accounts/${account}/statuses`,
query
url: `accounts/${account}/statuses`,
params
})
return Promise.resolve({ toots: res.body, pointer: null })
@ -120,8 +120,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: `accounts/${account}/statuses`,
query: {
url: `accounts/${account}/statuses`,
params: {
only_media: 'true'
}
})
@ -131,8 +131,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: `timelines/tag/${hashtag}`,
query
url: `timelines/tag/${hashtag}`,
params
})
return Promise.resolve({ toots: res.body, pointer: null })
@ -140,8 +140,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: `conversations`,
query
url: `conversations`,
params
})
return Promise.resolve({ toots: res.body, pointer: null })
@ -149,8 +149,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: `bookmarks`,
query
url: `bookmarks`,
params
})
return Promise.resolve({ toots: res.body, pointer: null })
@ -158,8 +158,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: `favourites`,
query
url: `favourites`,
params
})
return Promise.resolve({ toots: res.body, pointer: null })
@ -167,8 +167,8 @@ export const timelineFetch = async (
res = await client({
method: 'get',
instance: 'local',
endpoint: `timelines/list/${list}`,
query
url: `timelines/list/${list}`,
params
})
return Promise.resolve({ toots: res.body, pointer: null })
@ -176,12 +176,12 @@ export const timelineFetch = async (
const current = await client({
method: 'get',
instance: 'local',
endpoint: `statuses/${toot}`
url: `statuses/${toot}`
})
const context = await client({
method: 'get',
instance: 'local',
endpoint: `statuses/${toot}/context`
url: `statuses/${toot}/context`
})
return Promise.resolve({
toots: [

View File

@ -50,16 +50,16 @@ export const updateLocal = createAsyncThunk(
} = await client({
method: 'get',
instance: 'remote',
instanceUrl: url,
endpoint: `accounts/verify_credentials`,
instanceDomain: url,
url: `accounts/verify_credentials`,
headers: { Authorization: `Bearer ${token}` }
})
const { body: preferences } = await client({
method: 'get',
instance: 'remote',
instanceUrl: url,
endpoint: `preferences`,
instanceDomain: url,
url: `preferences`,
headers: { Authorization: `Bearer ${token}` }
})
@ -91,14 +91,11 @@ const instancesSlice = createSlice({
})
export const getLocalUrl = (state: RootState) => state.instances.local.url
export const getLocalToken = (state: RootState) => state.instances.local.token
export const getRemoteUrl = (state: RootState) => state.instances.remote.url
export const getLocalAccountId = (state: RootState) =>
state.instances.local.account.id
export const getLocalAccountPreferences = (state: RootState) =>
state.instances.local.account.preferences
// export const {
// updateLocalInstance,
// updateLocalAccount
// } = instancesSlice.actions
export default instancesSlice.reducer