Skip to content

Commit e47f9d4

Browse files
authored
Merge pull request #5 from oslabs-beta/chris/migrate-ErrorContainer
Migrated ErrorContainer to RTK
2 parents ecdb5c1 + fca1797 commit e47f9d4

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/app/RTKslices.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,19 @@ export const mainSlice = createSlice({
202202
tabs[currentTab].playing = false;
203203
tabs[currentTab].intervalId = null;
204204
},
205+
launchContentScript: (state, action) => {
206+
console.log('launchContentScript: ', current(state));
205207

208+
const { tabs, currentTab } = state;
209+
const { port } = tabs[currentTab] || {};
210+
211+
// Fired when user clicks launch button on the error page. Send msg to background to launch
212+
port.postMessage({
213+
action: 'launchContentScript',
214+
payload: action.payload,
215+
tabId: currentTab,
216+
});
217+
},
206218
playForward: (state, action) => {
207219
const {port, tabs, currentTab} = state
208220
const { hierarchy, snapshots, sliderIndex, intervalId } = tabs[currentTab] || {};
@@ -356,7 +368,6 @@ export const mainSlice = createSlice({
356368
tabs[currentTab].currBranch = savedSnapshot.Branch;
357369
tabs[currentTab].seriesSavedStatus = false;
358370
}
359-
360371
},
361372
})
362373

@@ -373,6 +384,7 @@ export const {
373384
changeSlider,
374385
setCurrentTabInApp,
375386
pause,
387+
launchContentScript,
376388
playForward,
377389
startPlaying,
378390
moveForward,

src/app/containers/ErrorContainer.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable max-len */
22
import React, { useState, useEffect, useRef } from 'react';
3-
import { launchContentScript } from '../actions/actions';
3+
import { launchContentScript } from '../RTKslices';
44
import Loader from '../components/Loader';
55
import ErrorMsg from '../components/ErrorMsg';
6-
import { useStoreContext } from '../store';
6+
// import { useStoreContext } from '../store';
7+
import { useDispatch, useSelector } from 'react-redux';
78
/*
89
This is the loading screen that a user may get when first initalizing the application. This page checks:
910
@@ -13,8 +14,10 @@ This is the loading screen that a user may get when first initalizing the applic
1314
*/
1415

1516
function ErrorContainer(): JSX.Element {
16-
const [store, dispatch] = useStoreContext(); // 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
17-
const { tabs, currentTitle, currentTab } = store; // We continue to destructure 'store' and get the 'tabs'/'currentTab'/'port'
17+
const dispatch = useDispatch();
18+
// const [store, dispatch] = useStoreContext(); // 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
19+
const { tabs, currentTitle, currentTab } = useSelector((state: any) => state.main);
20+
// const { tabs, currentTitle, currentTab } = store; // We continue to destructure 'store' and get the 'tabs'/'currentTab'/'port'
1821
const [loadingArray, setLoading] = useState([true, true, true]); // We create a local state "loadingArray" and set it to an array with three true elements. These will be used as hooks for error checking against a 'status' object that is declared later in a few lines. 'loadingArray' is used later in the return statement to display a spinning loader icon if it's true. If it's false, either a checkmark icon or an exclamation icon will be displayed to the user.
1922
const titleTracker = useRef(currentTitle); // useRef returns an object with a property 'initialValue' and a value of whatever was passed in. This allows us to reference a value that's not needed for rendering
2023
const timeout = useRef(null);
@@ -123,4 +126,4 @@ function ErrorContainer(): JSX.Element {
123126
);
124127
}
125128

126-
export default ErrorContainer;
129+
export default ErrorContainer;

0 commit comments

Comments
 (0)