fix: make sure things load properly on login/signup

This commit is contained in:
Andy Burke 2025-09-12 11:41:15 -07:00
parent f760156651
commit e52a9e997c
5 changed files with 81 additions and 61 deletions

View file

@ -48,14 +48,14 @@ export function get_events_collection_for_topic(topic_id: string): FSDB_COLLECTI
organize: (id) => { organize: (id) => {
TOPIC_EVENT_ID_MATCHER.lastIndex = 0; TOPIC_EVENT_ID_MATCHER.lastIndex = 0;
const { const groups: Record<string, string> | undefined = TOPIC_EVENT_ID_MATCHER.exec(id ?? '')?.groups;
groups: {
event_type, if (!groups) {
event_id throw new Error('Could not parse event id: ' + id);
} }
} = TOPIC_EVENT_ID_MATCHER.exec(id ?? '') ?? {
groups: {} const event_type = groups.event_type;
}; const event_id = groups.event_id;
return [ return [
event_type, event_type,

View file

@ -184,16 +184,15 @@ textarea:focus {
form div { form div {
position: relative; position: relative;
display: flex; display: flex;
margin-bottom: 1em; margin-bottom: 1.5em;
} }
form label { form label {
position: absolute; position: absolute;
top: 10px; top: 0;
font-size: 30px; font-size: large;
margin: 10px; margin: 10px;
padding: 0 10px; padding: 0 10px;
background-color: var(--bg);
-webkit-transition: -webkit-transition:
top 0.2s ease-in-out, top 0.2s ease-in-out,
font-size 0.2s ease-in-out; font-size 0.2s ease-in-out;
@ -204,8 +203,10 @@ form label {
form input:focus ~ label, form input:focus ~ label,
form input:valid ~ label { form input:valid ~ label {
top: -25px; top: -1.6rem;
font-size: 20px; font-size: small;
border: 1px solid rgba(128, 128, 128, 0.2);
border-bottom: 0;
} }
form input:focus { form input:focus {

View file

@ -114,6 +114,7 @@
update_topics_timeout = undefined; update_topics_timeout = undefined;
} }
try {
const topics_response = await api.fetch("/api/topics"); const topics_response = await api.fetch("/api/topics");
if (topics_response.ok) { if (topics_response.ok) {
const topic_list = document.getElementById("topic-list"); const topic_list = document.getElementById("topic-list");
@ -132,11 +133,21 @@
last_topic_update = now; last_topic_update = now;
} }
}
catch( error ) {
console.error( error );
}
update_topics_timeout = setTimeout( update_topics, UPDATE_TOPICS_FREQUENCY); update_topics_timeout = setTimeout( update_topics, UPDATE_TOPICS_FREQUENCY);
// now that we have topics, make sure our url is all good
extract_url_hash_info();
} }
document.addEventListener("DOMContentLoaded", async () => { document.addEventListener("DOMContentLoaded", async () => {
window.addEventListener("locationchange", update_topics);
document.addEventListener( 'user_logged_in', update_topics );
/* check if we are logged in */ /* check if we are logged in */
(async () => { (async () => {
try { try {
@ -167,8 +178,6 @@
} }
})(); })();
window.addEventListener("locationchange", update_topics);
await update_topics();
extract_url_hash_info(); extract_url_hash_info();
}); });

View file

@ -299,6 +299,8 @@
delete document.body.dataset.user; delete document.body.dataset.user;
delete document.body.dataset.perms; delete document.body.dataset.perms;
window.location = "/"; window.location = "/";
document.dispatchEvent(new CustomEvent("user_logged_out", { detail: {} }));
}; };
} }
</script> </script>

View file

@ -24,14 +24,15 @@
#signup-login-wall .limiter { #signup-login-wall .limiter {
width: 95%; width: 95%;
position: relative; position: relative;
background: rgba(128, 128, 128, 0.5); background: hsl(from var(--bg) h s 15);
max-width: 40em; max-width: 40em;
min-height: 22rem; min-height: 22rem;
margin: 0 auto;
} }
#signup-login-wall form { #signup-login-wall form {
width: 100%; width: 100%;
padding: 1rem; padding: 1.5rem;
} }
</style> </style>
@ -54,10 +55,13 @@
{ {
const form = document.currentScript.closest("form"); const form = document.currentScript.closest("form");
form.on_reply = (response) => { form.on_reply = (response) => {
// TODO: we should hold the session secret only in memory, not the cookie? const user = response.user;
document.body.dataset.user = JSON.stringify(response.user); document.body.dataset.user = JSON.stringify(user);
document.body.dataset.perms = document.body.dataset.perms = user.permissions.join(":");
response.user.permissions.join(":");
document.dispatchEvent(
new CustomEvent("user_logged_in", { detail: { user } }),
);
}; };
} }
</script> </script>
@ -91,9 +95,13 @@
{ {
const form = document.currentScript.closest("form"); const form = document.currentScript.closest("form");
form.on_reply = (response) => { form.on_reply = (response) => {
document.body.dataset.user = JSON.stringify(response.user); const user = response.user;
document.body.dataset.perms = document.body.dataset.user = JSON.stringify(user);
response.user.permissions.join(":"); document.body.dataset.perms = user.permissions.join(":");
document.dispatchEvent(
new CustomEvent("user_logged_in", { detail: { user } }),
);
}; };
} }
</script> </script>