diff --git a/src/pages/login-screen/login-screen.tsx b/src/pages/login-screen/login-screen.tsx
index fcaa37b..514cde9 100644
--- a/src/pages/login-screen/login-screen.tsx
+++ b/src/pages/login-screen/login-screen.tsx
@@ -3,7 +3,8 @@ import { AppRoute, cities } from '../../const';
import { loginAction } from '../../store/api-actions';
import { useAppDispatch } from '../../hooks';
import { Link } from 'react-router-dom';
-import { changeCity, redirectToRoute } from '../../store/action';
+import { redirectToRoute } from '../../store/action';
+import { changeCity } from '../../store/common-data/common-data';
function getRandomCity() {
const cityKeys = Object.keys(cities) as (keyof typeof cities)[];
diff --git a/src/pages/main-screen/main-screen.tsx b/src/pages/main-screen/main-screen.tsx
index 0287e86..f405972 100644
--- a/src/pages/main-screen/main-screen.tsx
+++ b/src/pages/main-screen/main-screen.tsx
@@ -5,10 +5,12 @@ import { useAppSelector } from '../../hooks';
import CityList from '../../components/city-list/city-list';
import { Header } from '../../components/header/header';
import { CardsSortingOptions } from '../../components/cards-sorting-options/cards-sorting-options';
+import { getOffers } from '../../store/offers-data/selectors';
+import { getCity } from '../../store/common-data/selectors';
function MainScreen(): JSX.Element {
- const city = useAppSelector((state) => state.city);
- const offers = useAppSelector((state) => state.offers);
+ const city = useAppSelector(getCity);
+ const offers = useAppSelector(getOffers);
const chosenOffers = offers.filter((offer) => offer.city.name === city);
const points = chosenOffers.map((offer) => offer.location);
const chosenCity = chosenOffers[0].city;
diff --git a/src/pages/offer-screen/offer-screen.tsx b/src/pages/offer-screen/offer-screen.tsx
index f907b72..1775317 100644
--- a/src/pages/offer-screen/offer-screen.tsx
+++ b/src/pages/offer-screen/offer-screen.tsx
@@ -8,15 +8,17 @@ import LoadingScreen from '../loading-screen/loading-screen';
import { useParams } from 'react-router-dom';
import { useEffect } from 'react';
import { Header } from '../../components/header/header';
+import { getChosenOffer, getIsChosenOfferDataLoading, getNearbyOffers, getReviews } from '../../store/offer-data/selectors';
+import { getOffers } from '../../store/offers-data/selectors';
const MAXIMUM_NEARBY_PREVIEW = 3;
function OfferScreen(): JSX.Element {
const dispatch = useAppDispatch();
- const offer = useAppSelector((state) => state.chosenOffer);
- const reviews = useAppSelector((state) => state.reviews);
- const nearbyOffers = useAppSelector((state) => state.nearbyOffers);
- const city = useAppSelector((state) => state.offers[0].city);
+ const offer = useAppSelector(getChosenOffer);
+ const reviews = useAppSelector(getReviews);
+ const nearbyOffers = useAppSelector(getNearbyOffers);
+ const city = useAppSelector(getOffers)[0].city;
const displayedNearby = (nearbyOffers).slice(
0,
@@ -30,7 +32,7 @@ function OfferScreen(): JSX.Element {
dispatch(fetchNearbyAction(id));
}, [dispatch, id]);
- const isChosenOfferDataLoading = useAppSelector((state) => state.isChosenOfferDataLoading);
+ const isChosenOfferDataLoading = useAppSelector(getIsChosenOfferDataLoading);
if (isChosenOfferDataLoading) {
return (
diff --git a/src/services/process-error-handle.ts b/src/services/process-error-handle.ts
index db11914..e2839a4 100644
--- a/src/services/process-error-handle.ts
+++ b/src/services/process-error-handle.ts
@@ -1,6 +1,6 @@
import {store} from '../store';
-import {setError} from '../store/action';
-import {clearErrorAction} from '../store/api-actions';
+import { clearErrorAction } from '../store/api-actions';
+import { setError } from '../store/common-data/common-data';
export const processErrorHandle = (message: string): void => {
store.dispatch(setError(message));
diff --git a/src/store/action.ts b/src/store/action.ts
index 3a00bcf..515c3b6 100644
--- a/src/store/action.ts
+++ b/src/store/action.ts
@@ -1,58 +1,6 @@
import { createAction } from '@reduxjs/toolkit';
-import { Point } from '../types/location';
-import { ExtendedOffer, Offer } from '../types/offer';
-import { AppRoute, AuthorizationStatus } from '../const';
-import { UserData } from '../types/user-data';
-import { Review } from '../types/review';
-
-export const changeCity = createAction('CITY_CHANGE', (value: string) => ({
- payload: value
-}));
-
-export const changeSortOptions = createAction('CHANGE_SORT_OPTIONS', (value: string) => ({
- payload: value
-}));
-
-export const changeHighlightedMarker = createAction('CHANGE_HIGHLIGHTED_MARKER', (value: Point | undefined) => ({
- payload: value
-}));
-
-export const loadOffers = createAction('LOAD_OFFERS', (value: Offer[]) => ({
- payload: value
-}));
-
-export const changeChosenOffer = createAction('CHANGE_CHOSEN_OFFER', (value: ExtendedOffer) => ({
- payload: value
-}));
-
-export const setOffersDataLoadingStatus = createAction('SET_OFFERS_DATA_LOADING_STATUS', (value: boolean) => ({
- payload: value
-}));
-
-export const setError = createAction('SET_ERROR', (value: string | null) => ({
- payload: value
-}));
-
-export const requireAuthorization = createAction('REQUIRE_AUTHORIZATION', (value: AuthorizationStatus) => ({
- payload: value
-}));
-
-export const loadUserData = createAction('LOAD_USER_DATA', (value: UserData) => ({
- payload: value
-}));
+import { AppRoute} from '../const';
export const redirectToRoute = createAction('REDIRECT_TO_ROUTE', (value: AppRoute) => ({
payload: value
-}));
-
-export const loadReviews = createAction('CHANGE_REVIEWS', (value: Review[]) => ({
- payload: value
-}));
-
-export const changeNearbyOffers = createAction('CHANGE_NEARBY_OFFERS', (value: Offer[]) => ({
- payload: value
-}));
-
-export const setChosenOfferDataLoadingStatus = createAction('SET_CHOSEN_OFFER_DATA_LOADING_STATUS', (value: boolean) => ({
- payload: value
-}));
+}));
\ No newline at end of file
diff --git a/src/store/api-actions.ts b/src/store/api-actions.ts
index a0accc6..40bca66 100644
--- a/src/store/api-actions.ts
+++ b/src/store/api-actions.ts
@@ -1,57 +1,50 @@
import { createAsyncThunk } from '@reduxjs/toolkit';
import { AppDispatch, State } from '../types/state';
import { AxiosInstance } from 'axios';
-import { changeChosenOffer, changeNearbyOffers, loadOffers, loadReviews, loadUserData, redirectToRoute, requireAuthorization, setChosenOfferDataLoadingStatus, setError, setOffersDataLoadingStatus } from './action';
+import { redirectToRoute } from './action';
import { ExtendedOffer, Offer } from '../types/offer';
-import { APIRoute, AppRoute, AuthorizationStatus, TIMEOUT_SHOW_ERROR } from '../const';
-import { store } from './';
+import { APIRoute, AppRoute, TIMEOUT_SHOW_ERROR } from '../const';
import { AuthData } from '../types/auth-data';
import { UserData } from '../types/user-data';
import { dropToken, saveToken } from '../services/token';
import { Review } from '../types/review';
+import { setError } from './common-data/common-data';
+
export const clearErrorAction = createAsyncThunk(
'CLEAR_ERROR_ACTION',
- () => {
- setTimeout(
- () => store.dispatch(setError(null)),
- TIMEOUT_SHOW_ERROR,
- );
- },
+ async (_, { dispatch }) => {
+ setTimeout(() => {
+ dispatch(setError(null));
+ }, TIMEOUT_SHOW_ERROR);
+ }
);
-export const fetchOffersAction = createAsyncThunk
(
'FETCH_OFFERS_ACTION',
- async (_arg, { dispatch, extra: api }) => {
- dispatch(setOffersDataLoadingStatus(true));
+ async (_arg, { extra: api }) => {
const { data } = await api.get(APIRoute.Offers);
- dispatch(loadOffers(data));
- dispatch(setOffersDataLoadingStatus(false));
+ return data
},
);
-export const checkAuthAction = createAsyncThunk(
'CHECK_AUTH_ACTION',
- async (_arg, { dispatch, extra: api }) => {
- try {
- const { data } = await api.get(APIRoute.Login);
- dispatch(requireAuthorization(AuthorizationStatus.Auth));
- dispatch(loadUserData(data));
- } catch {
- dispatch(requireAuthorization(AuthorizationStatus.NoAuth));
- }
- },
+ async (_arg, { extra: api }) => {
+ const { data } = await api.get(APIRoute.Login);
+ return data
+ }
);
-export const loginAction = createAsyncThunk {
const { data } = await api.post(APIRoute.Login, { email, password });
saveToken(data.token);
- dispatch(requireAuthorization(AuthorizationStatus.Auth));
- dispatch(loadUserData(data));
dispatch(redirectToRoute(AppRoute.Main));
+ return data;
},
);
@@ -72,72 +64,63 @@ export const logoutAction = createAsyncThunk(
'LOGOUT_ACTION',
- async (_arg, { dispatch, extra: api }) => {
- dispatch(setOffersDataLoadingStatus(true));
+ async (_arg, { extra: api }) => {
await api.delete(APIRoute.Logout);
dropToken();
- dispatch(requireAuthorization(AuthorizationStatus.NoAuth));
- dispatch(setOffersDataLoadingStatus(false));
},
);
-export const fetchOfferAction = createAsyncThunk(
'FETCH_OFFER_ACTION',
- async (id, { dispatch, extra: api }) => {
- dispatch(setChosenOfferDataLoadingStatus(true));
+ async (id, { extra: api }) => {
const { data } = await api.get(`${APIRoute.Offers}/${id}`);
- dispatch(changeChosenOffer(data));
- dispatch(setChosenOfferDataLoadingStatus(false));
+ return data
},
);
-export const fetchReviewsAction = createAsyncThunk(
'FETCH_REVIEWS_ACTION',
- async (id, { dispatch, extra: api }) => {
- dispatch(setChosenOfferDataLoadingStatus(true));
+ async (id, { extra: api }) => {
const { data } = await api.get(`${APIRoute.Comments}/${id}`);
- dispatch(loadReviews(data));
- dispatch(setChosenOfferDataLoadingStatus(false));
+ return data
},
);
-export const fetchNearbyAction = createAsyncThunk(
'FETCH_NEARBY_ACTION',
- async (id, { dispatch, extra: api }) => {
- dispatch(setChosenOfferDataLoadingStatus(true));
+ async (id, { extra: api }) => {
const { data } = await api.get(`${APIRoute.Offers}/${id}${APIRoute.Nearby}`);
- dispatch(changeNearbyOffers(data));
- dispatch(setChosenOfferDataLoadingStatus(false));
+ return data
},
);
-export const postReviewAction = createAsyncThunk(
- 'POST_REVIEW_ACTION',
- async ({ id, comment, rating }, { dispatch, extra: api }) => {
- await api.post(`${APIRoute.Comments}/${id}`, { comment, rating });
- const { data: reviews } = await api.get(`${APIRoute.Comments}/${id}`);
- dispatch(loadReviews(reviews));
- },
-);
+ {
+ dispatch: AppDispatch;
+ state: State;
+ extra: AxiosInstance;
+ }>(
+ 'POST_REVIEW_ACTION',
+ async ({ id, comment, rating }, { extra: api }) => {
+ await api.post(`${APIRoute.Comments}/${id}`, { comment, rating });
+ const { data } = await api.get(`${APIRoute.Comments}/${id}`);
+ return data
+ },
+ );
diff --git a/src/store/common-data/common-data.ts b/src/store/common-data/common-data.ts
new file mode 100644
index 0000000..8c8abfd
--- /dev/null
+++ b/src/store/common-data/common-data.ts
@@ -0,0 +1,33 @@
+import { PayloadAction, createSlice } from "@reduxjs/toolkit";
+import { NameSpace, cities } from "../../const";
+import { filters } from "../../utils";
+import { CommonData } from "../../types/state";
+import { Point } from "../../types/location";
+
+const initialState: CommonData = {
+ sortType: filters.POPULAR,
+ city: cities.Paris,
+ highlightedMarker: undefined,
+ error: null,
+ };
+
+ export const commmonData = createSlice({
+ name: NameSpace.Common,
+ initialState,
+ reducers: {
+ changeSortType: (state, action: PayloadAction) => {
+ state.sortType = action.payload;
+ },
+ changeCity: (state, action: PayloadAction) => {
+ state.city = action.payload;
+ },
+ changeHighlightedMarker: (state, action: PayloadAction) => {
+ state.highlightedMarker = action.payload;
+ },
+ setError: (state, action: PayloadAction) => {
+ state.error = action.payload;
+ },
+ },
+ });
+
+ export const { changeSortType, changeCity, changeHighlightedMarker, setError } = commmonData.actions;
\ No newline at end of file
diff --git a/src/store/common-data/selectors.ts b/src/store/common-data/selectors.ts
new file mode 100644
index 0000000..77bdeee
--- /dev/null
+++ b/src/store/common-data/selectors.ts
@@ -0,0 +1,8 @@
+import { NameSpace } from "../../const";
+import { Point } from "../../types/location";
+import { State } from "../../types/state";
+
+export const getSortType = (state: State): string => state[NameSpace.Common].sortType;
+export const getCity = (state: State): string => state[NameSpace.Common].city;
+export const getHighlightedMarker = (state: State): Point | undefined => state[NameSpace.Common].highlightedMarker;
+export const getError = (state: State): string | null => state[NameSpace.Common].error;
\ No newline at end of file
diff --git a/src/store/index.ts b/src/store/index.ts
index b6f6ecd..23cbdc4 100644
--- a/src/store/index.ts
+++ b/src/store/index.ts
@@ -1,12 +1,12 @@
import { configureStore } from '@reduxjs/toolkit';
-import { reducer } from './reducer';
import { createAPI } from '../services/api';
import { redirect } from './middlewares/redirect';
+import { rootReducer } from './root-reducer';
export const api = createAPI();
export const store = configureStore({
- reducer,
+ reducer: rootReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
thunk: {
diff --git a/src/store/middlewares/redirect.ts b/src/store/middlewares/redirect.ts
index 955a510..aef23f7 100644
--- a/src/store/middlewares/redirect.ts
+++ b/src/store/middlewares/redirect.ts
@@ -1,9 +1,9 @@
import {PayloadAction} from '@reduxjs/toolkit';
import browserHistory from '../../browser-history';
import {Middleware} from 'redux';
-import {reducer} from '../reducer';
+import { rootReducer } from '../root-reducer';
-type Reducer = ReturnType;
+type Reducer = ReturnType;
export const redirect: Middleware =
() =>
diff --git a/src/store/offer-data/offer-data.ts b/src/store/offer-data/offer-data.ts
new file mode 100644
index 0000000..f6c92a8
--- /dev/null
+++ b/src/store/offer-data/offer-data.ts
@@ -0,0 +1,46 @@
+import { createSlice } from "@reduxjs/toolkit";
+import { NameSpace } from "../../const";
+import { fetchNearbyAction, fetchOfferAction, fetchReviewsAction, postReviewAction } from "../api-actions";
+import { OfferData } from "../../types/state";
+
+
+const initialState: OfferData = {
+ chosenOffer: undefined,
+ reviews: [],
+ nearbyOffers: [],
+ isChosenOfferDataLoading: false
+ };
+
+ export const offerData = createSlice({
+ name: NameSpace.Offer,
+ initialState,
+ reducers: {},
+ extraReducers(builder) {
+ builder
+ .addCase(fetchOfferAction.fulfilled, (state, action) => {
+ state.isChosenOfferDataLoading = false;
+ state.chosenOffer = action.payload;
+ })
+ .addCase(fetchOfferAction.pending, (state) => {
+ state.isChosenOfferDataLoading = true;
+ })
+ .addCase(fetchReviewsAction.fulfilled, (state, action) => {
+ state.isChosenOfferDataLoading = false;
+ state.reviews = action.payload;
+ })
+ .addCase(fetchReviewsAction.pending, (state) => {
+ state.isChosenOfferDataLoading = false;
+ })
+ .addCase(fetchNearbyAction.fulfilled, (state, action) => {
+ state.isChosenOfferDataLoading = false;
+ state.nearbyOffers = action.payload;
+ })
+ .addCase(fetchNearbyAction.pending, (state) => {
+ state.isChosenOfferDataLoading = true;
+ })
+ .addCase(postReviewAction.fulfilled, (state, action) => {
+ state.reviews = action.payload;
+ })
+ }
+ }
+ );
\ No newline at end of file
diff --git a/src/store/offer-data/selectors.ts b/src/store/offer-data/selectors.ts
new file mode 100644
index 0000000..7a05fc7
--- /dev/null
+++ b/src/store/offer-data/selectors.ts
@@ -0,0 +1,9 @@
+import { NameSpace } from "../../const";
+import { ExtendedOffer, Offer } from "../../types/offer";
+import { Review } from "../../types/review";
+import { State } from "../../types/state";
+
+export const getChosenOffer = (state: State): ExtendedOffer | undefined => state[NameSpace.Offer].chosenOffer;
+export const getReviews = (state: State): Review[] => state[NameSpace.Offer].reviews;
+export const getNearbyOffers = (state: State): Offer[] => state[NameSpace.Offer].nearbyOffers;
+export const getIsChosenOfferDataLoading = (state: State): boolean => state[NameSpace.Offer].isChosenOfferDataLoading;
\ No newline at end of file
diff --git a/src/store/offers-data/offers-data.ts b/src/store/offers-data/offers-data.ts
new file mode 100644
index 0000000..159f613
--- /dev/null
+++ b/src/store/offers-data/offers-data.ts
@@ -0,0 +1,31 @@
+import { createSlice } from '@reduxjs/toolkit';
+import { NameSpace } from '../../const';
+import { OffersData } from '../../types/state';
+import { fetchOffersAction, logoutAction } from '../api-actions';
+
+const initialState: OffersData = {
+ offers: [],
+ isOffersDataLoading: false,
+};
+
+export const offersData = createSlice({
+ name: NameSpace.Offers,
+ initialState,
+ reducers: {},
+ extraReducers: (builder) => {
+ builder
+ .addCase(fetchOffersAction.fulfilled, (state, action) => {
+ state.offers = action.payload;
+ state.isOffersDataLoading = false;
+ })
+ .addCase(fetchOffersAction.pending, (state) => {
+ state.isOffersDataLoading = true;
+ })
+ .addCase(logoutAction.fulfilled, (state) => {
+ state.isOffersDataLoading = false;
+ })
+ .addCase(logoutAction.pending, (state) => {
+ state.isOffersDataLoading = true;
+ })
+ },
+});
diff --git a/src/store/offers-data/selectors.ts b/src/store/offers-data/selectors.ts
new file mode 100644
index 0000000..c33fc1c
--- /dev/null
+++ b/src/store/offers-data/selectors.ts
@@ -0,0 +1,6 @@
+import { NameSpace } from "../../const";
+import { Offer } from "../../types/offer";
+import { State } from "../../types/state";
+
+export const getOffers = (state: State): Offer[] => state[NameSpace.Offers].offers;
+export const getIsOffersDataLoading = (state: State): boolean => state[NameSpace.Offers].isOffersDataLoading;
\ No newline at end of file
diff --git a/src/store/reducer.ts b/src/store/reducer.ts
deleted file mode 100644
index 2e7dfc2..0000000
--- a/src/store/reducer.ts
+++ /dev/null
@@ -1,81 +0,0 @@
-import { createReducer } from '@reduxjs/toolkit';
-import { ExtendedOffer, Offer } from '../types/offer';
-import { changeChosenOffer, changeCity, changeHighlightedMarker, changeNearbyOffers, changeSortOptions, loadOffers, loadReviews, loadUserData, requireAuthorization, setChosenOfferDataLoadingStatus, setError, setOffersDataLoadingStatus } from './action';
-import { filters } from '../utils';
-import { Point } from '../types/location';
-import { AuthorizationStatus, cities } from '../const';
-import { UserData } from '../types/user-data';
-import { Review } from '../types/review';
-
-
-type StateType = {
- city: string;
- offers: Offer[];
- sortType: string;
- highlightedMarker?: Point;
- chosenOffer?: ExtendedOffer;
- isOffersDataLoading: boolean;
- error: string | null;
- authorizationStatus: AuthorizationStatus;
- userData?: UserData;
- reviews: Review[];
- nearbyOffers: Offer[];
- isChosenOfferDataLoading: boolean;
- }
-
-const initialState: StateType = {
- city: cities.Paris,
- offers: [],
- sortType: filters.POPULAR,
- highlightedMarker: undefined,
- chosenOffer: undefined,
- isOffersDataLoading: false,
- error: null,
- authorizationStatus: AuthorizationStatus.Unknown,
- userData: undefined,
- reviews: [],
- nearbyOffers: [],
- isChosenOfferDataLoading: false
-};
-
-const reducer = createReducer(initialState, (builder) => {
- builder
- .addCase(changeCity, (state, action) => {
- state.city = action.payload;
- })
- .addCase(changeSortOptions, (state, action) => {
- state.sortType = action.payload;
- })
- .addCase(changeHighlightedMarker, (state, action) => {
- state.highlightedMarker = action.payload;
- })
- .addCase(loadOffers, (state, action) => {
- state.offers = action.payload;
- })
- .addCase(changeChosenOffer, (state, action) => {
- state.chosenOffer = action.payload;
- })
- .addCase(setOffersDataLoadingStatus, (state, action) => {
- state.isOffersDataLoading = action.payload;
- })
- .addCase(setError, (state, action) => {
- state.error = action.payload;
- })
- .addCase(requireAuthorization, (state, action) => {
- state.authorizationStatus = action.payload;
- })
- .addCase(loadUserData, (state, action) => {
- state.userData = action.payload;
- })
- .addCase(loadReviews, (state, action) => {
- state.reviews = action.payload;
- })
- .addCase(changeNearbyOffers, (state, action) => {
- state.nearbyOffers = action.payload;
- })
- .addCase(setChosenOfferDataLoadingStatus, (state, action) => {
- state.isChosenOfferDataLoading = action.payload;
- });
-});
-
-export {reducer};
diff --git a/src/store/root-reducer.ts b/src/store/root-reducer.ts
new file mode 100644
index 0000000..c57d8fa
--- /dev/null
+++ b/src/store/root-reducer.ts
@@ -0,0 +1,13 @@
+import { combineReducers } from "@reduxjs/toolkit";
+import { NameSpace } from "../const";
+import { offersData } from "./offers-data/offers-data";
+import { offerData } from "./offer-data/offer-data";
+import { userProcess } from "./user-process/user-process";
+import { commmonData } from "./common-data/common-data";
+
+export const rootReducer = combineReducers({
+ [NameSpace.Offers]: offersData.reducer,
+ [NameSpace.Offer]: offerData.reducer,
+ [NameSpace.User]: userProcess.reducer,
+ [NameSpace.Common]: commmonData.reducer,
+ });
\ No newline at end of file
diff --git a/src/store/user-process/selectors.ts b/src/store/user-process/selectors.ts
new file mode 100644
index 0000000..9f1d6b0
--- /dev/null
+++ b/src/store/user-process/selectors.ts
@@ -0,0 +1,6 @@
+import { AuthorizationStatus, NameSpace } from "../../const";
+import { State } from "../../types/state";
+import { UserData } from "../../types/user-data";
+
+export const getAuthorizationStatus = (state: State): AuthorizationStatus => state[NameSpace.User].authorizationStatus;
+export const getUserData = (state: State): UserData | undefined => state[NameSpace.User].userData;
\ No newline at end of file
diff --git a/src/store/user-process/user-process.ts b/src/store/user-process/user-process.ts
new file mode 100644
index 0000000..8a85bcc
--- /dev/null
+++ b/src/store/user-process/user-process.ts
@@ -0,0 +1,35 @@
+import { createSlice } from "@reduxjs/toolkit";
+import { AuthorizationStatus, NameSpace } from "../../const";
+import { checkAuthAction, loginAction, logoutAction } from "../api-actions";
+import { UserProcess } from "../../types/state";
+
+const initialState: UserProcess = {
+ authorizationStatus: AuthorizationStatus.Unknown,
+ userData: undefined,
+ };
+
+ export const userProcess = createSlice({
+ name: NameSpace.User,
+ initialState,
+ reducers: {},
+ extraReducers(builder) {
+ builder
+ .addCase(checkAuthAction.fulfilled, (state, action) => {
+ state.authorizationStatus = AuthorizationStatus.Auth;
+ state.userData = action.payload;
+ })
+ .addCase(checkAuthAction.rejected, (state) => {
+ state.authorizationStatus = AuthorizationStatus.NoAuth;
+ })
+ .addCase(loginAction.fulfilled, (state, action) => {
+ state.authorizationStatus = AuthorizationStatus.Auth;
+ state.userData = action.payload;
+ })
+ .addCase(loginAction.rejected, (state) => {
+ state.authorizationStatus = AuthorizationStatus.NoAuth;
+ })
+ .addCase(logoutAction.fulfilled, (state) => {
+ state.authorizationStatus = AuthorizationStatus.NoAuth;
+ });
+ }
+ });
\ No newline at end of file
diff --git a/src/types/state.ts b/src/types/state.ts
index c45a265..13b2136 100644
--- a/src/types/state.ts
+++ b/src/types/state.ts
@@ -1,4 +1,33 @@
-import { store } from '../store/index.js';
+import { AuthorizationStatus } from '../const';
+import { store } from '../store/index';
+import { Point } from './location';
+import { ExtendedOffer, Offer } from './offer';
+import { Review } from './review';
+import { UserData } from './user-data';
+
+export type OfferData = {
+ chosenOffer?: ExtendedOffer;
+ reviews: Review[];
+ nearbyOffers: Offer[];
+ isChosenOfferDataLoading: boolean;
+ };
+
+export type OffersData = {
+ offers: Offer[];
+ isOffersDataLoading: boolean;
+ };
+
+export type UserProcess = {
+ authorizationStatus: AuthorizationStatus;
+ userData?: UserData,
+ };
+
+export type CommonData = {
+ sortType: string;
+ city: string;
+ highlightedMarker: Point | undefined;
+ error: string | null;
+}
export type State = ReturnType;
From 2088b1fcd073a0ab4634a1f303c73e6d1eb866d5 Mon Sep 17 00:00:00 2001
From: mayonnaise <90057279+Mayanzev@users.noreply.github.com>
Date: Tue, 21 May 2024 13:28:57 +0300
Subject: [PATCH 3/3] fix lint
---
.../cards-sorting-options.tsx | 2 +-
src/components/comment-form/comment-form.tsx | 18 ++--
src/const.ts | 2 +-
src/store/action.ts | 2 +-
src/store/api-actions.ts | 14 +--
src/store/common-data/common-data.ts | 60 ++++++-------
src/store/common-data/selectors.ts | 8 +-
src/store/offer-data/offer-data.ts | 86 +++++++++----------
src/store/offer-data/selectors.ts | 10 +--
src/store/offers-data/offers-data.ts | 2 +-
src/store/offers-data/selectors.ts | 8 +-
src/store/root-reducer.ts | 22 ++---
src/store/user-process/selectors.ts | 8 +-
src/store/user-process/user-process.ts | 66 +++++++-------
src/types/state.ts | 2 +-
15 files changed, 157 insertions(+), 153 deletions(-)
diff --git a/src/components/cards-sorting-options/cards-sorting-options.tsx b/src/components/cards-sorting-options/cards-sorting-options.tsx
index 31f0ddd..02a3f9b 100644
--- a/src/components/cards-sorting-options/cards-sorting-options.tsx
+++ b/src/components/cards-sorting-options/cards-sorting-options.tsx
@@ -11,7 +11,7 @@ function CardsSortingOptionsComponent(): JSX.Element {
const handleSortOptionClick = (sortType: string) => {
dispatch(changeSortType(sortType));
- setIsSortOpened(false);
+ setIsSortOpened(false);
};
return (
diff --git a/src/components/comment-form/comment-form.tsx b/src/components/comment-form/comment-form.tsx
index 63e90bb..def1d3c 100644
--- a/src/components/comment-form/comment-form.tsx
+++ b/src/components/comment-form/comment-form.tsx
@@ -46,6 +46,16 @@ function CommentForm(): JSX.Element {
resetForm();
};
+ const ratingTitles: { [key: number]: string } = {
+ 5: 'excellent',
+ 4: 'good',
+ 3: 'not bad',
+ 2: 'badly',
+ 1: 'terribly'
+ };
+
+ const getRatingTitle = (rating: number): string => ratingTitles[rating];
+
return (