From ba88c506b9829ec4a71cf7bf770910c2b87044c5 Mon Sep 17 00:00:00 2001 From: dinar1122 Date: Sat, 19 Apr 2025 03:27:03 +0300 Subject: [PATCH 1/6] lecture 5 done --- src/api/index.js | 10 ++++ src/app/article/index.js | 18 +++++- src/app/login/index.js | 1 + src/components/article-card/index.js | 8 +-- src/components/comment-form/index.js | 59 +++++++++++++++++++ src/components/comment-item/index.js | 72 +++++++++++++++++++++++ src/components/comment-item/style.css | 56 ++++++++++++++++++ src/components/comments-wrapper/index.js | 60 +++++++++++++++++++ src/components/comments-wrapper/style.css | 35 +++++++++++ src/components/form/index.js | 21 ++++++- src/components/form/style.css | 17 +++++- src/components/input/index.js | 6 +- src/components/input/style.css | 26 ++++++++ src/containers/locale-select/index.js | 18 +----- src/hooks/use-translate.js | 28 ++++++--- src/i18n/context.js | 30 ---------- src/i18n/index.js | 53 +++++++++++++++++ src/i18n/translate.js | 21 ------- src/i18n/translations/en.json | 7 ++- src/i18n/translations/ru.json | 7 ++- src/index.js | 9 +-- src/services.js | 12 ++++ src/store-redux/comments/actions.js | 68 +++++++++++++++++++++ src/store-redux/comments/reducer.js | 67 +++++++++++++++++++++ src/store-redux/exports.js | 1 + src/store/session/index.js | 1 + 26 files changed, 618 insertions(+), 93 deletions(-) create mode 100644 src/components/comment-form/index.js create mode 100644 src/components/comment-item/index.js create mode 100644 src/components/comment-item/style.css create mode 100644 src/components/comments-wrapper/index.js create mode 100644 src/components/comments-wrapper/style.css delete mode 100644 src/i18n/context.js create mode 100644 src/i18n/index.js delete mode 100644 src/i18n/translate.js create mode 100644 src/store-redux/comments/actions.js create mode 100644 src/store-redux/comments/reducer.js diff --git a/src/api/index.js b/src/api/index.js index a5f073295..a6d56f6a8 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -9,8 +9,18 @@ class APIService { this.defaultHeaders = { 'Content-Type': 'application/json', }; + this.unsubscribe = this.services.i18n.subscribe((locale) => { + this.updateLanguageHeader(locale); + }); + + this.updateLanguageHeader(this.services.i18n.getLocale()); + + } + updateLanguageHeader(locale) { + this.defaultHeaders['Accept-Language'] = locale || 'ru'; } + /** * HTTP запрос * @param url diff --git a/src/app/article/index.js b/src/app/article/index.js index 54f037b64..50d9646bd 100644 --- a/src/app/article/index.js +++ b/src/app/article/index.js @@ -13,7 +13,9 @@ import TopHead from '../../containers/top-head'; import { useDispatch, useSelector } from 'react-redux'; import shallowequal from 'shallowequal'; import articleActions from '../../store-redux/article/actions'; +import commentsActions from '../../store-redux/comments/actions'; import HeadLayout from '../../components/head-layout'; +import CommentsWrapper from '../../components/comments-wrapper'; function Article() { const store = useStore(); @@ -26,11 +28,14 @@ function Article() { useInit(() => { //store.actions.article.load(params.id); dispatch(articleActions.load(params.id)); + dispatch(commentsActions.load(params.id)); }, [params.id]); const select = useSelector( state => ({ article: state.article.data, + comments: state.comments.data, + commentsWaiting: state.comments.waiting, waiting: state.article.waiting, }), shallowequal, @@ -42,7 +47,6 @@ function Article() { // Добавление в корзину addToBasket: useCallback(_id => store.actions.basket.addToBasket(_id), [store]), }; - return ( <> @@ -56,6 +60,18 @@ function Article() { + {select.commentsWaiting ? ( +
+ Загрузка комментариев... +
+ ) : ( + + )} ); diff --git a/src/app/login/index.js b/src/app/login/index.js index 32b86daa4..3fb13833b 100644 --- a/src/app/login/index.js +++ b/src/app/login/index.js @@ -15,6 +15,7 @@ import useInit from '../../hooks/use-init'; import HeadLayout from '../../components/head-layout'; import Form from '../../components/form'; + function Login() { const { t } = useTranslate(); const location = useLocation(); diff --git a/src/components/article-card/index.js b/src/components/article-card/index.js index d636d9f88..76ef8706c 100644 --- a/src/components/article-card/index.js +++ b/src/components/article-card/index.js @@ -13,22 +13,22 @@ function ArticleCard(props) {
{article.description}
-
Страна производитель:
+
{t(`product.country`)}:
{article.madeIn?.title} ({article.madeIn?.code})
-
Категория:
+
{t(`product.category`)}:
{article.category?.title}
-
Год выпуска:
+
{t(`product.year`)}:
{article.edition}
-
Цена:
+
{t(`product.price`)}:
{numberFormat(article.price)} ₽