Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayanzev committed May 21, 2024
1 parent abe65b6 commit 2088b1f
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function CardsSortingOptionsComponent(): JSX.Element {

const handleSortOptionClick = (sortType: string) => {
dispatch(changeSortType(sortType));
setIsSortOpened(false);
setIsSortOpened(false);
};

return (
Expand Down
18 changes: 11 additions & 7 deletions src/components/comment-form/comment-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,24 @@ 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 (
<form className="reviews__form form" method="post">
<label className="reviews__label form__label" htmlFor="review">Your review</label>
<div className="reviews__rating-form form__rating">
{[5, 4, 3, 2, 1].map((rating) => (
<Fragment key={rating}>
<input className="form__rating-input visually-hidden" name="rating" value={rating} id={`${rating}-stars`} type="radio" checked={Number(formData.rating) === rating} onChange={handleFieldChange} />
<label htmlFor={`${rating}-stars`} className="reviews__rating-label form__rating-label" title={
rating === 5 ? "excellent" :
rating === 4 ? "good" :
rating === 3 ? "not bad" :
rating === 2 ? "badly" : "terribly"
}
>
<label htmlFor={`${rating}-stars`} className="reviews__rating-label form__rating-label" title={getRatingTitle(rating)}>
<svg className="form__star-image" width="37" height="33">
<use xlinkHref="#icon-star"></use>
</svg>
Expand Down
2 changes: 1 addition & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ export enum NameSpace {
Offer = 'OFFER',
Offers = 'OFFERS',
User = 'USER',
Common = "COMMON"
Common = 'COMMON'
}
2 changes: 1 addition & 1 deletion src/store/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { AppRoute} from '../const';

export const redirectToRoute = createAction('REDIRECT_TO_ROUTE', (value: AppRoute) => ({
payload: value
}));
}));
14 changes: 7 additions & 7 deletions src/store/api-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { setError } from './common-data/common-data';

export const clearErrorAction = createAsyncThunk(
'CLEAR_ERROR_ACTION',
async (_, { dispatch }) => {
(_, { dispatch }) => {
setTimeout(() => {
dispatch(setError(null));
}, TIMEOUT_SHOW_ERROR);
Expand All @@ -28,7 +28,7 @@ export const fetchOffersAction = createAsyncThunk<Offer[], undefined, {
'FETCH_OFFERS_ACTION',
async (_arg, { extra: api }) => {
const { data } = await api.get<Offer[]>(APIRoute.Offers);
return data
return data;
},
);

Expand All @@ -40,7 +40,7 @@ export const checkAuthAction = createAsyncThunk<UserData, undefined, {
'CHECK_AUTH_ACTION',
async (_arg, { extra: api }) => {
const { data } = await api.get<UserData>(APIRoute.Login);
return data
return data;
}
);

Expand Down Expand Up @@ -78,7 +78,7 @@ export const fetchOfferAction = createAsyncThunk<ExtendedOffer, string, {
'FETCH_OFFER_ACTION',
async (id, { extra: api }) => {
const { data } = await api.get<ExtendedOffer>(`${APIRoute.Offers}/${id}`);
return data
return data;
},
);

Expand All @@ -90,7 +90,7 @@ export const fetchReviewsAction = createAsyncThunk<Review[], string, {
'FETCH_REVIEWS_ACTION',
async (id, { extra: api }) => {
const { data } = await api.get<Review[]>(`${APIRoute.Comments}/${id}`);
return data
return data;
},
);

Expand All @@ -102,7 +102,7 @@ export const fetchNearbyAction = createAsyncThunk<Offer[], string, {
'FETCH_NEARBY_ACTION',
async (id, { extra: api }) => {
const { data } = await api.get<Offer[]>(`${APIRoute.Offers}/${id}${APIRoute.Nearby}`);
return data
return data;
},
);

Expand All @@ -120,7 +120,7 @@ export const postReviewAction = createAsyncThunk<Review[], {
async ({ id, comment, rating }, { extra: api }) => {
await api.post(`${APIRoute.Comments}/${id}`, { comment, rating });
const { data } = await api.get<Review[]>(`${APIRoute.Comments}/${id}`);
return data
return data;
},
);

60 changes: 30 additions & 30 deletions src/store/common-data/common-data.ts
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;
8 changes: 4 additions & 4 deletions src/store/common-data/selectors.ts
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;
86 changes: 43 additions & 43 deletions src/store/offer-data/offer-data.ts
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;
});
}
}
);
10 changes: 5 additions & 5 deletions src/store/offer-data/selectors.ts
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;
2 changes: 1 addition & 1 deletion src/store/offers-data/offers-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export const offersData = createSlice({
})
.addCase(logoutAction.pending, (state) => {
state.isOffersDataLoading = true;
})
});
},
});
8 changes: 4 additions & 4 deletions src/store/offers-data/selectors.ts
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;
22 changes: 11 additions & 11 deletions src/store/root-reducer.ts
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,
});
8 changes: 4 additions & 4 deletions src/store/user-process/selectors.ts
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;
Loading

0 comments on commit 2088b1f

Please sign in to comment.