diff --git a/src/App.tsx b/src/App.tsx index 399d4d1..ca1b050 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,15 +1,18 @@ -import './App.css'; -//import MailboxList from './Mailbox'; -import React, { useEffect, useState } from 'react' +import "./App.css"; +import 'bootstrap/dist/css/bootstrap.min.css'; + +//import MailboxList from "./Mailbox"; +import AuthModal from "./AuthModal"; +import React, { useEffect, useState } from "react" -interface IUser { - name: string; - id: string; +interface IAuth { + password: string; + username: string; } const App = () => { - const [users, setUsers] = useState>([]) + const [state, setInternalState] = useState(null) const fetchUserData = () => { fetch("https://jsonplaceholder.typicode.com/users") @@ -17,23 +20,30 @@ const App = () => { return response.json() }) .then(data => { - setUsers(data) + //setUsers(data) }) } + const loadAuth = () => { + const auth = localStorage.getItem("auth") + if (!auth) return; + setInternalState(JSON.parse(auth)) + } + + const setState = (auth: IAuth) => { + localStorage.setItem("auth", JSON.stringify(auth)) + } + useEffect(() => { - fetchUserData() + loadAuth() + //fetchUserData() }, []) return (
- {users.length > 0 && ( -
    - {users.map(user => ( -
  • {user.name}
  • - ))} -
- )} + {state ? +

{state.username}

: + }
); }