Création/mise à jour basique d'un DAD #15

Manually merged
wpetit merged 7 commits from feature/dad into develop 2020-08-26 14:52:54 +02:00
2 changed files with 37 additions and 1 deletions
Showing only changes of commit f03a0c96dc - Show all commits

View File

@ -1,4 +1,4 @@
import React, { FunctionComponent } from 'react'; import React, { FunctionComponent, useState } from 'react';
import { BrowserRouter, Route, Redirect, Switch } from "react-router-dom"; import { BrowserRouter, Route, Redirect, Switch } from "react-router-dom";
import { HomePage } from './HomePage/HomePage'; import { HomePage } from './HomePage/HomePage';
import { ProfilePage } from './ProfilePage/ProfilePage'; import { ProfilePage } from './ProfilePage/ProfilePage';
@ -8,6 +8,8 @@ import { DashboardPage } from './DashboardPage/DashboardPage';
import { useUserProfile } from '../gql/queries/profile'; import { useUserProfile } from '../gql/queries/profile';
import { LoggedInContext } from '../hooks/useLoggedIn'; import { LoggedInContext } from '../hooks/useLoggedIn';
import { PrivateRoute } from './PrivateRoute'; import { PrivateRoute } from './PrivateRoute';
import { useKonamiCode } from '../hooks/useKonamiCode';
import { Modal } from './Modal';
export interface AppProps { export interface AppProps {
@ -16,6 +18,9 @@ export interface AppProps {
export const App: FunctionComponent<AppProps> = () => { export const App: FunctionComponent<AppProps> = () => {
const { user } = useUserProfile(); const { user } = useUserProfile();
const [ showBoneyM, setShowBoneyM ] = useState(false);
useKonamiCode(() => setShowBoneyM(true));
return ( return (
<LoggedInContext.Provider value={user.id !== ''}> <LoggedInContext.Provider value={user.id !== ''}>
<BrowserRouter> <BrowserRouter>
@ -28,6 +33,17 @@ export const App: FunctionComponent<AppProps> = () => {
<Route component={() => <Redirect to="/" />} /> <Route component={() => <Redirect to="/" />} />
</Switch> </Switch>
</BrowserRouter> </BrowserRouter>
{
showBoneyM ?
<Modal active={true} showCloseButton={true} onClose={() => setShowBoneyM(false)}>
<iframe width={560} height={315}
frameBorder={0}
allowFullScreen={true}
src="https://www.youtube.com/embed/uVzT5QEEQ2c?autoplay=1" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture">
</iframe>
</Modal> :
null
}
</LoggedInContext.Provider> </LoggedInContext.Provider>
); );
} }

View File

@ -0,0 +1,20 @@
import { useEffect } from "react";
export function useKonamiCode(cb: Function) {
const KONAMI_CODE = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
let cursor = 0;
useEffect(()=> {
const onKeyDown = (e) => {
cursor = (e.keyCode == KONAMI_CODE[cursor]) ? cursor + 1 : 0;
if (cursor == KONAMI_CODE.length) {
cb();
cursor = 0;
}
};
document.addEventListener('keydown', onKeyDown);
return () => document.removeEventListener('keydown', onKeyDown);
}, []);
}