From 729d83ae6acf97117be1fad4e9877c45be418ca0 Mon Sep 17 00:00:00 2001 From: Raman Tehlan Date: Tue, 15 Dec 2020 03:25:23 +0530 Subject: [PATCH] Add all reducers/actions --- applications/web/pages/p/index.tsx | 38 ++++---- applications/web/redux/actions.ts | 137 ++++++++++++++++++++--------- applications/web/redux/reducers.ts | 62 +++++++------ 3 files changed, 153 insertions(+), 84 deletions(-) diff --git a/applications/web/pages/p/index.tsx b/applications/web/pages/p/index.tsx index b80491d7a0..1ad64328b3 100644 --- a/applications/web/pages/p/index.tsx +++ b/applications/web/pages/p/index.tsx @@ -15,7 +15,12 @@ import { stringifyNotebook } from "@nteract/commutable"; const CodeMirrorEditor = dynamic(() => import('@nteract/editor'), { ssr: false }); // User defined -import { toggleBinderMenu, toggleConsole } from "../../redux/actions" +import { + toggleBinderMenu, + toggleConsole, + toggleSaveDialog, + updateLoggedIn +} from "../../redux/actions" import { Menu, MenuItem } from '../../components/Menu' import { Button } from '../../components/Button' import { Console } from '../../components/Console' @@ -38,7 +43,12 @@ const Binder = dynamic(() => import("../../components/Binder"), { const BINDER_URL = "https://mybinder.org"; export interface ComponentProps extends HTMLAttributes { - router: NextRouter + router: NextRouter, + toggleBinderMenu: () => {}, + toggleConsole: () => {}, + toggleSaveDialog: () => {} + updateLoggedIn: () => {} + } export interface StateProps { @@ -53,8 +63,6 @@ type Props = ComponentProps & StateProps; **************************/ export const Main: FC = (props: Props) => { const router = useRouter() - // Toggle Values - const [showSaveDialog, setShowSaveDialog] = useState(false) // Git API Values const [filePath, setFilepath] = useState(router.query.file as string) const [fileContent, setFileContent] = useState("") @@ -80,12 +88,10 @@ export const Main: FC = (props: Props) => { const [host, setHost] = useState() // Login Values - const [loggedIn, setLoggedIn] = useState(false) const [username, setUsername] = useState("") const [userImage, setUserImage] = useState("") const [userLink, setUserLink] = useState("") - /*************************************** Notification and Console functions ****************************************/ @@ -171,7 +177,7 @@ export const Main: FC = (props: Props) => { } function showSave() { - toggle(showSaveDialog, setShowSaveDialog) + props.toggleSaveDialog() } @@ -319,7 +325,7 @@ export const Main: FC = (props: Props) => { .then((res) => res.json()) .then((data) => { if (data["login"] !== undefined) { - setLoggedIn(true) + props.updateLoggedIn(true) setUsername(data["login"]) setUserLink(data["html_url"]) setUserImage(data["avatar_url"]) @@ -331,7 +337,7 @@ export const Main: FC = (props: Props) => { } else { localStorage.removeItem("token") - setLoggedIn(false) + props.updateLoggedIn(false) addLog({ type: "failure", message: `Github token expired. User logged out.` @@ -451,9 +457,9 @@ export const Main: FC = (props: Props) => { } - {showSaveDialog && + {props.globalState.showSaveDialog && <> - toggle(showSaveDialog, setShowSaveDialog)} /> + props.toggleSaveDialog()} />
onSave(e)} > You are about to commit to {username}/{repo}[{gitRef}] as @{username}. @@ -480,7 +486,7 @@ export const Main: FC = (props: Props) => {