Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 25 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class APIService {
'Content-Type': 'application/json',
};
}

/**
* HTTP запрос
* @param url
Expand All @@ -21,9 +20,14 @@ class APIService {
*/
async request({ url, method = 'GET', headers = {}, ...options }) {
if (!url.match(/^(http|\/\/)/)) url = this.config.baseUrl + url;

// Извлечем язык, раз у нас уже есть сервис здесь, и перед каждым запросом будем его обновлять
// а в main добавим зависимость lang
const lang = this.services.i18n.getLang();

const res = await fetch(url, {
method,
headers: { ...this.defaultHeaders, ...headers },
headers: { ...this.defaultHeaders, ...headers, 'Accept-language': lang },
...options,
});
return { data: await res.json(), status: res.status, headers: res.headers };
Expand Down
17 changes: 15 additions & 2 deletions src/app/article/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ 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/comment/actions';
import HeadLayout from '../../components/head-layout';
import Comments from '../../containers/comment/';
import { useSelector as useSelectorRedux } from 'react-redux';

function Article() {
const store = useStore();
const { t, lang } = useTranslate();

const dispatch = useDispatch();
// Параметры из пути /articles/:id
Expand All @@ -26,7 +30,8 @@ function Article() {
useInit(() => {
//store.actions.article.load(params.id);
dispatch(articleActions.load(params.id));
}, [params.id]);
dispatch(commentsActions.load(params.id));
}, [params.id, lang]);

const select = useSelector(
state => ({
Expand All @@ -36,7 +41,12 @@ function Article() {
shallowequal,
); // Нужно указать функцию для сравнения свойства объекта, так как хуком вернули объект

const { t } = useTranslate();
const selectRedux = useSelectorRedux(
state => ({
waiting: state.comment.waiting,
}),
shallowequal,
);

const callbacks = {
// Добавление в корзину
Expand All @@ -56,6 +66,9 @@ function Article() {
<Spinner active={select.waiting}>
<ArticleCard article={select.article} onAdd={callbacks.addToBasket} t={t} />
</Spinner>
<Spinner active={selectRedux.waiting}>
<Comments />
</Spinner>
</PageLayout>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions src/app/login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import HeadLayout from '../../components/head-layout';
import Form from '../../components/form';

function Login() {
const { t } = useTranslate();
const { t, lang } = useTranslate();
const location = useLocation();
const navigate = useNavigate();
const store = useStore();

useInit(() => {
store.actions.session.resetErrors();
});
}, [lang]);

const select = useSelector(state => ({
waiting: state.session.waiting,
Expand Down
5 changes: 2 additions & 3 deletions src/app/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ import HeadLayout from '../../components/head-layout';

function Main() {
const store = useStore();
const { t, lang } = useTranslate();

useInit(
async () => {
await Promise.all([store.actions.catalog.initParams(), store.actions.categories.load()]);
},
[],
[lang],
true,
);

const { t } = useTranslate();

return (
<>
<HeadLayout>
Expand Down
5 changes: 2 additions & 3 deletions src/app/profile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ import HeadLayout from '../../components/head-layout';

function Profile() {
const store = useStore();
const { t, lang } = useTranslate();

useInit(() => {
store.actions.profile.load();
}, []);
}, [lang]);

const select = useSelector(state => ({
profile: state.profile.data,
waiting: state.profile.waiting,
}));

const { t } = useTranslate();

return (
<>
<HeadLayout>
Expand Down
2 changes: 1 addition & 1 deletion src/components/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Button({ onClick = () => {}, title, style, type = 'button' }) {

return (
<div className={cn()}>
<button type={type} className={cn({ style })} onClick={() => onClick()}>{title}</button>
<button type={type} className={cn({ style })} onClick={(e) => onClick(e)}>{title}</button>
</div>
);
}
Expand Down
Loading