import * as TodosApi from '../../api' ; import { actions as categoriesActions } from '../slices/categories' ; import { AppDispatch , AppThunk } from '..' ; export const fetchCategories = ( ) : AppThunk => async ( dispatch ) => { try { const categories = await TodosApi . fetchCategories ( ) ; dispatch ( categoriesActions . setCategories ( categories ) ) ; } catch ( error ) { throw error ; } } ; export const addCategory = ( category ) : AppThunk => async ( dispatch ) => { try { const id = await TodosApi . addCategory ( category ) ; const finalCategory = { id , ... category , } ; dispatch ( categoriesActions . addCategory ( finalCategory ) ) ; } catch ( error ) { throw error ; } } ; export const removeCategory = ( id ) : AppThunk => async ( dispatch ) => { try { await TodosApi . removeCategory ( id ) ; dispatch ( categoriesActions . removeCategory ( id ) ) ; } catch ( error ) { throw error ; } } ; export const updateTodo = ( id , changes ) => async ( dispatch ) => { try { await TodosApi . updateCategory ( id , changes ) ; dispatch ( categoriesActions . updateCategory ( { id , changes } ) ) ; } catch ( error ) { throw error ; } } ;