All files / js App.tsx

87.5% Statements 7/8
75% Branches 3/4
100% Functions 3/3
85.71% Lines 6/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                      15x         37x   36x   36x       6x                                   15x      
import React, {useEffect, useState} from "react";
import ReactDOM from "react-dom";
import { BrowserRouter, Switch, Route } from "react-router-dom";
 
import GameView from "./widgets/GameView";
import Profile, {User} from "./widgets/Profile";
import Ai from "./widgets/Ai";
import NavBar from "./NavBar";
import AuthService from "./auth/AuthService";
 
// make sure to use https, otherwise the copy to clipboard will not work
Iif (location.protocol !== 'https:' && location.hostname !== "localhost") {
    location.href = location.href.replace("http://", "https://");
}
 
function App() {
    const [currentUser, setCurrentUser] = useState<User|undefined>(undefined);
 
    useEffect(() => setCurrentUser(AuthService.getCurrentUser()), [])
 
    return(
        <BrowserRouter>
            <NavBar
                section={"MultiJSnake"}
                onUserChange={() => setCurrentUser(AuthService.getCurrentUser())}
                currentUser={currentUser}
            />
            <Switch>
                {/*@skip-for-static-start*/}
                <Route exact path={["/", "/game"]}>
                    <GameView
                        currentUser={currentUser}
                    />
                </Route>
                <Route exact path={["/profile"]} component={Profile} />
                {/*@skip-for-static-end*/}
                <Route exact path={["/ai"]} component={Ai} />
            </Switch>
        </BrowserRouter>
    )
}
 
ReactDOM.render(
    <App />,
    document.getElementById('react')
)