Auto pretty everything, add initial auth modal.
Sorry this isn't more commits, but, whatever.
This commit is contained in:
parent
9033b9862a
commit
cda369a5f0
10 changed files with 94 additions and 62 deletions
67
src/App.tsx
67
src/App.tsx
|
@ -1,51 +1,48 @@
|
|||
import "./App.css";
|
||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||
import "bootstrap/dist/css/bootstrap.min.css";
|
||||
|
||||
//import MailboxList from "./Mailbox";
|
||||
import AuthModal from "./AuthModal";
|
||||
import React, { useEffect, useState } from "react"
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
interface IAuth {
|
||||
password: string;
|
||||
username: string;
|
||||
password: string;
|
||||
username: string;
|
||||
}
|
||||
|
||||
const App = () => {
|
||||
const [state, setInternalState] = useState<IAuth|null>(null)
|
||||
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 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 loadAuth = () => {
|
||||
const auth = localStorage.getItem("auth");
|
||||
if (!auth) return;
|
||||
setInternalState(JSON.parse(auth));
|
||||
};
|
||||
|
||||
const setState = (auth: IAuth) => {
|
||||
localStorage.setItem("auth", JSON.stringify(auth))
|
||||
}
|
||||
const setState = (auth: IAuth) => {
|
||||
localStorage.setItem("auth", JSON.stringify(auth));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
loadAuth()
|
||||
//fetchUserData()
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
loadAuth();
|
||||
//fetchUserData()
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
{state ?
|
||||
<p>{state.username}</p> :
|
||||
<AuthModal></AuthModal>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="App">
|
||||
{state ? <p>{state.username}</p> : <AuthModal></AuthModal>}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue