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:
48
src/components/Toot/action.ts
Normal file
48
src/components/Toot/action.ts
Normal 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
|
Reference in New Issue
Block a user