-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
157 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +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"; | ||
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<string>) => { | ||
state.sortType = action.payload; | ||
}, | ||
changeCity: (state, action: PayloadAction<string>) => { | ||
state.city = action.payload; | ||
}, | ||
changeHighlightedMarker: (state, action: PayloadAction<Point | undefined>) => { | ||
state.highlightedMarker = action.payload; | ||
}, | ||
setError: (state, action: PayloadAction<string | null>) => { | ||
state.error = action.payload; | ||
}, | ||
sortType: filters.POPULAR, | ||
city: cities.Paris, | ||
highlightedMarker: undefined, | ||
error: null, | ||
}; | ||
|
||
export const commmonData = createSlice({ | ||
name: NameSpace.Common, | ||
initialState, | ||
reducers: { | ||
changeSortType: (state, action: PayloadAction<string>) => { | ||
state.sortType = action.payload; | ||
}, | ||
changeCity: (state, action: PayloadAction<string>) => { | ||
state.city = action.payload; | ||
}, | ||
changeHighlightedMarker: (state, action: PayloadAction<Point | undefined>) => { | ||
state.highlightedMarker = action.payload; | ||
}, | ||
}); | ||
|
||
export const { changeSortType, changeCity, changeHighlightedMarker, setError } = commmonData.actions; | ||
setError: (state, action: PayloadAction<string | null>) => { | ||
state.error = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { changeSortType, changeCity, changeHighlightedMarker, setError } = commmonData.actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { NameSpace } from "../../const"; | ||
import { Point } from "../../types/location"; | ||
import { State } from "../../types/state"; | ||
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; | ||
export const getError = (state: State): string | null => state[NameSpace.Common].error; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,46 @@ | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
import { NameSpace } from "../../const"; | ||
import { fetchNearbyAction, fetchOfferAction, fetchReviewsAction, postReviewAction } from "../api-actions"; | ||
import { OfferData } from "../../types/state"; | ||
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; | ||
}) | ||
} | ||
} | ||
); | ||
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; | ||
}); | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { NameSpace } from "../../const"; | ||
import { ExtendedOffer, Offer } from "../../types/offer"; | ||
import { Review } from "../../types/review"; | ||
import { State } from "../../types/state"; | ||
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; | ||
export const getIsChosenOfferDataLoading = (state: State): boolean => state[NameSpace.Offer].isChosenOfferDataLoading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { NameSpace } from "../../const"; | ||
import { Offer } from "../../types/offer"; | ||
import { State } from "../../types/state"; | ||
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; | ||
export const getIsOffersDataLoading = (state: State): boolean => state[NameSpace.Offers].isOffersDataLoading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +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"; | ||
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, | ||
}); | ||
[NameSpace.Offers]: offersData.reducer, | ||
[NameSpace.Offer]: offerData.reducer, | ||
[NameSpace.User]: userProcess.reducer, | ||
[NameSpace.Common]: commmonData.reducer, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { AuthorizationStatus, NameSpace } from "../../const"; | ||
import { State } from "../../types/state"; | ||
import { UserData } from "../../types/user-data"; | ||
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; | ||
export const getUserData = (state: State): UserData | undefined => state[NameSpace.User].userData; |
Oops, something went wrong.