fix: load a chat channel on login/load

This commit is contained in:
Andy Burke 2026-01-21 15:40:13 -08:00
parent 32ed2dfd33
commit 6637927e20
3 changed files with 48 additions and 24 deletions

View file

@ -72,6 +72,21 @@ const APP = {
channel_id
});
}
if (!document.body.dataset.channel || document.body.dataset.channel !== channel_id) {
const previous = typeof document.body.dataset.channel === 'string' ? document.body.dataset.channel : undefined;
if ( channel_id ) {
document.body.dataset.channel = channel_id;
}
else {
delete document.body.dataset.channel;
}
this._emit( 'channel_changed', {
previous,
channel_id
});
}
},
load: async function() {
@ -234,3 +249,8 @@ const APP = {
};
document.addEventListener("DOMContentLoaded", APP.load.bind( APP ));
APP.on( 'view_changed', ( { view } ) => {
if ( !view ) {
window.location.hash = '/chat';
}
});

View file

@ -87,6 +87,11 @@
border-right: 1px solid var(--border-subtle);
}
#sidebar .profile-container {
width: 100%;
max-width: 100%;
}
#sidebar #sidebar-context-menu {
display: none;
visibility: hidden;

View file

@ -1,7 +1,10 @@
<script>
APP.on("channels_updated", ({ channels }) => {
function on_channels_updated({ channels }) {
const channel_list = document.getElementById("channel-list");
if ( !channel_list ) {
setTimeout( () => {
on_channels_updated( { channels } );
}, 100 );
return;
}
@ -16,14 +19,18 @@
channel_list.insertAdjacentHTML(
"beforeend",
`<li id="channel-selector-${channel.id}" class="channel" data-channel-selector-for="${channel.id}"><a href="#/channel/${channel.id}/chat">${channel.name}</a></li>`,
`<li id="channel-selector-${channel.id}" class="channel" data-channel-selector-for="${channel.id}"><a href="#/chat/channel/${channel.id}">${channel.name}</a></li>`,
);
}
});
}
APP.on( 'view_changed', ( { previous, view, channel_id } ) => {
APP.on("channels_updated", on_channels_updated );
APP.on( 'view_changed', async ( { previous, view, channel_id } ) => {
if ( view !== 'chat' ) {
return;
}
if (document.body.dataset.channel !== channel_id) {
const previous_channel = typeof document.body.dataset.channel === 'string' ? document.body.dataset.channel : undefined;
if ( channel_id ) {
@ -33,22 +40,14 @@
delete document.body.dataset.channel;
}
const target_channel_id = channel_id ?? this.CHANNELS.CHANNEL_LIST[0]?.id;
await APP.CHANNELS.update(); // don't force, but ensure we have channels
const target_channel_id = channel_id ?? APP.CHANNELS.CHANNEL_LIST[0]?.id;
// TODO: allow a different default than chat
const hash_target = `/${ view ? view : 'chat' }` + ( target_channel_id ? `/channel/${ target_channel_id }` : '' );
const hash_target = `/chat` + ( target_channel_id ? `/channel/${ target_channel_id }` : '' );
if ( window.location.hash?.slice( 1 ) !== hash_target ) {
if ( previous_channel !== target_channel_id ) {
this._emit( 'channel_changed', {
previous: previous_channel,
channel_id: target_channel_id
});
}
window.location.hash = hash_target;
}
}
});
function update_channel_indicators(event) {