From ee20b87ee2c86a87b7ba765c03f84f3232434f50 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 11 Dec 2024 12:53:04 -0500 Subject: [PATCH] ssb: Alt+up/down to cycle through channels. --- apps/ssb.json | 2 +- apps/ssb/tf-app.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/apps/ssb.json b/apps/ssb.json index 1ac1d7cf..a500bb84 100644 --- a/apps/ssb.json +++ b/apps/ssb.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🐌", - "previous": "&hWgKPOx3M3T7BufeywObcOCHvsdRfVAoZ9LErkPhJPE=.sha256" + "previous": "&tkrwd7UkPaWUk9189g3D08N44EjT0AJOlDLw6oMfbpY=.sha256" } diff --git a/apps/ssb/tf-app.js b/apps/ssb/tf-app.js index cb9d26e4..51d581e8 100644 --- a/apps/ssb/tf-app.js +++ b/apps/ssb/tf-app.js @@ -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=')) {