You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// we wrap our application with the <Router> tag so that all components that are nested will have the react-router context
22
24
<Router>
25
+
{/* we wrap our MainContainer with the provider so that we will be able to use the store context. We create our store by using useReducer and passing it into the value property */}
Copy file name to clipboardExpand all lines: src/app/containers/MainContainer.tsx
+32-3Lines changed: 32 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -18,17 +18,27 @@ import {
18
18
import{useStoreContext}from'../store';
19
19
20
20
functionMainContainer(): JSX.Element{
21
+
// we destructure the returned context object from the invocation of the useStoreContext function. Properties not found on the initialState object (store/dispatch) are from the useReducer function invocation in the App component
21
22
const[store,dispatch]=useStoreContext();
23
+
// we continue to destructure store and get the tabs/currentTab/port
22
24
const{ tabs, currentTab, port }=store;
25
+
// We create a local state actionView and set it to true
23
26
const[actionView,setActionView]=useState(true);
27
+
24
28
// this function handles Time Jump sidebar view
25
29
consttoggleActionContainer=()=>{
30
+
// sets actionView to the opposite boolean value
26
31
setActionView(!actionView);
32
+
27
33
// aside is like an added text that appears "on the side" aside some text.
28
34
consttoggleElem=document.querySelector('aside');
35
+
// toggles the addition or the removal of the 'no-aside' class
29
36
toggleElem.classList.toggle('no-aside');
37
+
30
38
// hides the record toggle button from Actions Container in Time Jump sidebar view
// switches whether to display the button by changing the display property between none and flex
32
42
if(recordBtn.style.display==='none'){
33
43
recordBtn.style.display='flex';
34
44
}else{
@@ -37,22 +47,35 @@ function MainContainer(): JSX.Element {
37
47
};
38
48
// let port;
39
49
useEffect(()=>{
40
-
// only open port once
50
+
// only open port once so if it exists, do not run useEffect again
41
51
if(port)return;
42
52
43
-
// open long-lived connection with background script
53
+
// chrome.runtime allows our application to retrieve our service worker (our eventual bundles/background.bundle.js after running npm run build), details about the manifest, and allows us to listen and respond to events in our application lifecycle.
54
+
// we connect our listeners to our service worker
44
55
constcurrentPort=chrome.runtime.connect();
56
+
45
57
// listen for a message containing snapshots from the background script
46
58
currentPort.onMessage.addListener(
47
59
// parameter message is an object with following type script properties
0 commit comments