diff --git a/dark-mode/src/common/containers/App.js b/dark-mode/src/common/containers/App.js
index 7b58de6de..3a6164f95 100644
--- a/dark-mode/src/common/containers/App.js
+++ b/dark-mode/src/common/containers/App.js
@@ -1,5 +1,32 @@
-import React from 'react';
+import React, { useContext, useReducer, useLayoutEffect } from 'react';
+import ThemeContext from '../../context';
+
+import themeReducer from '../../reducer';
+
+const DARK_MODE_CLASS = 'dark-mode';
export default function App({ children }) {
- return children;
+ const initialState = useContext(ThemeContext);
+ const [state, dispatch] = useReducer(themeReducer, initialState);
+
+ const {
+ theme,
+ } = state;
+
+ useLayoutEffect(() => {
+ switch (theme) {
+ case 'dark':
+ document.getElementById('root').classList.add(DARK_MODE_CLASS);
+ break;
+ default:
+ document.getElementById('root').classList.remove(DARK_MODE_CLASS);
+ break;
+ }
+ }, [theme]);
+
+ return (
+
+ {children}
+
+ )
}
diff --git a/dark-mode/src/context.js b/dark-mode/src/context.js
new file mode 100644
index 000000000..eea48e75c
--- /dev/null
+++ b/dark-mode/src/context.js
@@ -0,0 +1,7 @@
+import React from 'react';
+
+const initialState = {theme: 'light'};
+
+const ThemeContext = React.createContext(initialState);
+
+export default ThemeContext;
\ No newline at end of file
diff --git a/dark-mode/src/reducer.js b/dark-mode/src/reducer.js
new file mode 100644
index 000000000..f0b5ec7e5
--- /dev/null
+++ b/dark-mode/src/reducer.js
@@ -0,0 +1,15 @@
+const initialState = {
+ theme: 'light',
+};
+
+export default function themeReducer({theme}, action) {
+ switch (action.type) {
+ case "SET_THEME":
+ return {
+ theme: theme === 'light' ? 'dark' : 'light',
+ };
+
+ default:
+ return initialState;
+ }
+}
diff --git a/dark-mode/src/routes/App/components/App.js b/dark-mode/src/routes/App/components/App.js
index f69fd1260..d2ffda5be 100644
--- a/dark-mode/src/routes/App/components/App.js
+++ b/dark-mode/src/routes/App/components/App.js
@@ -1,9 +1,33 @@
-import React from 'react';
+import React, { useContext } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { faMoon } from '@fortawesome/free-solid-svg-icons';
+import { faMoon, faSun } from '@fortawesome/free-solid-svg-icons';
import '../styles/_app.scss';
+import ThemeContext from '../../../context';
+
+const themeMap = {
+ dark: {
+ color: '#FFA500',
+ iconType: faSun,
+ },
+ light: {
+ color: null,
+ iconType: faMoon,
+ }
+}
+
+
function App() {
+ const {dispatch, state} = useContext(ThemeContext);
+
+ const {
+ theme,
+ } = state;
+
+ const handleThemePicker = () => {
+ dispatch({type: "SET_THEME"})
+ }
+
return (
@@ -12,8 +36,11 @@ function App() {
{/* --The button that should toggle dark mode-- */}
-
diff --git a/rocket-ship/src/routes/LaunchPad/components/LaunchPad.js b/rocket-ship/src/routes/LaunchPad/components/LaunchPad.js
index c6d12c59a..93dadf684 100644
--- a/rocket-ship/src/routes/LaunchPad/components/LaunchPad.js
+++ b/rocket-ship/src/routes/LaunchPad/components/LaunchPad.js
@@ -1,13 +1,27 @@
-import React, { useState } from 'react';
+import React, { useState, useLayoutEffect } from 'react';
import '../styles/_launchpad.scss';
export default function LaunchPad({Rocket}) {
const [rerenderCount, triggerRerender] = useState(0);
- setTimeout(() => { triggerRerender(rerenderCount + 1); }, 500);
+ const [start, setStart] = useState(false);
+ useLayoutEffect(() => {
+ if (rerenderCount < 10) {
+ setTimeout(() => { triggerRerender(rerenderCount + 1); }, 500);
+ }
+ }, [rerenderCount])
+
+ function handleLaunch() {
+ setStart(true);
+ if (rerenderCount >= 10) {
+ triggerRerender(0);
+ }
+ }
+
return (
-
+ Launch
+
);
-}
+}
\ No newline at end of file
diff --git a/rocket-ship/src/routes/LaunchPad/components/Rocket/components/Rocket.js b/rocket-ship/src/routes/LaunchPad/components/Rocket/components/Rocket.js
index ff104115c..125fcf5b8 100644
--- a/rocket-ship/src/routes/LaunchPad/components/Rocket/components/Rocket.js
+++ b/rocket-ship/src/routes/LaunchPad/components/Rocket/components/Rocket.js
@@ -1,9 +1,15 @@
import React, { useState, Component } from 'react';
import RocketCore from './RocketCore';
-export function FunctionalRocket() {
- const [initialLaunchTime] = useState(Date.now());
-
+export function FunctionalRocket({start}) {
+ const [initialLaunchTime, setInitialLaunchTime] = useState(Date.now());
+
+ React.useLayoutEffect(() => {
+ if(start) {
+ setInitialLaunchTime(Date.now());
+ }
+ }, [start])
+
return ;
}
diff --git a/rocket-ship/src/routes/LaunchPad/components/Rocket/components/RocketCore.js b/rocket-ship/src/routes/LaunchPad/components/Rocket/components/RocketCore.js
index 23032e213..9b7c212b9 100644
--- a/rocket-ship/src/routes/LaunchPad/components/Rocket/components/RocketCore.js
+++ b/rocket-ship/src/routes/LaunchPad/components/Rocket/components/RocketCore.js
@@ -8,14 +8,14 @@ const FINAL_POSITION_BOTTOM_VAL = 'calc(400px)';
function timeToPositionPercent(startTime) {
const now = Date.now();
const timeDiff = now - startTime;
-
+
if (timeDiff >= MS_TO_TAKEOFF) { return FINAL_POSITION_BOTTOM_VAL; }
return `calc(300px + ${((timeDiff / MS_TO_TAKEOFF) * 100).toFixed(0)}%)`;
}
function generateEmptyListEls(quantity) {
- return [...Array(quantity)].map(() => );
+ return [...Array(quantity)].map((q, index) => );
}
export default function RocketCore({ initialLaunchTime }) {