<commit_before>import "./App.css";
import React, { useState, useEffect } from "react";
import { BrowserRouter } from "react-router-dom";

import HeaderBar from "./components/HeaderBar/HeaderBar";
import Layout from "./hoc/Layout/Layout";
import PageRouter from "./hoc/PageRouter/PageRouter";

import { AuthContext } from "./context/AuthContext";
import { onAuthStateChange } from "./services/firebase";

export const NO_COMPETITION = 0;

function App() {
  const [user, setUser] = useState({ signedIn: false });
  const [authStateReceived, setAuthStateReceived] = useState(false);
  const [compId, setCompId] = useState(0);
  const [competitionInfo, setCompetitionInfo] = useState({});
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    const unsubscribe = onAuthStateChange((userData) => {
      setUser(userData);
      setAuthStateReceived(true);
    });

    return () => {
      unsubscribe();
    };
  }, []);

  useEffect(() => {
    const parsedCompId = Number(localStorage.getItem("compId") || 0);
    setCompId(parsedCompId);
  }, []);

  const fetchCompetitionInfo = async (fetchCall, stateKey) => {
    try {
      const data = await fetch(fetchCall).then((response) => response.json());

      return {
        [stateKey]: data,
      };
    } catch (e) {
      return {
        [stateKey]: undefined,
      };
    }
  };

  const isReadyForDataFetch = () => {
    if (!user.signedIn) {
      return false;
    }
    if (user.id === undefined) {
      return false;
    }
    if (compId === 0) {
      return false;
    }
    return true;
  };

  useEffect(() => {
    if (!authStateReceived) {
      return;
    }

    if (isReadyForDataFetch()) {
      setLoading(true);
      Promise.all([
        fetchCompetitionInfo(
          `./competitionInfo?user=${user.id}&competition=${compId}`,
          "generalInfo"
        ),
        fetchCompetitionInfo(
          `./recentBuys?competition=${compId}`,
          "recentBuys"
        ),
        fetchCompetitionInfo(
          `./investments?user=${user.id}&competition=${compId}`,
          "investments"
        ),
        fetchCompetitionInfo("./trending", "trending"),
      ]).then((resolvedData) => {
        setLoading(false);
        console.log(resolvedData);
        console.log(competitionInfo);
        let newCompInfo = {};
        for (const response of resolvedData) {
          newCompInfo = {
            ...newCompInfo,
            ...response,
          };
        }
        setCompetitionInfo(newCompInfo);
      });
    }
  }, [user.id, authStateReceived]);

  let pageRoute = (
    <PageRouter
      signedIn={user.signedIn}
      compId={compId}
      loading={loading}
      compIdChanged={setCompId}
      competitionInfo={competitionInfo}
      updateCompId={setCompId}
    />
  );

  // !user.signedIn ? (
  //   <Switch>
  //     <Route path="/signin" component={LandingPage} />
  //     <Redirect to="/signin" />
  //   </Switch>
  // ) : compId == NO_COMPETITION ? (
  //   <Switch>
  //     <Route
  //       path="/compselect"
  //       render={(props) => (
  //         <SelectCompetition {...props} compIdChanged={setCompId} />
  //       )}
  //     />
  //     <Redirect to="/compselect" />
  //   </Switch>
  // ) : !competitionInfo.generalInfo || loading ? (
  //   <div>Loading...</div>
  // ) : (
  //   <Switch>
  //     <Route
  //       path="/dashboard"
  //       render={() => (
  //         <Dashboard
  //           generalInfo={competitionInfo.generalInfo}
  //           recentBuys={competitionInfo.recentBuys}
  //           trendingSearches={competitionInfo.trending}
  //           investments={competitionInfo.investments}
  //         />
  //       )}
  //     />
  //     <Route path="/competition" render={() => <Competition />} />
  //     <Route
  //       path="/mysgonks"
  //       render={() => (
  //         <MySGonks
  //           generalInfo={competitionInfo.generalInfo}
  //           investments={competitionInfo.investments}
  //         />
  //       )}
  //     />
  //     <Route
  //       path="/marketplace"
  //       render={() => (
  //         <Marketplace
  //           generalInfo={competitionInfo.generalInfo}
  //           recentBuys={competitionInfo.recentBuys}
  //           trendingSearches={competitionInfo.trending}
  //           investments={competitionInfo.investments}
  //         />
  //       )}
  //     />
  //     <Route path="/placeholder" component={Explanation} />
  //     <Redirect to="/dashboard" />
  //   </Switch>
  // );

  return (
    <BrowserRouter>
      <div className="App">
        <AuthContext>
          <HeaderBar
            loggedIn={user.signedIn}
            innerNav={compId != 0}
            compIdChanged={setCompId}
          />
          {!authStateReceived ? (
            <div>Signing in...</div>
          ) : (
            <Layout>{pageRoute}</Layout>
          )}
        </AuthContext><commit_msg>Delete obselete code<commit_after>import "./App.css";
import React, { useState, useEffect } from "react";
import { BrowserRouter } from "react-router-dom";

import HeaderBar from "./components/HeaderBar/HeaderBar";
import Layout from "./hoc/Layout/Layout";
import PageRouter from "./hoc/PageRouter/PageRouter";

import { AuthContext } from "./context/AuthContext";
import { onAuthStateChange } from "./services/firebase";

export const NO_COMPETITION = 0;

function App() {
  const [user, setUser] = useState({ signedIn: false });
  const [authStateReceived, setAuthStateReceived] = useState(false);
  const [compId, setCompId] = useState(0);
  const [competitionInfo, setCompetitionInfo] = useState({});
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    const unsubscribe = onAuthStateChange((userData) => {
      setUser(userData);
      setAuthStateReceived(true);
    });

    return () => {
      unsubscribe();
    };
  }, []);

  useEffect(() => {
    const parsedCompId = Number(localStorage.getItem("compId") || 0);
    setCompId(parsedCompId);
  }, []);

  const fetchCompetitionInfo = async (fetchCall, stateKey) => {
    try {
      const data = await fetch(fetchCall).then((response) => response.json());

      return {
        [stateKey]: data,
      };
    } catch (e) {
      return {
        [stateKey]: undefined,
      };
    }
  };

  const isReadyForDataFetch = () => {
    if (!user.signedIn) {
      return false;
    }
    if (user.id === undefined) {
      return false;
    }
    if (compId === 0) {
      return false;
    }
    return true;
  };

  useEffect(() => {
    if (!authStateReceived) {
      return;
    }

    if (isReadyForDataFetch()) {
      setLoading(true);
      Promise.all([
        fetchCompetitionInfo(
          `./competitionInfo?user=${user.id}&competition=${compId}`,
          "generalInfo"
        ),
        fetchCompetitionInfo(
          `./recentBuys?competition=${compId}`,
          "recentBuys"
        ),
        fetchCompetitionInfo(
          `./investments?user=${user.id}&competition=${compId}`,
          "investments"
        ),
        fetchCompetitionInfo("./trending", "trending"),
      ]).then((resolvedData) => {
        setLoading(false);
        console.log(resolvedData);
        console.log(competitionInfo);
        let newCompInfo = {};
        for (const response of resolvedData) {
          newCompInfo = {
            ...newCompInfo,
            ...response,
          };
        }
        setCompetitionInfo(newCompInfo);
      });
    }
  }, [user.id, authStateReceived]);

  let pageRoute = (
    <PageRouter
      signedIn={user.signedIn}
      compId={compId}
      loading={loading}
      compIdChanged={setCompId}
      competitionInfo={competitionInfo}
      updateCompId={setCompId}
    />
  );

  return (
    <BrowserRouter>
      <div className="App">
        <AuthContext>
          <HeaderBar
            loggedIn={user.signedIn}
            innerNav={compId != 0}
            compIdChanged={setCompId}
          />
          {!authStateReceived ? (
            <div>Signing in...</div>
          ) : (
            <Layout>{pageRoute}</Layout>
          )}
        </AuthContext>
{'fraction_non_alphanumeric': 0.1567228441382704, 'fraction_numerical': 0.0012301636117603642, 'mean_word_length': 2.072562358276644, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2105043', 'n_tokens_mistral': 2479, 'n_tokens_neox': 2436, 'n_words': 399}