2024-08-27 09:28:24 -07:00
|
|
|
import "./App.css";
|
2024-08-27 09:39:28 -07:00
|
|
|
import "bootstrap/dist/css/bootstrap.min.css";
|
2024-08-26 16:07:43 -07:00
|
|
|
|
2024-08-27 09:28:24 -07:00
|
|
|
//import MailboxList from "./Mailbox";
|
|
|
|
import AuthModal from "./AuthModal";
|
2024-08-27 09:39:28 -07:00
|
|
|
import React, { useEffect, useState } from "react";
|
2024-08-27 09:28:24 -07:00
|
|
|
|
|
|
|
interface IAuth {
|
2024-08-27 09:39:28 -07:00
|
|
|
password: string;
|
|
|
|
username: string;
|
2024-08-27 08:23:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const App = () => {
|
2024-08-27 09:39:28 -07:00
|
|
|
const [state, setInternalState] = useState<IAuth | null>(null);
|
|
|
|
|
|
|
|
const fetchUserData = () => {
|
|
|
|
fetch("https://jsonplaceholder.typicode.com/users")
|
|
|
|
.then((response) => {
|
|
|
|
return response.json();
|
|
|
|
})
|
|
|
|
.then((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(() => {
|
|
|
|
loadAuth();
|
|
|
|
//fetchUserData()
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="App">
|
2024-08-27 10:09:41 -07:00
|
|
|
{state ? <p>{state.username}</p> : <AuthModal doLogin={() => alert("login")}></AuthModal>}
|
2024-08-27 09:39:28 -07:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2024-07-31 20:58:46 -07:00
|
|
|
|
|
|
|
export default App;
|