Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change logic of handling all notifications array #120

Merged
merged 1 commit into from
Oct 13, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/common/Topics/ChatsBlock/ChatsBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '../../../redux/chatSlice';
import { useUser } from '../../../hooks/useUser';
// eslint-disable-next-line max-len
import { selectAccessToken } from '../../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
import { selectAccessToken } from '../../../redux/authOperationsToolkit/authOperationsThunkSelectors';
import localLogOutUtil from '../../../utils/localLogOutUtil';
import {
subscribeOnlineOrTypingStatus,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Chat/Chat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import {
useSendMessageToNewTopicMutation,
useSendMessageToTopicMutation,
} from '../../redux/messagesAPI/messagesAPI';
import { selectAccessToken } from '../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
import { selectAccessToken } from '../../redux/authOperationsToolkit/authOperationsThunkSelectors';
import localLogOutUtil from '../../utils/localLogOutUtil';
import UsersAvatar from './UsersAvatar/';
import { useMediaQuery } from 'react-responsive';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useInView } from 'react-intersection-observer';
import { MessageContainer } from '../Chat.styled';
import { useSetMessageStatusMutation } from '../../../redux/messagesAPI/messagesAPI';
import { useDispatch, useSelector } from 'react-redux';
import { selectAccessToken } from '../../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
import { selectAccessToken } from '../../../redux/authOperationsToolkit/authOperationsThunkSelectors';
import { useEffect, useState } from 'react';
import { deletReadedAllTopicsNotification } from '../../../redux/chatSlice';

Expand Down
4 changes: 2 additions & 2 deletions src/components/Chat/TopicSettingsMenu/TopicSettingsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import {
} from '../../../redux/topics-operations';
import { useDispatch, useSelector } from 'react-redux';
// eslint-disable-next-line max-len
import { selectAccessToken } from '../../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
import { selectAccessToken } from '../../../redux/authOperationsToolkit/authOperationsThunkSelectors';
import {
setAccessToken,
setIsLoggedIn,
setRefreshToken,
} from '../../../redux/authOperatonsToolkit/authOperationsThunkSlice';
} from '../../../redux/authOperationsToolkit/authOperationsThunkSlice';
import localLogOutUtil from '../../../utils/localLogOutUtil';

const TopicSettingsMenu = ({ topicId, subscribeStatus }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Chat/UsersAvatar/UsersAvatar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useSelector } from 'react-redux';
import { useGetSubscribersQuery } from '../../../redux/topics-operations';
// eslint-disable-next-line max-len
import { selectAccessToken } from '../../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
import { selectAccessToken } from '../../../redux/authOperationsToolkit/authOperationsThunkSelectors';
import { Avatars } from '../../../ui-kit/images/avatars';
import Avatar from '../../../ui-kit/components/Avatar';

Expand Down
2 changes: 1 addition & 1 deletion src/components/Layouts/Footer/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useDispatch, useSelector } from 'react-redux';
import {
selectAccessToken,
selectIsLoggedIn,
} from '../../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
} from '../../../redux/authOperationsToolkit/authOperationsThunkSelectors';
// import {
// setAccessToken,
// setIsLoggedIn,
Expand Down
3 changes: 2 additions & 1 deletion src/components/Layouts/Header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { NavLink, useLocation } from 'react-router-dom';
import HeaderUserInfo from './HeaderUserInfo';
import { useTopicsContext } from '../../../common/Topics/TopicsContext';
import { useDispatch, useSelector } from 'react-redux';
import { selectIsLoggedIn } from '../../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
// eslint-disable-next-line max-len
import { selectIsLoggedIn } from '../../../redux/authOperationsToolkit/authOperationsThunkSelectors';
import { setChatOpened } from '../../../redux/chatSlice';
import { useMediaQuery } from 'react-responsive';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
UserName,
} from './HeaderUserInfo.styled';
// eslint-disable-next-line max-len
import { selectAccessToken } from '../../../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
import { selectAccessToken } from '../../../../redux/authOperationsToolkit/authOperationsThunkSelectors';
import localLogOutUtil from '../../../../utils/localLogOutUtil';
// import { selectUserThunk } from '../../../../redux/userApiThunk/userApiThunkSelectors';
// import { useUser } from '../../../../hooks/useUser';
Expand Down
2 changes: 1 addition & 1 deletion src/components/LoginPageComponent/LoginPageComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
setAccessToken,
setIsLoggedIn,
setRefreshToken,
} from '../../redux/authOperatonsToolkit/authOperationsThunkSlice.js';
} from '../../redux/authOperationsToolkit/authOperationsThunkSlice.js';

function LoginPageComponent() {
const [login] = useLoginMutation();
Expand Down
2 changes: 1 addition & 1 deletion src/components/NewTopic/NewTopic.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import NewTopicInput from './NewTopicInput';
import { useCreateMutation } from '../../redux/topics-operations';
import { useDispatch, useSelector } from 'react-redux';
import { selectAccessToken } from '../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
import { selectAccessToken } from '../../redux/authOperationsToolkit/authOperationsThunkSelectors';
import localLogOutUtil from '../../utils/localLogOutUtil';

const defaultValues = {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Routes/PrivateRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Navigate, Outlet } from 'react-router-dom';
// import { useUser } from '../../hooks/useUser';
// import { PATH } from '../../constans/routes';
import { useSelector } from 'react-redux';
import { selectIsLoggedIn } from '../../redux/authOperatonsToolkit/authOperationsThunkSelectors.js';
// eslint-disable-next-line max-len
import { selectIsLoggedIn } from '../../redux/authOperationsToolkit/authOperationsThunkSelectors.js';

export const PrivateRoute = ({ redirectTo }) => {
// const { isAuthenticated } = useUser();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Routes/PublicRoute.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSelector } from 'react-redux';
import { Navigate, Outlet } from 'react-router-dom';
import { selectIsLoggedIn } from '../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
import { selectIsLoggedIn } from '../../redux/authOperationsToolkit/authOperationsThunkSelectors';
// import { useUser } from '../../hooks/useUser';
// import { PATH } from '../../constans/routes';
// import { useSelector } from 'react-redux';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { useSelector } from 'react-redux';
import { selectUserInfo } from '../../../redux/userSlice';
// eslint-disable-next-line max-len
import { selectAccessToken } from '../../../redux/authOperatonsToolkit/authOperationsThunkSelectors';
import { selectAccessToken } from '../../../redux/authOperationsToolkit/authOperationsThunkSelectors';

export const PermissionPrivateMessage = () => {
const { hasPermissionSendingPrivateMessage } = useSelector(selectUserInfo);
Expand Down
49 changes: 24 additions & 25 deletions src/hooks/useAllTopicsNotificationInfo.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { selectAccessToken } from '../redux/authOperatonsToolkit/authOperationsThunkSelectors';
import { selectAccessToken } from '../redux/authOperationsToolkit/authOperationsThunkSelectors';
import {
useGetAllPrivateTopicsQuery,
useGetAllQuery,
} from '../redux/topics-operations';
import { setAllTopicsNotifications } from '../redux/chatSlice';
fetchNotificationsAllTopics,
fetchNotificationsPrivateTopics,
} from '../redux/chatSlice';
// import { useGetAllPrivateTopicsQuery, useGetAllQuery } from '../redux/topics-operations';
// import { setAllTopicsNotifications } from '../redux/chatSlice';

export const useAllTopicsNotificationInfo = (isLoggedIn) => {
const accessTokenInStore = useSelector(selectAccessToken);
const { currentData: allTopicsCurrentData } = useGetAllQuery({
accessTokenInStore,
});
const { currentData: privateTopicsData } =
useGetAllPrivateTopicsQuery(accessTokenInStore);

// const { currentData: allTopicsCurrentData } = useGetAllQuery({
// accessTokenInStore,
// });
// const { currentData: privateTopicsData } = useGetAllPrivateTopicsQuery(accessTokenInStore);

const dispatch = useDispatch();
// useEffect for notification array filling
useEffect(() => {
if (isLoggedIn && accessTokenInStore) {
if (allTopicsCurrentData && privateTopicsData) {
dispatch(
setAllTopicsNotifications([
...allTopicsCurrentData.filter((el) => el.unreadMessageCount !== 0),
...privateTopicsData.filter((el) => el.unreadMessageCount !== 0),
]),
);
}
dispatch(fetchNotificationsAllTopics(accessTokenInStore));
dispatch(fetchNotificationsPrivateTopics(accessTokenInStore));
// if (allTopicsCurrentData && privateTopicsData) {
// dispatch(
// setAllTopicsNotifications([
// ...allTopicsCurrentData.filter(el => el.unreadMessageCount !== 0),
// ...privateTopicsData.filter(el => el.unreadMessageCount !== 0),
// ])
// );
// }
}
}, [
isLoggedIn,
accessTokenInStore,
allTopicsCurrentData,
privateTopicsData,
dispatch,
]);
// }, [isLoggedIn, accessTokenInStore, allTopicsCurrentData, privateTopicsData, dispatch]);
}, [isLoggedIn, accessTokenInStore, dispatch]);
};
2 changes: 1 addition & 1 deletion src/hooks/useWebSocketConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import createClientInstance from '../utils/stompClient';
// import { connectWebSocket } from '../redux/chat-operations';
// import SockJS from 'sockjs-client';
// import { BASE_URL } from '../redux/apiParams';
import { selectAccessToken } from '../redux/authOperatonsToolkit/authOperationsThunkSelectors';
import { selectAccessToken } from '../redux/authOperationsToolkit/authOperationsThunkSelectors';
// import localLogOutUtil from '../utils/localLogOutUtil';

export const useWebSocketConnection = (isLoggedIn) => {
Expand Down
Loading
Loading