From b5e966c9a1a3ade64b83b20501b5c75286ee383e Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 14 Apr 2024 13:53:51 +0100 Subject: [PATCH] Make the wiki app use the global id picker. --- apps/wiki.json | 2 +- apps/wiki/app.js | 6 ++++++ apps/wiki/index.html | 1 - apps/wiki/tf-id-picker.js | 44 --------------------------------------- apps/wiki/tf-wiki-app.js | 8 +++---- 5 files changed, 11 insertions(+), 50 deletions(-) delete mode 100644 apps/wiki/tf-id-picker.js diff --git a/apps/wiki.json b/apps/wiki.json index 8bd14630..9b73770e 100644 --- a/apps/wiki.json +++ b/apps/wiki.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "📝", - "previous": "&hTgvoLzZ+6dlqYL7zRDAa91TzptTquAY8MaZ7Gn36Cc=.sha256" + "previous": "&DaYqKHRBKhjFGaOzbKZ1+/pLspJeEkDJYTF2B50tH6k=.sha256" } diff --git a/apps/wiki/app.js b/apps/wiki/app.js index 7fc80313..7beb8a90 100644 --- a/apps/wiki/app.js +++ b/apps/wiki/app.js @@ -4,6 +4,9 @@ import * as utils from './utils.js'; let g_hash; let g_collection_notifies = {}; +tfrpc.register(async function getActiveIdentity() { + return ssb.getActiveIdentity(); +}); tfrpc.register(async function getOwnerIdentities() { return ssb.getOwnerIdentities(); }); @@ -54,6 +57,9 @@ core.register('message', async function message_handler(message) { await tfrpc.rpc.hash_changed(message.hash); } }); +core.register('setActiveIdentity', async function setActiveIdentityHandler(id) { + await tfrpc.rpc.setActiveIdentity(id); +}); tfrpc.register(function set_hash(hash) { if (g_hash != hash) { diff --git a/apps/wiki/index.html b/apps/wiki/index.html index d363220a..c30e24b5 100644 --- a/apps/wiki/index.html +++ b/apps/wiki/index.html @@ -10,7 +10,6 @@ window.litDisableBundleWarning = true; - diff --git a/apps/wiki/tf-id-picker.js b/apps/wiki/tf-id-picker.js deleted file mode 100644 index 6eb679c2..00000000 --- a/apps/wiki/tf-id-picker.js +++ /dev/null @@ -1,44 +0,0 @@ -import {LitElement, html} from './lit-all.min.js'; -import * as tfrpc from '/static/tfrpc.js'; - -/* - ** Provide a list of IDs, and this lets the user pick one. - */ -class TfIdentityPickerElement extends LitElement { - static get properties() { - return { - ids: {type: Array}, - selected: {type: String}, - }; - } - - constructor() { - super(); - this.ids = []; - } - - changed(event) { - this.selected = event.srcElement.value; - this.dispatchEvent( - new Event('change', { - srcElement: this, - }) - ); - } - - render() { - return html` - - - `; - } -} - -customElements.define('tf-id-picker', TfIdentityPickerElement); diff --git a/apps/wiki/tf-wiki-app.js b/apps/wiki/tf-wiki-app.js index 7f6f3b2c..378f51d1 100644 --- a/apps/wiki/tf-wiki-app.js +++ b/apps/wiki/tf-wiki-app.js @@ -31,13 +31,16 @@ class TfCollectionsAppElement extends LitElement { tfrpc.register(function hash_changed(hash) { self.notify_hash_changed(hash); }); + tfrpc.register(function setActiveIdentity(id) { + self.whoami = id; + }); tfrpc.rpc.get_hash().then((hash) => self.notify_hash_changed(hash)); } async load() { this.ids = await tfrpc.rpc.getIdentities(); this.owner_ids = await tfrpc.rpc.getOwnerIdentities(); - this.whoami = await tfrpc.rpc.localStorageGet('collections_whoami'); + this.whoami = await tfrpc.rpc.getActiveIdentity(); let ids = [...new Set([...this.owner_ids, this.whoami])].sort(); this.following = Object.keys(await tfrpc.rpc.following(ids, 1)).sort(); @@ -273,9 +276,6 @@ class TfCollectionsAppElement extends LitElement { margin-right: 16px; } -
- -
${keyed( this.whoami,