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

Basic actions work, with some bugs

One bug: https://github.com/tootsuite/mastodon/issues/3166

Another bug, still seems `extraData` does not work that well for `FlatList`
This commit is contained in:
Zhiyuan Zheng
2020-11-01 01:57:53 +01:00
parent d2cc643b9c
commit c7a4129b82
7 changed files with 141 additions and 45 deletions

View File

@ -0,0 +1,48 @@
import { Dispatch } from '@reduxjs/toolkit'
import { Alert } from 'react-native'
import client from 'src/api/client'
import { updateStatus } from 'src/stacks/common/timelineSlice'
const action = async ({
dispatch,
id,
type,
stateKey,
statePrev
}: {
dispatch: Dispatch
id: string
type: 'favourite' | 'reblog' | 'bookmark' | 'mute' | 'pin'
stateKey: 'favourited' | 'reblogged' | 'bookmarked' | 'muted' | 'pinned'
statePrev: boolean
}): Promise<void> => {
console.log(stateKey + ' --- ' + statePrev)
const alert = {
title: 'This is a title',
message: 'This is a message'
}
// ISSUE: https://github.com/tootsuite/mastodon/issues/3166
let res = await client({
method: 'post',
instance: 'local',
endpoint: `statuses/${id}/${statePrev ? 'un' : ''}${type}`
})
res = await client({
method: 'post',
instance: 'local',
endpoint: `statuses/${id}/${statePrev ? 'un' : ''}${type}`
})
if (!res.body[stateKey] === statePrev) {
dispatch(updateStatus(res.body))
console.log('------ ' + res.body[stateKey])
} else {
Alert.alert(alert.title, alert.message, [
{ text: 'OK', onPress: () => console.log('OK Pressed') }
])
}
}
export default action