mirror of
https://github.com/ershisan99/it-incubator-todolist-ts-17-live-2024-08-17.git
synced 2025-12-16 12:33:29 +00:00
chore: final details
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import {
|
||||
appSlice,
|
||||
InitialState,
|
||||
AppInitialState,
|
||||
setAppError,
|
||||
setAppStatus,
|
||||
} from './app-reducer'
|
||||
|
||||
let startState: InitialState
|
||||
let startState: AppInitialState
|
||||
|
||||
const appReducer = appSlice.reducer
|
||||
|
||||
|
||||
@@ -5,16 +5,22 @@ import { AppThunk } from 'app/store'
|
||||
|
||||
export type RequestStatus = 'idle' | 'loading' | 'succeeded' | 'failed'
|
||||
|
||||
export type InitialState = {
|
||||
// происходит ли сейчас взаимодействие с сервером
|
||||
export type AppInitialState = {
|
||||
/**
|
||||
* происходит ли сейчас взаимодействие с сервером
|
||||
*/
|
||||
status: RequestStatus
|
||||
// если ошибка какая-то глобальная произойдёт - мы запишем текст ошибки сюда
|
||||
/**
|
||||
* если ошибка какая-то глобальная произойдёт - мы запишем текст ошибки сюда
|
||||
*/
|
||||
error: string | null
|
||||
// true когда приложение проинициализировалось (проверили юзера, настройки получили и т.д.)
|
||||
/**
|
||||
* true когда приложение проинициализировалось (проверили юзера, настройки получили и т.д.)
|
||||
*/
|
||||
isInitialized: boolean
|
||||
}
|
||||
|
||||
const initialState: InitialState = {
|
||||
const initialState: AppInitialState = {
|
||||
status: 'idle',
|
||||
error: null,
|
||||
isInitialized: false,
|
||||
@@ -23,17 +29,23 @@ const initialState: InitialState = {
|
||||
export const appSlice = createSlice({
|
||||
name: 'app',
|
||||
initialState,
|
||||
reducers: {
|
||||
setAppError(state, action: PayloadAction<string | null>) {
|
||||
reducers: (builder) => ({
|
||||
// setAppError(state, action: PayloadAction<AppInitialState['error']>) {
|
||||
// state.error = action.payload
|
||||
// },
|
||||
setAppError: builder.reducer<AppInitialState['error']>((state, action) => {
|
||||
state.error = action.payload
|
||||
},
|
||||
}),
|
||||
setAppStatus(state, action: PayloadAction<RequestStatus>) {
|
||||
state.status = action.payload
|
||||
},
|
||||
setAppInitialized(state, action: PayloadAction<boolean>) {
|
||||
setAppInitialized(
|
||||
state,
|
||||
action: PayloadAction<AppInitialState['isInitialized']>
|
||||
) {
|
||||
state.isInitialized = action.payload
|
||||
},
|
||||
},
|
||||
}),
|
||||
selectors: {
|
||||
selectAppError: (state) => state.error,
|
||||
selectAppStatus: (state) => state.status,
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
import { tasksSlice } from 'features/TodolistsList/tasks-reducer'
|
||||
import { todolistsSlice } from 'features/TodolistsList/todolists-reducer'
|
||||
import { combineReducers } from 'redux'
|
||||
import { ThunkAction, ThunkDispatch } from 'redux-thunk'
|
||||
import { appSlice } from './app-reducer'
|
||||
import { authSlice } from 'features/Login/auth-reducer'
|
||||
import { configureStore, UnknownAction } from '@reduxjs/toolkit'
|
||||
import { combineSlices, configureStore, UnknownAction } from '@reduxjs/toolkit'
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
[appSlice.reducerPath]: appSlice.reducer,
|
||||
[tasksSlice.reducerPath]: tasksSlice.reducer,
|
||||
[todolistsSlice.reducerPath]: todolistsSlice.reducer,
|
||||
[authSlice.reducerPath]: authSlice.reducer,
|
||||
})
|
||||
const rootReducer = combineSlices(
|
||||
appSlice,
|
||||
authSlice,
|
||||
todolistsSlice,
|
||||
tasksSlice
|
||||
)
|
||||
|
||||
// ❗старая запись, с новыми версиями не работает
|
||||
// const store = createStore(rootReducer, applyMiddleware(thunkMiddleware));
|
||||
export const store = configureStore({ reducer: rootReducer })
|
||||
export const store = configureStore({
|
||||
reducer: rootReducer,
|
||||
})
|
||||
|
||||
export type AppRootState = ReturnType<typeof rootReducer>
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ export const AddItemForm = React.memo(function ({
|
||||
if (error !== null) {
|
||||
setError(null)
|
||||
}
|
||||
if (e.charCode === 13) {
|
||||
if (e.key === 'Enter') {
|
||||
addItemHandler()
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ export const AddItemForm = React.memo(function ({
|
||||
error={!!error}
|
||||
value={title}
|
||||
onChange={onChangeHandler}
|
||||
onKeyPress={onKeyPressHandler}
|
||||
onKeyDown={onKeyPressHandler}
|
||||
label='Title'
|
||||
helperText={error}
|
||||
/>
|
||||
|
||||
@@ -27,9 +27,7 @@ export type UpdateDomainTaskModel = {
|
||||
deadline?: string
|
||||
}
|
||||
|
||||
export type TasksState = {
|
||||
[key: string]: Array<TaskEntity>
|
||||
}
|
||||
export type TasksState = Record<string, Array<TaskEntity>>
|
||||
|
||||
const initialState: TasksState = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user