ssb: Alt+up/down to cycle through channels.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 18m53s

This commit is contained in:
Cory McWilliams 2024-12-11 12:53:04 -05:00
parent 83e025d0bb
commit ee20b87ee2
2 changed files with 31 additions and 1 deletions

View File

@ -1,5 +1,5 @@
{
"type": "tildefriends-app",
"emoji": "🐌",
"previous": "&hWgKPOx3M3T7BufeywObcOCHvsdRfVAoZ9LErkPhJPE=.sha256"
"previous": "&tkrwd7UkPaWUk9189g3D08N44EjT0AJOlDLw6oMfbpY=.sha256"
}

View File

@ -97,6 +97,36 @@ class TfElement extends LitElement {
this.channels = Object.keys(channel_map).sort();
}
connectedCallback() {
super.connectedCallback();
this._keydown = this.keydown.bind(this);
window.addEventListener('keydown', this._keydown);
}
disconnectedCallback() {
super.disconnectedCallback();
window.removeEventListener('keydown', this._keydown);
}
keydown(event) {
if (event.altKey && event.key == 'ArrowUp') {
this.next_channel(1);
event.preventDefault();
} else if (event.altKey && event.key == 'ArrowDown') {
this.next_channel(-1);
event.preventDefault();
}
}
next_channel(delta) {
let channel_names = ['', '@'].concat(this.channels);
let index = channel_names.indexOf(this.hash.substring(1));
if (index != -1) {
index += delta;
this.set_hash('#' + encodeURIComponent(channel_names[(index + channel_names.length) % channel_names.length]));
}
}
set_hash(hash) {
this.hash = decodeURIComponent(hash || '#');
if (this.hash.startsWith('#q=')) {