-
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.
Добро пожаловать, или посторонним вход воспрещён (часть 2) (#11)
* добавляет работу формы для комментариев * добавляет работу формы для комментариев * favorites * роуты * форма и фавориты
- Loading branch information
Showing
42 changed files
with
613 additions
and
201 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {AppRoute, AuthStatus} from '../../const.ts'; | ||
import {Navigate, useLocation} from 'react-router-dom'; | ||
import React from 'react'; | ||
import {useAppSelector} from '../../hooks/store.ts'; | ||
import {userSelectors} from '../../store/slices/user.ts'; | ||
import Loader from '../loader/loader.tsx'; | ||
|
||
type AccessRouteProps = { | ||
children: React.JSX.Element; | ||
} | ||
|
||
type Redirect = { | ||
from?: string; | ||
}; | ||
|
||
const createAccessRoute = (status: AuthStatus, fallback: AppRoute) => | ||
function AccessRoute({children}: AccessRouteProps) { | ||
const authStatus = useAppSelector(userSelectors.authStatus); | ||
const location = useLocation(); | ||
|
||
if (authStatus === AuthStatus.Unknown) { | ||
return <Loader/>; | ||
} | ||
|
||
const redirect = (location.state as Redirect ?? {}).from ?? fallback; | ||
|
||
return ( | ||
authStatus === status | ||
? children | ||
: | ||
<Navigate | ||
to={redirect} | ||
state={{ | ||
from: location.pathname | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
const PrivateRoute = createAccessRoute(AuthStatus.Auth, AppRoute.Login); | ||
const PublicRoute = createAccessRoute(AuthStatus.NoAuth, AppRoute.Root); | ||
|
||
|
||
export {PrivateRoute, PublicRoute}; |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type {OfferFullInfo} from '../../types/offer.ts'; | ||
import {useActionCreators, useAppSelector} from '../../hooks/store.ts'; | ||
import {useEffect} from 'react'; | ||
import {commentsActions, commentsSelectors} from '../../store/slices/comments.ts'; | ||
import Review from '../review/review.tsx'; | ||
|
||
interface CommentsListProps { | ||
offerId: OfferFullInfo['id']; | ||
} | ||
|
||
const MAX_COUNT_COMMENTS = 10; | ||
|
||
function CommentsList ({offerId}: CommentsListProps) { | ||
const {fetchComments} = useActionCreators(commentsActions); | ||
const postCommentStatus = useAppSelector(commentsSelectors.statusPostRequest); | ||
const comments = useAppSelector(commentsSelectors.sortedComments).slice(0, MAX_COUNT_COMMENTS); | ||
const commentsCount = comments.length; | ||
|
||
useEffect(() => { | ||
fetchComments(offerId); | ||
}, [postCommentStatus, offerId]); | ||
|
||
return ( | ||
<> | ||
<h2 className="reviews__title"> | ||
Reviews · <span className="reviews__amount">{commentsCount}</span> | ||
</h2> | ||
<ul className="reviews__list"> | ||
{ | ||
commentsCount > 0 && | ||
comments.map((comment) => <Review key={comment.id} review={comment}/> | ||
) | ||
} | ||
</ul> | ||
</> | ||
); | ||
} | ||
|
||
export default CommentsList; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const MIN_LENGTH_COMMENT = 50; | ||
const MAX_LENGTH_COMMENT = 300; | ||
const MIN_STARS_COMMENT = 1; | ||
|
||
export {MAX_LENGTH_COMMENT, MIN_STARS_COMMENT, MIN_LENGTH_COMMENT}; |
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
Oops, something went wrong.