Skip to content

Commit c907cee

Browse files
committed
processed the opening and closing of the topics and chat components for different sizes of screen
1 parent 083d3cc commit c907cee

File tree

6 files changed

+52
-14
lines changed

6 files changed

+52
-14
lines changed

src/common/Sidebar/Sidebar.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ import { useMediaQuery } from 'react-responsive';
3232
import { useLogoutMutation } from '../../redux/auth-operations';
3333
import { useTopicsContext } from '../Topics/TopicsContext';
3434
import { useDispatch, useSelector } from 'react-redux';
35-
import { setIsLoggedIn } from '../../redux/authOperatonsToolkit/authOperationsThunkSlice';
35+
3636
import { selectChatOpened, setChatOpened } from '../../redux/chatSlice';
37+
import localLogOutUtil from '../../utils/localLogOutUtil';
3738

3839
const menuRoutes = [
3940
{
@@ -102,7 +103,7 @@ const Sidebar = () => {
102103
if (!isMobile) {
103104
setShowMenu(true);
104105
} else {
105-
setShowMenu(false);
106+
setShowMenu(true); // Mobile menu always true?
106107
}
107108
}, [isMobile, setShowMenu]);
108109

@@ -112,13 +113,15 @@ const Sidebar = () => {
112113

113114
if (error) {
114115
alert(error.data.message);
115-
dispatch(setIsLoggedIn(false));
116+
// dispatch(setIsLoggedIn(false));
117+
localLogOutUtil();
116118
return;
117119
}
118120

119121
// localLogOut();
120122
// navigate(PATH.MAIN);
121-
dispatch(setIsLoggedIn(false));
123+
// dispatch(setIsLoggedIn(false));
124+
localLogOutUtil();
122125
} catch (error) {
123126
console.error('Виникла помилка:', error);
124127
return;
@@ -131,6 +134,7 @@ const Sidebar = () => {
131134
setShowMenu(false);
132135
dispatch(setChatOpened(true));
133136
}
137+
134138
setShowTopics(true);
135139
navigate(path);
136140
};

src/common/Topics/ChatsBlock/ChatsBlock.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { selectAccessToken } from '../../../redux/authOperatonsToolkit/authOpera
3030
import localLogOutUtil from '../../../utils/localLogOutUtil';
3131

3232
const ChatsBlock = ({ filter }) => {
33-
const { isTopics } = useTopicsContext();
33+
const { isTopics, showTopics } = useTopicsContext();
3434
const ChatItems = ChatBlockDataHelper(isTopics); //?!
3535
const { pathname } = useLocation();
3636
const path = pathname.includes('topics') ? 'topics' : 'notification';

src/components/Layouts/Header/Header.jsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,50 @@ import { useSidebarContext } from '../../../common/Sidebar/SidebarContext';
99
import Wrapper from '../Wrapper';
1010
// import { useUser } from '../../../hooks/useUser';
1111
import { PATH } from '../../../constans/routes';
12-
import { NavLink } from 'react-router-dom';
12+
import { NavLink, useLocation } from 'react-router-dom';
1313
import HeaderUserInfo from './HeaderUserInfo';
1414
import { useTopicsContext } from '../../../common/Topics/TopicsContext';
1515
import { useDispatch, useSelector } from 'react-redux';
1616
import { selectIsLoggedIn } from '../../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
1717
import { setChatOpened } from '../../../redux/chatSlice';
18+
import { useMediaQuery } from 'react-responsive';
1819

1920
const Header = () => {
2021
const { showMenu, setShowMenu } = useSidebarContext();
2122
// const { isAuthenticated } = useUser();
2223
const { setShowTopics } = useTopicsContext();
24+
const { pathname } = useLocation();
25+
const path = pathname.includes('chat') ? 'chat' : 'notifications';
26+
27+
const isMobile = useMediaQuery({ query: '(max-width: 767px)' });
2328

2429
const isLoggedIn = useSelector(selectIsLoggedIn);
2530

2631
const dispatch = useDispatch();
2732

2833
const onIconMenuClick = () => {
29-
if (!showMenu) {
34+
if (!showMenu && path === 'chat') {
3035
dispatch(setChatOpened(false));
3136
} else {
3237
dispatch(setChatOpened(true));
3338
}
3439

40+
if (
41+
!showMenu &&
42+
isMobile &&
43+
(pathname.includes('topics') || pathname.includes('notification'))
44+
) {
45+
setShowTopics(false);
46+
} else {
47+
setShowTopics(true);
48+
}
49+
50+
if (showMenu && isMobile && pathname.includes('chat')) {
51+
setShowTopics(false);
52+
}
53+
3554
setShowMenu(!showMenu);
36-
setShowTopics(false);
55+
// setShowTopics(false);
3756
};
3857

3958
return (

src/pages/NotificationPage/NotificationPage.jsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ import { Outlet } from 'react-router';
33
import { NotificationPageWrap } from './NotificationPage.styled';
44
import Topics from '../../common/Topics';
55
import { useTopicsContext } from '../../common/Topics/TopicsContext';
6+
import { useMediaQuery } from 'react-responsive';
7+
import { useLocation } from 'react-router-dom';
68

79
const NotificationPage = () => {
8-
const { setІsTopics } = useTopicsContext();
10+
const { showTopics, setShowTopics, setІsTopics } = useTopicsContext();
11+
const isTablet = useMediaQuery({ query: '(max-width: 1199px)' });
12+
const { pathname } = useLocation();
913

1014
useEffect(() => {
1115
setІsTopics(false);
1216
// eslint-disable-next-line react-hooks/exhaustive-deps
1317
}, []);
1418

19+
useEffect(() => {
20+
if (isTablet && pathname.includes('notification/chat')) {
21+
setShowTopics(false);
22+
} else {
23+
setShowTopics(true);
24+
}
25+
});
26+
1527
return (
1628
<NotificationPageWrap>
17-
<Topics isTopics={false} />
29+
{showTopics ? <Topics isTopics={false} /> : null}
1830
<Outlet />
1931
</NotificationPageWrap>
2032
);

src/pages/NotificationPage/NotificationPage.styled.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { Box } from '@mui/material';
33

44
export const NotificationPageWrap = styled(Box)`
55
display: flex;
6-
flex-grow: 2;
6+
/* flex-grow: 2; */
77
88
@media screen and (min-width: calc(1200px - 0.02px)) {
9+
flex-grow: 2;
910
gap: 40px;
1011
}
1112
`;

src/pages/TopicsPage/TopicsPage.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-unused-vars */
12
import { useState, useEffect } from 'react';
23
import { useMediaQuery } from 'react-responsive';
34
import { Outlet, useLocation, useParams } from 'react-router-dom';
@@ -11,7 +12,7 @@ import { useTopicsContext } from '../../common/Topics/TopicsContext';
1112

1213
const useTabletAndBelowMediaQuery = () =>
1314
// useMediaQuery({ query: '(max-width: 770px)' });
14-
useMediaQuery({ query: '(max-width: 768px)' });
15+
useMediaQuery({ query: '(max-width: 1199px)' });
1516

1617
const useMobileMediaQuery = () =>
1718
// useMediaQuery({ query: '(max-width: 769px)' });
@@ -35,8 +36,9 @@ function TopicsPage() {
3536
}, []);
3637

3738
useEffect(() => {
38-
if (isTabletAndBelow && pathname.includes('chat')) setShowTopics(false);
39-
else setShowTopics(true);
39+
if (isTabletAndBelow && pathname.includes('chat')) {
40+
setShowTopics(false);
41+
} else setShowTopics(true);
4042
}, [setShowTopics, isTabletAndBelow, pathname, isMobile]);
4143

4244
const handleModal = () => {

0 commit comments

Comments
 (0)