From 7c60153c21a373f7d2dd533e272b8b27885976b2 Mon Sep 17 00:00:00 2001 From: Nuwan Chathuranga Date: Tue, 14 Sep 2021 22:47:31 +0530 Subject: [PATCH] adding redux toolkit for state management --- jam-ui/src/App.js | 10 +- jam-ui/src/Main.js | 6 +- jam-ui/src/components/navbar/NavbarTop.js | 2 +- .../src/components/profile/JKMessageModal.js | 125 ++++++++++++------ .../src/store/features/textMessagesSlice.js | 89 +++++++++++++ jam-ui/src/store/store.js | 8 ++ ruby/lib/jam_ruby/models/notification.rb | 4 +- web/app/views/api_text_messages/index.rabl | 8 +- 8 files changed, 201 insertions(+), 51 deletions(-) create mode 100644 jam-ui/src/store/features/textMessagesSlice.js create mode 100644 jam-ui/src/store/store.js diff --git a/jam-ui/src/App.js b/jam-ui/src/App.js index 0e4a11df1..c89603aa9 100644 --- a/jam-ui/src/App.js +++ b/jam-ui/src/App.js @@ -8,6 +8,9 @@ import 'react-image-lightbox/style.css'; import useScript from './hooks/useScript'; +import { useDispatch } from "react-redux"; +//import { addMessage } from "./store/features/textMessagesSlice" + const App = () => { function initJKScripts() { @@ -38,13 +41,18 @@ const App = () => { function registerTextMessageCallback(){ window.JK.JamServer.registerMessageCallback(window.JK.MessageType.TEXT_MESSAGE, function(header, payload) { - console.log('Handling CHAT_MESSAGE msg ' + JSON.stringify(payload)); + console.log('Handling TEXT_MESSAGE ' + JSON.stringify(payload)); // chatMessageReceived(payload); // context.ChatActions.msgReceived(payload); // handledNotification(payload); + + //dispatch(addMessage()) + }); } + const dispatch = useDispatch() + useScript(`${process.env.REACT_APP_LEGACY_BASE_URL}/client_scripts`, initJKScripts); return ( diff --git a/jam-ui/src/Main.js b/jam-ui/src/Main.js index 012569208..c16ef7cce 100644 --- a/jam-ui/src/Main.js +++ b/jam-ui/src/Main.js @@ -5,6 +5,8 @@ import { AuthProvider } from "./context/AuthContext"; import { settings } from './config'; import toggleStylesheet from './helpers/toggleStylesheet'; import { getItemFromStore, setItemToStore, themeColors } from './helpers/utils'; +import store from './store/store'; +import { Provider } from 'react-redux'; const Main = props => { const [isFluid, setIsFluid] = useState(getItemFromStore('isFluid', settings.isFluid)); @@ -117,7 +119,9 @@ const Main = props => { return - {props.children} + + {props.children} + ; }; diff --git a/jam-ui/src/components/navbar/NavbarTop.js b/jam-ui/src/components/navbar/NavbarTop.js index fc0fac8dc..85ea674b5 100644 --- a/jam-ui/src/components/navbar/NavbarTop.js +++ b/jam-ui/src/components/navbar/NavbarTop.js @@ -45,7 +45,7 @@ const NavbarTop = () => { -