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

Basic toot in timeline working

This commit is contained in:
Zhiyuan Zheng
2020-10-26 00:27:53 +01:00
parent 996cf0c1e7
commit eefa7e01bd
21 changed files with 483 additions and 284 deletions

View File

@ -0,0 +1,48 @@
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
import { client } from 'src/api/client'
export const fetch = createAsyncThunk(
'account/fetch',
async ({ id }, { getState }) => {
const instanceLocal = getState().instanceInfo.local + '/api/v1/'
return await client.get(`${instanceLocal}accounts/${id}`)
}
)
const accountInitState = {
account: {},
status: 'idle'
}
export const getState = state => state.account
export const accountSlice = createSlice({
name: 'account',
initialState: {
account: {},
status: 'idle'
},
reducers: {
reset: state => {
state.account = accountInitState
}
},
extraReducers: {
[fetch.pending]: state => {
state.status = 'loading'
},
[fetch.fulfilled]: (state, action) => {
state.status = 'succeeded'
state.account = action.payload
},
[fetch.rejected]: (state, action) => {
state.status = 'failed'
console.error(action.error.message)
}
}
})
export const { reset } = accountSlice.actions
export default accountSlice.reducer