web: added login page

It's a start, but nothing great.
This commit is contained in:
Thomas Mathews 2022-12-22 10:55:22 -08:00
parent ab2ced247b
commit cdb2fefe90
5 changed files with 195 additions and 21 deletions

View file

@ -1,4 +1,4 @@
let DAMUS
let DAMUS = new_model();
const BOOTSTRAP_RELAYS = [
"wss://relay.damus.io",
@ -17,6 +17,12 @@ const SID_NOTIFICATIONS = "notifications";
const SID_EXPLORE = "explore";
const SID_PROFILES = "profiles";
// This is our main entry.
// https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
addEventListener('DOMContentLoaded', (ev) => {
damus_web_init();
});
async function damus_web_init() {
init_message_textareas();
let tries = 0;
@ -36,13 +42,31 @@ async function damus_web_init() {
}
async function damus_web_init_ready() {
const model = new_model();
DAMUS = model;
model.pubkey = await get_pubkey();
const model = DAMUS;
model.pubkey = await get_pubkey(false);
find_node("#container-busy").classList.add("hide");
if (!model.pubkey) {
// TODO show welcome screen
find_node("#container-welcome").classList.remove("hide");
return;
}
find_node("#container-app").classList.remove("hide");
webapp_init();
}
async function signin() {
const model = DAMUS;
model.pubkey = await get_pubkey();
if (!model.pubkey) {
return;
}
find_node("#container-welcome").classList.add("hide");
find_node("#container-app").classList.remove("hide");
webapp_init();
}
async function webapp_init() {
const model = DAMUS;
// WARNING Order Matters!
view_show_spinner(true);

View file

@ -240,19 +240,21 @@ function update_title(model) {
update_notification_markers(has_notes)
}
async function get_pubkey() {
async function get_pubkey(use_prompt=true) {
let pubkey = get_local_state('pubkey')
if (pubkey)
return pubkey
if (window.nostr && window.nostr.getPublicKey) {
console.log("calling window.nostr.getPublicKey()...")
log_debug("calling window.nostr.getPublicKey()...")
const pubkey = await window.nostr.getPublicKey()
console.log("got %s pubkey from nos2x", pubkey)
log_debug("got %s pubkey from nos2x", pubkey)
return await handle_pubkey(pubkey)
}
pubkey = prompt("Enter nostr id (eg: jb55@jb55.com) or pubkey (hex or npub)")
if (!pubkey)
throw new Error("Need pubkey to continue")
if (!use_prompt)
return;
pubkey = prompt("Enter Nostr ID (eg: jb55@jb55.com) or public key (hex or npub).")
if (!pubkey.trim())
return;
return await handle_pubkey(pubkey)
}
@ -280,6 +282,20 @@ function open_profile(pubkey) {
view_update_profile(DAMUS, pubkey);
}
function open_faqs() {
find_node("#faqs").classList.remove("closed");
}
function close_modal(el) {
while (el.parentElement) {
if (el.classList.contains("modal")) {
el.classList.add("closed");
break;
}
el = el.parentElement;
}
}
function view_update_profile(model, pubkey) {
const profile = model.profiles[pubkey] || {};
const el = find_node("[role='profile-info']");