From 50afd67455cb1f15cf41e37b711826d5ca839810 Mon Sep 17 00:00:00 2001 From: KostiantynU <115901013+KostiantynU@users.noreply.github.com> Date: Sun, 13 Oct 2024 16:26:04 +0300 Subject: [PATCH] Change logic of handling all notifications array --- src/common/Topics/ChatsBlock/ChatsBlock.jsx | 2 +- src/components/Chat/Chat.jsx | 2 +- .../MessageContainerObserver.jsx | 2 +- .../TopicSettingsMenu/TopicSettingsMenu.jsx | 4 +- .../Chat/UsersAvatar/UsersAvatar.jsx | 2 +- src/components/Layouts/Footer/Footer.jsx | 2 +- src/components/Layouts/Header/Header.jsx | 3 +- .../Header/HeaderUserInfo/HeaderUserInfo.jsx | 2 +- .../LoginPageComponent/LoginPageComponent.jsx | 2 +- src/components/NewTopic/NewTopic.jsx | 2 +- src/components/Routes/PrivateRoute.jsx | 3 +- src/components/Routes/PublicRoute.jsx | 2 +- .../UserSettings/PermissionPrivateMessage.js | 2 +- src/hooks/useAllTopicsNotificationInfo.js | 49 +++-- src/hooks/useWebSocketConnection.js | 2 +- .../authOperationsThunkSelectors.js | 0 .../authOperationsThunkSlice.js | 0 src/redux/chatSlice.js | 189 ++++++++++++++++-- src/redux/messagesAPI/messagesAPI.js | 4 +- src/redux/store.js | 5 +- .../components/SharedLayout/SharedLayout.jsx | 3 +- src/utils/localLogOutUtil.js | 2 +- 22 files changed, 222 insertions(+), 62 deletions(-) rename src/redux/{authOperatonsToolkit => authOperationsToolkit}/authOperationsThunkSelectors.js (100%) rename src/redux/{authOperatonsToolkit => authOperationsToolkit}/authOperationsThunkSlice.js (100%) diff --git a/src/common/Topics/ChatsBlock/ChatsBlock.jsx b/src/common/Topics/ChatsBlock/ChatsBlock.jsx index 5c56bf4..fc7cdac 100644 --- a/src/common/Topics/ChatsBlock/ChatsBlock.jsx +++ b/src/common/Topics/ChatsBlock/ChatsBlock.jsx @@ -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, diff --git a/src/components/Chat/Chat.jsx b/src/components/Chat/Chat.jsx index 1de2325..c6235eb 100644 --- a/src/components/Chat/Chat.jsx +++ b/src/components/Chat/Chat.jsx @@ -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'; diff --git a/src/components/Chat/MessageContainerObserver/MessageContainerObserver.jsx b/src/components/Chat/MessageContainerObserver/MessageContainerObserver.jsx index aefd8ab..597d0c8 100644 --- a/src/components/Chat/MessageContainerObserver/MessageContainerObserver.jsx +++ b/src/components/Chat/MessageContainerObserver/MessageContainerObserver.jsx @@ -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'; diff --git a/src/components/Chat/TopicSettingsMenu/TopicSettingsMenu.jsx b/src/components/Chat/TopicSettingsMenu/TopicSettingsMenu.jsx index 950291b..ff9def1 100644 --- a/src/components/Chat/TopicSettingsMenu/TopicSettingsMenu.jsx +++ b/src/components/Chat/TopicSettingsMenu/TopicSettingsMenu.jsx @@ -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 }) => { diff --git a/src/components/Chat/UsersAvatar/UsersAvatar.jsx b/src/components/Chat/UsersAvatar/UsersAvatar.jsx index 049bbfc..728e3fe 100644 --- a/src/components/Chat/UsersAvatar/UsersAvatar.jsx +++ b/src/components/Chat/UsersAvatar/UsersAvatar.jsx @@ -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'; diff --git a/src/components/Layouts/Footer/Footer.jsx b/src/components/Layouts/Footer/Footer.jsx index 1b1c339..5a499d0 100644 --- a/src/components/Layouts/Footer/Footer.jsx +++ b/src/components/Layouts/Footer/Footer.jsx @@ -8,7 +8,7 @@ import { useDispatch, useSelector } from 'react-redux'; import { selectAccessToken, selectIsLoggedIn, -} from '../../../redux/authOperatonsToolkit/authOperationsThunkSelectors'; +} from '../../../redux/authOperationsToolkit/authOperationsThunkSelectors'; // import { // setAccessToken, // setIsLoggedIn, diff --git a/src/components/Layouts/Header/Header.jsx b/src/components/Layouts/Header/Header.jsx index efef53f..f8e4cf5 100644 --- a/src/components/Layouts/Header/Header.jsx +++ b/src/components/Layouts/Header/Header.jsx @@ -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'; diff --git a/src/components/Layouts/Header/HeaderUserInfo/HeaderUserInfo.jsx b/src/components/Layouts/Header/HeaderUserInfo/HeaderUserInfo.jsx index 0515e86..6b5606f 100644 --- a/src/components/Layouts/Header/HeaderUserInfo/HeaderUserInfo.jsx +++ b/src/components/Layouts/Header/HeaderUserInfo/HeaderUserInfo.jsx @@ -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'; diff --git a/src/components/LoginPageComponent/LoginPageComponent.jsx b/src/components/LoginPageComponent/LoginPageComponent.jsx index be983d9..659eed6 100644 --- a/src/components/LoginPageComponent/LoginPageComponent.jsx +++ b/src/components/LoginPageComponent/LoginPageComponent.jsx @@ -22,7 +22,7 @@ import { setAccessToken, setIsLoggedIn, setRefreshToken, -} from '../../redux/authOperatonsToolkit/authOperationsThunkSlice.js'; +} from '../../redux/authOperationsToolkit/authOperationsThunkSlice.js'; function LoginPageComponent() { const [login] = useLoginMutation(); diff --git a/src/components/NewTopic/NewTopic.jsx b/src/components/NewTopic/NewTopic.jsx index 513596a..dd08d4e 100644 --- a/src/components/NewTopic/NewTopic.jsx +++ b/src/components/NewTopic/NewTopic.jsx @@ -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 = { diff --git a/src/components/Routes/PrivateRoute.jsx b/src/components/Routes/PrivateRoute.jsx index f1c6e54..9742077 100644 --- a/src/components/Routes/PrivateRoute.jsx +++ b/src/components/Routes/PrivateRoute.jsx @@ -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(); diff --git a/src/components/Routes/PublicRoute.jsx b/src/components/Routes/PublicRoute.jsx index e6663f2..be4cdc7 100644 --- a/src/components/Routes/PublicRoute.jsx +++ b/src/components/Routes/PublicRoute.jsx @@ -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'; diff --git a/src/components/SettingsPageComponent/UserSettings/PermissionPrivateMessage.js b/src/components/SettingsPageComponent/UserSettings/PermissionPrivateMessage.js index 12009b2..84b8179 100644 --- a/src/components/SettingsPageComponent/UserSettings/PermissionPrivateMessage.js +++ b/src/components/SettingsPageComponent/UserSettings/PermissionPrivateMessage.js @@ -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); diff --git a/src/hooks/useAllTopicsNotificationInfo.js b/src/hooks/useAllTopicsNotificationInfo.js index 2397b53..56b2cf3 100644 --- a/src/hooks/useAllTopicsNotificationInfo.js +++ b/src/hooks/useAllTopicsNotificationInfo.js @@ -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]); }; diff --git a/src/hooks/useWebSocketConnection.js b/src/hooks/useWebSocketConnection.js index f6de0aa..ba5e6f3 100644 --- a/src/hooks/useWebSocketConnection.js +++ b/src/hooks/useWebSocketConnection.js @@ -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) => { diff --git a/src/redux/authOperatonsToolkit/authOperationsThunkSelectors.js b/src/redux/authOperationsToolkit/authOperationsThunkSelectors.js similarity index 100% rename from src/redux/authOperatonsToolkit/authOperationsThunkSelectors.js rename to src/redux/authOperationsToolkit/authOperationsThunkSelectors.js diff --git a/src/redux/authOperatonsToolkit/authOperationsThunkSlice.js b/src/redux/authOperationsToolkit/authOperationsThunkSlice.js similarity index 100% rename from src/redux/authOperatonsToolkit/authOperationsThunkSlice.js rename to src/redux/authOperationsToolkit/authOperationsThunkSlice.js diff --git a/src/redux/chatSlice.js b/src/redux/chatSlice.js index 523d6f1..48da634 100644 --- a/src/redux/chatSlice.js +++ b/src/redux/chatSlice.js @@ -1,12 +1,13 @@ -import { createSlice } from '@reduxjs/toolkit'; +import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'; import { createSelector } from 'reselect'; +import { BASE_URL } from './apiParams'; -const whenStateArrLengthMore = (stateArr, actionPayload) => { +const whenStateArrLengthMore = (stateArr, actionPayloadArray) => { return stateArr.reduce((acuum, el) => { - if (actionPayload.find((payloadEl) => payloadEl.id === el.id)) { + if (actionPayloadArray.find((payloadEl) => payloadEl.id === el.id)) { return [ ...acuum, - actionPayload.find((payloadEl) => payloadEl.id === el.id), + actionPayloadArray.find((payloadEl) => payloadEl.id === el.id), ]; } else { return [...acuum, el]; @@ -14,10 +15,35 @@ const whenStateArrLengthMore = (stateArr, actionPayload) => { }, []); }; +const handleAllNotificationsArray = (stateArr, actionPayloadArray) => { + if (!stateArr.length) { + return [...actionPayloadArray.filter((el) => el.unreadMessageCount !== 0)]; + } else if (stateArr.length >= actionPayloadArray.length) { + return whenStateArrLengthMore( + stateArr, + actionPayloadArray.filter((el) => el.unreadMessageCount !== 0), + ); + } else { + return actionPayloadArray + .filter((el) => el.unreadMessageCount !== 0) + .reduce((acuum, el) => { + if (stateArr.find((stateEl) => stateEl.id === el.id)) { + return [ + ...acuum, + actionPayloadArray.find((payloadEl) => payloadEl.id === el.id), + ]; + } else { + return [...acuum, el]; + } + }, []); + } +}; + const chatSlice = createSlice({ name: 'chat', initialState: { notificationsAllTopics: [], + notificationsAllTopicsStatus: '', subscribedAllTopicsNotify: false, subscriptionAllTopicsNotify: [], messages: [], @@ -50,19 +76,16 @@ const chatSlice = createSlice({ action.payload, ); } else { - state.notificationsAllTopics = state.action.payload.reduce( - (acuum, el) => { - if (action.payload.find((payloadEl) => payloadEl.id === el.id)) { - return [ - ...acuum, - action.payload.find((payloadEl) => payloadEl.id === el.id), - ]; - } else { - return [...acuum, el]; - } - }, - [], - ); + state.notificationsAllTopics = action.payload.reduce((acuum, el) => { + if (action.payload.find((payloadEl) => payloadEl.id === el.id)) { + return [ + ...acuum, + action.payload.find((payloadEl) => payloadEl.id === el.id), + ]; + } else { + return [...acuum, el]; + } + }, []); } }, setAllTopicsNotificationsWS: (state, action) => { @@ -149,6 +172,106 @@ const chatSlice = createSlice({ state.usersStatusOnlineTyping = []; }, }, + extraReducers(builder) { + builder + .addCase(fetchNotificationsAllTopics.pending, (state) => { + state.notificationsAllTopicsStatus = 'pending'; + }) + .addCase(fetchNotificationsAllTopics.fulfilled, (state, action) => { + // if (action.payload.httpStatus === 'UNAUTHORIZED') { + // return { + // ...state, + // notificationsAllTopics: [], + // notificationsAllTopicsStatus: 'UNAUTHORIZED', + // }; + // } + + // state.notificationsAllTopics = [ + // ...state.notificationsAllTopics, + // ...action.payload.filter(el => el.unreadMessageCount !== 0), + // ]; + state.notificationsAllTopics = handleAllNotificationsArray( + state.notificationsAllTopics, + action.payload, + ); + + // if (!state.notificationsAllTopics.length) { + // state.notificationsAllTopics = [ + // ...action.payload.filter(el => el.unreadMessageCount !== 0), + // ]; + // } else if (state.notificationsAllTopics.length >= action.payload.length) { + // state.notificationsAllTopics = whenStateArrLengthMore( + // state.notificationsAllTopics, + // action.payload.filter(el => el.unreadMessageCount !== 0) + // ); + // } else { + // state.notificationsAllTopics = action.payload + // .filter(el => el.unreadMessageCount !== 0) + // .reduce((acuum, el) => { + // if (action.payload.find(payloadEl => payloadEl.id === el.id)) { + // return [...acuum, action.payload.find(payloadEl => payloadEl.id === el.id)]; + // } else { + // return [...acuum, el]; + // } + // }, []); + // } + + state.notificationsAllTopicsStatus = 'successfull'; + }) + .addCase(fetchNotificationsAllTopics.rejected, (state, action) => { + state.notificationsAllTopics = []; + state.notificationsAllTopicsStatus = action.error; + }) + .addCase(fetchNotificationsPrivateTopics.pending, (state) => { + state.notificationsAllTopicsStatus = 'pending'; + }) + .addCase(fetchNotificationsPrivateTopics.fulfilled, (state, action) => { + // if (action.payload.httpStatus === 'UNAUTHORIZED') { + // return { + // ...state, + // notificationsAllTopics: [], + // notificationsAllTopicsStatus: 'UNAUTHORIZED', + // }; + // } + + // state.notificationsAllTopics = [ + // ...state.notificationsAllTopics, + // ...action.payload.filter(el => el.unreadMessageCount !== 0), + // ]; + + state.notificationsAllTopics = handleAllNotificationsArray( + state.notificationsAllTopics, + action.payload, + ); + + // if (!state.notificationsAllTopics.length) { + // state.notificationsAllTopics = [ + // ...action.payload.filter(el => el.unreadMessageCount !== 0), + // ]; + // } else if (state.notificationsAllTopics.length >= action.payload.length) { + // state.notificationsAllTopics = whenStateArrLengthMore( + // state.notificationsAllTopics, + // action.payload.filter(el => el.unreadMessageCount !== 0) + // ); + // } else { + // state.notificationsAllTopics = action.payload + // .filter(el => el.unreadMessageCount !== 0) + // .reduce((acuum, el) => { + // if (action.payload.find(payloadEl => payloadEl.id === el.id)) { + // return [...acuum, action.payload.find(payloadEl => payloadEl.id === el.id)]; + // } else { + // return [...acuum, el]; + // } + // }, []); + // } + + state.notificationsAllTopicsStatus = 'successfull'; + }) + .addCase(fetchNotificationsPrivateTopics.rejected, (state, action) => { + state.notificationsAllTopics = []; + state.notificationsAllTopicsStatus = action.error; + }); + }, }); export const { @@ -256,3 +379,35 @@ export const selectUsersStatusOnlineTyping = createSelector( selectChatState, (chat) => chat.usersStatusOnlineTyping, ); + +export const fetchNotificationsAllTopics = createAsyncThunk( + 'fetchNotificationsAll', + async (accessTokenInStore) => { + const response = await fetch(`${BASE_URL}/topics/all`, { + headers: { + Authorization: `Bearer ${accessTokenInStore}`, + 'Content-type': 'application/json', + }, + }) + .then((response) => response.json()) + .then((result) => result); + + return response; + }, +); + +export const fetchNotificationsPrivateTopics = createAsyncThunk( + 'fetchNotificationsPrivate', + async (accessTokenInStore) => { + const response = await fetch(`${BASE_URL}/topics/private`, { + headers: { + Authorization: `Bearer ${accessTokenInStore}`, + 'Content-type': 'application/json', + }, + }) + .then((response) => response.json()) + .then((result) => result); + + return response; + }, +); diff --git a/src/redux/messagesAPI/messagesAPI.js b/src/redux/messagesAPI/messagesAPI.js index c115960..f1d2321 100644 --- a/src/redux/messagesAPI/messagesAPI.js +++ b/src/redux/messagesAPI/messagesAPI.js @@ -1,7 +1,7 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; import { BASE_URL, Referer } from '../apiParams'; -export const messagesAPI = createApi({ +const messagesAPI = createApi({ reducerPath: 'messagesSlice', baseQuery: fetchBaseQuery({ baseUrl: `${BASE_URL}` }), tagTypes: ['messages'], @@ -74,3 +74,5 @@ export const { useSendMessageToNewTopicMutation, useSetMessageStatusMutation, } = messagesAPI; + +export default messagesAPI; diff --git a/src/redux/store.js b/src/redux/store.js index 2493f54..023ddc5 100644 --- a/src/redux/store.js +++ b/src/redux/store.js @@ -6,13 +6,14 @@ import topicsApi from './topics-operations'; import userApi from './user-operations'; import userInfoSlice from './userSlice'; import chatSlice from './chatSlice'; -import authOperationsThunk from './authOperatonsToolkit/authOperationsThunkSlice'; -import { messagesAPI } from './messagesAPI/messagesAPI'; +import authOperationsThunk from './authOperationsToolkit/authOperationsThunkSlice'; +import messagesAPI from './messagesAPI/messagesAPI'; const store = configureStore({ reducer: { [authenticationApi.reducerPath]: authenticationApi.reducer, [topicsApi.reducerPath]: topicsApi.reducer, + [userApi.reducerPath]: userApi.reducer, [userInfoSlice.name]: userInfoSlice.reducer, [chatSlice.name]: chatSlice.reducer, diff --git a/src/ui-kit/components/SharedLayout/SharedLayout.jsx b/src/ui-kit/components/SharedLayout/SharedLayout.jsx index ff712ad..e8e61f6 100644 --- a/src/ui-kit/components/SharedLayout/SharedLayout.jsx +++ b/src/ui-kit/components/SharedLayout/SharedLayout.jsx @@ -8,7 +8,8 @@ import { useWebSocketConnection } from '../../../hooks/useWebSocketConnection'; import { useSubscriptionToAllTopicsNotify } from '../../../hooks/useSubscriptionToAllTopicsNotify'; import { MainWrapper } from './SharedLayout.styled'; import { useSelector } from 'react-redux'; -import { selectIsLoggedIn } from '../../../redux/authOperatonsToolkit/authOperationsThunkSelectors'; +// eslint-disable-next-line max-len +import { selectIsLoggedIn } from '../../../redux/authOperationsToolkit/authOperationsThunkSelectors'; import { useAllTopicsNotificationInfo } from '../../../hooks/useAllTopicsNotificationInfo'; // import { useGetUserInfoQuery } from '../../../redux/user-operations'; // import { useEffect } from 'react'; diff --git a/src/utils/localLogOutUtil.js b/src/utils/localLogOutUtil.js index 46bbd12..924a726 100644 --- a/src/utils/localLogOutUtil.js +++ b/src/utils/localLogOutUtil.js @@ -2,7 +2,7 @@ import { setAccessToken, setIsLoggedIn, setRefreshToken, -} from '../redux/authOperatonsToolkit/authOperationsThunkSlice'; +} from '../redux/authOperationsToolkit/authOperationsThunkSlice'; // import { disconnectWebSocket } from '../redux/chat-operations'; import { client,