import React, { useEffect } from 'react'
import Login from './components/login/Login'
import {useStateProvider} from './util/StateProvider'
import { reducerCases } from './util/Constants'
import Home from './components/home/Home'

const App = () => {
  const [{token}, dispatch] = useStateProvider()
  useEffect(() => {
    const hash = window.location.hash;
    if(hash){
      const token = hash.substring(1).split("&")[0].split("=")[1];
      dispatch({type:reducerCases.SET_TOKEN, token})
    }
  }, [token, dispatch]);


  return (
    <div>
      {
        token?  <Home/> : <Login/>
      }
      
    </div>
  )
}

export default App
