Skip to content

Commit

Permalink
Update handle in UI after changing
Browse files Browse the repository at this point in the history
Also improve UX a bit
  • Loading branch information
anderspitman committed Oct 1, 2024
1 parent 5318ec6 commit 8163670
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 10 additions & 0 deletions atproto.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ function logout() {
localStorage.removeItem('login_data');
}

function setLoginDataHandle(newHandle) {
const loginDataJson = localStorage.getItem('login_data');
if (loginDataJson) {
const ld = JSON.parse(loginDataJson);
ld.handle = newHandle;
localStorage.setItem('login_data', JSON.stringify(ld));
}
}

async function login(handleOrServer) {

let handle;
Expand Down Expand Up @@ -424,4 +433,5 @@ export {
login,
logout,
inProd,
setLoginDataHandle,
};
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<style>

#user-id {
.user-id {
font-weight: bold;
}

Expand Down Expand Up @@ -88,7 +88,7 @@ <h1>Custom Bluesky Handles</h1>

<template id='logged-in-page'>
<p>
Your current handle is <span id='user-id'></span> (<a id='logout-btn' href='/logout'>logout</a>)
Your current handle is <span class='user-id'></span> (<a id='logout-btn' href='/logout'>logout</a>)
</p>

<p>
Expand Down
9 changes: 6 additions & 3 deletions ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class LoggedInPage extends HTMLElement {
connectedCallback() {
const tmpl = cloneTemplate('logged-in-page');

const userIdEl = tmpl.querySelector('#user-id');
const userIdEl = tmpl.querySelector('.user-id');
userIdEl.innerText = this.atClient.handle;

const logoutBtn = tmpl.querySelector('#logout-btn');
Expand Down Expand Up @@ -155,7 +155,7 @@ async function setRecords(atClient, ndClient, statusText) {

const newHandle = host ? `${host}.${domain}` : domain;

const failHtml = `Failed to update handle. <a href='${window.location.href}'>Restart</a>.`;
const failHtml = `Failed to update handle. <a href='${window.location.href}'>Start Over</a>.`;

let attemptNum = 1;
const intId = setInterval(async () => {
Expand All @@ -182,7 +182,10 @@ async function setRecords(atClient, ndClient, statusText) {
statusText.innerHTML = failHtml;
return;
}
statusText.innerText = "Successfully updated handle";

atproto.setLoginDataHandle(newHandle);

statusText.innerHTML = `Successfully updated handle to <span class='user-id'>${newHandle}</span>. <a href='${window.location.href}'>Start Over</a>`;
}
}, 1000);
}
Expand Down

0 comments on commit 8163670

Please sign in to comment.