Skip to content

Commit 9ec1179

Browse files
authored
Добавил возможность переходить в свой профиль на мобилке (#351)
1 parent 111cae3 commit 9ec1179

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

src/components/layout/header/AdaptiveMenu.jsx

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
44
import styled from 'styled-components';
55
import { Button } from 'antd';
66
import { useAuth } from 'common/context/Auth/useAuth';
7+
import { useSelector } from 'react-redux';
8+
import { selectProfile } from 'features/profile/profileSlice';
79

810
const StyledMenu = styled.ul`
911
list-style: none;
@@ -20,10 +22,29 @@ const StyledMenu = styled.ul`
2022
}
2123
`;
2224

25+
const StyledAvatar = styled.div`
26+
& > img {
27+
width: 50px;
28+
height: 50px;
29+
border-radius: 50%;
30+
cursor: pointer;
31+
}
32+
`;
33+
34+
const Line = styled.hr`
35+
margin-top: 10px;
36+
width: 90%;
37+
border: 0;
38+
height: 1px;
39+
background: #333;
40+
background-image: linear-gradient(to right, #ccc, #333, #ccc);
41+
`;
42+
2343
const AdaptiveMenu = ({ toggleMobileMenu, mobileMenu }) => {
2444
const location = useLocation();
2545
const history = useHistory();
2646
const { token, executeLoggingInProcess, logout } = useAuth();
47+
const profile = useSelector(selectProfile);
2748

2849
const handleAddQuestion = useCallback(() => {
2950
history.push('/create');
@@ -54,19 +75,36 @@ const AdaptiveMenu = ({ toggleMobileMenu, mobileMenu }) => {
5475
{
5576
id: 2,
5677
protected: true,
78+
jsx: (
79+
<>
80+
<Link to="/profile">
81+
<div className="d-flex align-items-center">
82+
<StyledAvatar>
83+
<img className="m-auto" src={profile.avatar?.thumbnail} alt="" />
84+
</StyledAvatar>
85+
<span className="nameUser mx-2">Профиль @{profile.name}</span>
86+
</div>
87+
</Link>
88+
<Line />
89+
</>
90+
),
91+
},
92+
{
93+
id: 3,
94+
protected: true,
5795
jsx: (
5896
<div>
5997
<Link to="/favorites">Избранные</Link>
6098
</div>
6199
),
62100
},
63101
{
64-
id: 3,
102+
id: 4,
65103
protected: true,
66104
jsx: <Link to="/cart">Корзина</Link>,
67105
},
68106
{
69-
id: 4,
107+
id: 5,
70108
protected: true,
71109
jsx: (
72110
<Link to="/" onClick={logout}>
@@ -75,7 +113,7 @@ const AdaptiveMenu = ({ toggleMobileMenu, mobileMenu }) => {
75113
),
76114
},
77115
{
78-
id: 5,
116+
id: 6,
79117
guest: true,
80118
jsx: (
81119
<Button
@@ -99,7 +137,7 @@ const AdaptiveMenu = ({ toggleMobileMenu, mobileMenu }) => {
99137

100138
return true;
101139
});
102-
}, [executeLoggingInProcess, handleAddQuestion, logout, token]);
140+
}, [executeLoggingInProcess, handleAddQuestion, logout, profile, token]);
103141

104142
if (!mobileMenu) return null;
105143

0 commit comments

Comments
 (0)