Fix account tab persistence and viewer fallback

This commit is contained in:
2026-06-27 19:09:07 +02:00
parent 3eb6bdf534
commit 59cdad220a
3 changed files with 85 additions and 17 deletions
+46 -9
View File
@@ -87,6 +87,25 @@ function scrollToBottom() {
setTimeout(go, 150);
}
function makeScrollSentinel() {
const sentinel = document.createElement("div");
sentinel.id = "scroll-sentinel";
sentinel.className = "scroll-sentinel";
return sentinel;
}
function resetMessageView(title = "Select a channel", subtitle = "Reading messages from the local SQLite database.") {
const root = document.getElementById("messages-list");
if (root) {
root.innerHTML = "";
root.appendChild(makeScrollSentinel());
}
document.getElementById("viewer-title").textContent = title;
document.getElementById("viewer-subtitle").textContent = subtitle;
viewerState.oldestMessageId = null;
viewerState.newestMessageId = null;
}
function renderChannelList() {
const root = document.getElementById("viewer-channel-list");
if (!root) return;
@@ -179,6 +198,13 @@ async function switchViewerAccount(accountId) {
renderChannelList();
if (viewerState.channelId) {
await loadChannel(viewerState.channelId);
} else {
resetMessageView(
"No channels",
viewerState.accountId
? "This account has no tracked channels yet."
: "No local legacy channels found."
);
}
}
@@ -190,10 +216,10 @@ async function loadViewerAccount(params) {
} catch {
viewerState.accounts = [];
}
viewerState.accountId =
requested ||
viewerState.accounts[0]?.id ||
null;
const requestedExists = requested && viewerState.accounts.some((acc) => acc.id === requested);
viewerState.accountId = requestedExists
? requested
: viewerState.accounts[0]?.id || null;
renderAccountSelector();
@@ -289,8 +315,9 @@ function makeDateSep(text) {
function renderMessages(payload, append = false) {
const root = document.getElementById("messages-list");
const sentinel = document.getElementById("scroll-sentinel");
if (!root) return;
let sentinel = document.getElementById("scroll-sentinel");
if (!sentinel) sentinel = makeScrollSentinel();
const channel = payload.channel;
document.getElementById("viewer-title").textContent =
@@ -408,14 +435,24 @@ async function main() {
const params = new URLSearchParams(window.location.search);
await loadViewerAccount(params);
viewerState.channels = await api(channelsEndpoint());
viewerState.channelId =
params.get("channel") ||
viewerState.channels[0]?.channel_id ||
null;
const requestedChannel = params.get("channel");
const requestedChannelExists =
requestedChannel &&
viewerState.channels.some((channel) => channel.channel_id === requestedChannel);
viewerState.channelId = requestedChannelExists
? requestedChannel
: viewerState.channels[0]?.channel_id || null;
renderChannelList();
if (viewerState.channelId) {
await loadChannel(viewerState.channelId);
} else {
resetMessageView(
"No channels",
viewerState.accountId
? "This account has no tracked channels yet."
: "No local legacy channels found."
);
}
setupInfiniteScroll();