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