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:
48
src/stacks/common/accountSlice.js
Normal file
48
src/stacks/common/accountSlice.js
Normal 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
|
Reference in New Issue
Block a user