Skip to content

Commit

Permalink
исправил часть проблем
Browse files Browse the repository at this point in the history
  • Loading branch information
Haykashen committed Oct 15, 2024
1 parent 7c5c861 commit fe60641
Show file tree
Hide file tree
Showing 34 changed files with 259 additions and 747 deletions.
31 changes: 26 additions & 5 deletions src/app/article/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,49 @@ import TopHead from '../../containers/top-head';
import { useDispatch, useSelector } from 'react-redux';
import shallowequal from 'shallowequal';
import articleActions from '../../store-redux/article/actions';
import Reviews from '../reviews';
import commentsActions from '../../store-redux/comments/actions';
import CommentContainer from '../../containers/comment';

function Article() {
const store = useStore();

const dispatch = useDispatch();
// Параметры из пути /articles/:id

const params = useParams();

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,
waiting: state.article.waiting,
comments: state.comments.data,
waitingComments: state.comments.waiting
}),
shallowequal,
);
); // Нужно указать функцию для сравнения свойства объекта, так как хуком вернули объект

const { t } = useTranslate();

const callbacks = {
// Добавление в корзину
addToBasket: useCallback(_id => store.actions.basket.addToBasket(_id), [store]),
};

const handleReply = commentId => {
dispatch(commentsActions.setReplyTo(commentId));
};
//const tree = listToTree(select.comments.items)
// const commentsArray = treeToList(listToTree(select.comments.items)) ;
console.log('select.comments.items=',select.comments.items)
//const commentsArray = select.comments.items.map(comment => (
// <CommentContainer key={comment._id} comment={comment} onReply={handleReply} level={0}/>
//))
return (
<PageLayout>
<TopHead />
Expand All @@ -47,9 +65,12 @@ function Article() {
<Navigation />
<Spinner active={select.waiting}>
<ArticleCard article={select.article} onAdd={callbacks.addToBasket} t={t} />
<Reviews/>
</Spinner>
<h3 style={{ margin: '30px 0 25px 30px'}}>Комментарии ({select.comments.count})</h3>
<div>{select.comments.items && select.comments.items.map(comment => (<CommentContainer key={comment._id} comment={comment} onReply={handleReply} level={0}/>))} </div>

</PageLayout>
);
}
export default memo(Article);

export default memo(Article);
10 changes: 8 additions & 2 deletions src/app/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import { useCallback, useContext, useEffect, useState } from 'react';
import { Routes, Route } from 'react-router-dom';
import useSelector from '../hooks/use-selector';
import useStore from '../hooks/use-store';
import useInit from '../hooks/use-init';
import Main from './main';
Expand All @@ -9,6 +10,7 @@ import Login from './login';
import Profile from './profile';
import Protected from '../containers/protected';
import { useSelector as useSelectorRedux } from 'react-redux';

/**
* Приложение
* @returns {React.ReactElement}
Expand All @@ -18,7 +20,9 @@ function App() {
useInit(async () => {
await store.actions.session.remind();
});

const activeModal = useSelectorRedux(state => state.modals.name);

return (
<>
<Routes>
Expand All @@ -34,8 +38,10 @@ function App() {
}
/>
</Routes>

{activeModal === 'basket' && <Basket />}
</>
);
}
export default App;

export default App;
12 changes: 8 additions & 4 deletions src/app/login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@ function Login() {
const location = useLocation();
const navigate = useNavigate();
const store = useStore();

useInit(() => {
store.actions.session.resetErrors();
});

const select = useSelector(state => ({
waiting: state.session.waiting,
errors: state.session.errors,
}));

const [data, setData] = useState({
login: '',
password: '',
});

const callbacks = {
// Колбэк на ввод в элементах формы
onChange: useCallback((value, name) => {
setData(prevData => ({ ...prevData, [name]: value }));
}, []),

// Отправка данных формы для авторизации
onSubmit: useCallback(
e => {
Expand All @@ -47,9 +52,7 @@ function Login() {
navigate(back);
});
},

[data, location.state, navigate, store.actions.session]
// [data, location.state],
[data, location.state],
),
};

Expand Down Expand Up @@ -83,4 +86,5 @@ function Login() {
</PageLayout>
);
}
export default memo(Login);

export default memo(Login);
74 changes: 0 additions & 74 deletions src/app/reviews/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/comment-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const CommentView = ({
: 'comment-author';

return (
<div className="comment" style={{ marginLeft: `${indent}px` }}>
<div className="comment" style={{ marginLeft: `${indent}px`, marginRight: `${indent}px`}}>
<div className="comment-item" style={{ marginBottom: '30px' }}>
<strong className={authorClassName}>{comment.author?.profile?.name || 'Аноним'}</strong>{' '}
<span className="comment-date">
Expand Down
1 change: 0 additions & 1 deletion src/components/comment-view/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.comment-author--current {
color: #666666;
}
Expand Down
85 changes: 0 additions & 85 deletions src/components/comment/index.js

This file was deleted.

33 changes: 0 additions & 33 deletions src/components/comment/style.css

This file was deleted.

22 changes: 0 additions & 22 deletions src/components/comment_footer/index.js

This file was deleted.

Loading

0 comments on commit fe60641

Please sign in to comment.