Use tabs, add jmap-client-ts, use it a bit

This commit is contained in:
Eli Ribble 2024-08-27 14:00:30 -07:00
parent 913856c11b
commit 05779c0b64
8 changed files with 88 additions and 37 deletions

View File

@ -1 +1,3 @@
{} {
useTabs: true
}

6
package-lock.json generated
View File

@ -18,6 +18,7 @@
"@types/react-dom": "^18.3.0", "@types/react-dom": "^18.3.0",
"base-64": "^1.0.0", "base-64": "^1.0.0",
"bootstrap": "^5.3.3", "bootstrap": "^5.3.3",
"jmap-client-ts": "^1.0.0",
"react": "^18.3.1", "react": "^18.3.1",
"react-bootstrap": "^2.10.4", "react-bootstrap": "^2.10.4",
"react-dom": "^18.3.1", "react-dom": "^18.3.1",
@ -11992,6 +11993,11 @@
"jiti": "bin/jiti.js" "jiti": "bin/jiti.js"
} }
}, },
"node_modules/jmap-client-ts": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/jmap-client-ts/-/jmap-client-ts-1.0.0.tgz",
"integrity": "sha512-qL31lYUpLAqrVFMaMsogorcAcpZRTSjWPwnxdl61mDNY9DINQvrKIkYCMstva4cxTbL1kQFG4aT8K9wOesrj7g=="
},
"node_modules/js-tokens": { "node_modules/js-tokens": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",

View File

@ -13,6 +13,7 @@
"@types/react-dom": "^18.3.0", "@types/react-dom": "^18.3.0",
"base-64": "^1.0.0", "base-64": "^1.0.0",
"bootstrap": "^5.3.3", "bootstrap": "^5.3.3",
"jmap-client-ts": "^1.0.0",
"react": "^18.3.1", "react": "^18.3.1",
"react-bootstrap": "^2.10.4", "react-bootstrap": "^2.10.4",
"react-dom": "^18.3.1", "react-dom": "^18.3.1",

View File

@ -1,6 +1,8 @@
import "./App.css"; import "./App.css";
import "bootstrap/dist/css/bootstrap.min.css"; import "bootstrap/dist/css/bootstrap.min.css";
import * as base64 from "base-64"; import * as base64 from "base-64";
import { Client } from "jmap-client-ts";
import { FetchTransport } from "jmap-client-ts/lib/utils/fetch-transport";
//import MailboxList from "./Mailbox"; //import MailboxList from "./Mailbox";
import AuthModal from "./AuthModal"; import AuthModal from "./AuthModal";
@ -11,31 +13,53 @@ interface IAuth {
password: string; password: string;
} }
interface IAppState {
auth: IAuth;
}
const App = () => { const App = () => {
const [state, setInternalState] = useState<IAuth | null>(null); const [state, setInternalState] = useState<IAppState | null>(null);
// When the user provides credentials // When the user provides credentials
const onLogin = (email: string, password: string) => { const onLogin = (email: string, password: string) => {
// Store the provided credentials for now // Store the provided credentials for now
const auth = {email: email, password: password} const state = { auth: { email: email, password: password } };
setInternalState(auth); setInternalState(state);
localStorage.setItem("auth", JSON.stringify(auth)); localStorage.setItem("auth", JSON.stringify(state.auth));
doLogin(auth); doLogin(state.auth);
}; };
// Make the request to get system metadata // Make the request to get system metadata
const doLogin = (auth: IAuth) => { const doLogin = (auth: IAuth) => {
const domain = auth.email.split("@")[1]; const domain = auth.email.split("@")[1];
const well_known_url = "https://" + domain + "/.well-known/jmap" const well_known_url = "https://" + domain + "/.well-known/jmap";
const basic_auth =
"Basic " + base64.encode(auth.email + ":" + auth.password);
let client = new Client({
accessToken: "fake token",
httpHeaders: { Authorization: basic_auth },
sessionUrl: well_known_url,
transport: new FetchTransport(fetch.bind(window)),
});
client
.fetchSession()
.then((response) => console.log(response))
.catch((error) => console.error(error));
return;
/*
let headers = new Headers(); let headers = new Headers();
headers.append("Authorization", "Basic " + base64.encode(auth.email + ":" + auth.password)); headers.append("Authorization", basic_auth);
fetch(well_known_url, { fetch(well_known_url, {
method: "GET", method: "GET",
headers: headers, headers: headers,
}) })
.then(response => response.json()) .then(response => response.json())
.then(data => console.log(data)) .then(data => {
.catch(error => console.error(error)); console.log(data);
})
.catch(error => console.error(error));*/
}; };
const loadAuth = () => { const loadAuth = () => {
@ -52,7 +76,11 @@ const App = () => {
return ( return (
<div className="App"> <div className="App">
{state ? <p>{state.email}</p> : <AuthModal onLogin={onLogin}></AuthModal>} {state && state.auth ? (
<p>{state.auth.email}</p>
) : (
<AuthModal onLogin={onLogin}></AuthModal>
)}
</div> </div>
); );
}; };

View File

@ -1,12 +1,12 @@
import Button from "react-bootstrap/Button" import Button from "react-bootstrap/Button";
import Form from "react-bootstrap/Form" import Form from "react-bootstrap/Form";
import Modal from "react-bootstrap/Modal" import Modal from "react-bootstrap/Modal";
import React, {useState} from "react" import React, { useState } from "react";
type AuthProps = { type AuthProps = {
onLogin: (email: string, password: string) => void; onLogin: (email: string, password: string) => void;
} };
const AuthModal: React.FC<AuthProps> = ({ onLogin }) => { const AuthModal: React.FC<AuthProps> = ({ onLogin }) => {
const [email, setEmail] = useState(""); const [email, setEmail] = useState("");
@ -23,10 +23,19 @@ const AuthModal: React.FC<AuthProps> = ({ onLogin }) => {
</Modal.Header> </Modal.Header>
<Modal.Body> <Modal.Body>
<Form onSubmit={(e) => {e.preventDefault(); onLogin(email, password)}}> <Form
onSubmit={(e) => {
e.preventDefault();
onLogin(email, password);
}}
>
<Form.Group className="mb-3" controlId="formBasicEmail"> <Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Label>Email address</Form.Label> <Form.Label>Email address</Form.Label>
<Form.Control type="email" placeholder="Enter email" onChange={e => setEmail(e.target.value)}/> <Form.Control
type="email"
placeholder="Enter email"
onChange={(e) => setEmail(e.target.value)}
/>
<Form.Text className="text-muted"> <Form.Text className="text-muted">
We'll never share your email with anyone else. We'll never share your email with anyone else.
</Form.Text> </Form.Text>
@ -34,16 +43,21 @@ const AuthModal: React.FC<AuthProps> = ({ onLogin }) => {
<Form.Group className="mb-3" controlId="formBasicPassword"> <Form.Group className="mb-3" controlId="formBasicPassword">
<Form.Label>Password</Form.Label> <Form.Label>Password</Form.Label>
<Form.Control type="password" placeholder="Password" onChange={e => setPassword(e.target.value)}/> <Form.Control
type="password"
placeholder="Password"
onChange={(e) => setPassword(e.target.value)}
/>
</Form.Group> </Form.Group>
<Button variant="primary" type="submit">Login</Button> <Button variant="primary" type="submit">
Login
</Button>
</Form> </Form>
</Modal.Body> </Modal.Body>
<Modal.Footer> <Modal.Footer></Modal.Footer>
</Modal.Footer>
</Modal.Dialog> </Modal.Dialog>
</div> </div>
); );
} };
export default AuthModal; export default AuthModal;