Make the wiki app use the global id picker.

This commit is contained in:
Cory McWilliams 2024-04-14 13:53:51 +01:00
parent 96cb6f4b12
commit b5e966c9a1
5 changed files with 11 additions and 50 deletions

View File

@ -1,5 +1,5 @@
{ {
"type": "tildefriends-app", "type": "tildefriends-app",
"emoji": "📝", "emoji": "📝",
"previous": "&hTgvoLzZ+6dlqYL7zRDAa91TzptTquAY8MaZ7Gn36Cc=.sha256" "previous": "&DaYqKHRBKhjFGaOzbKZ1+/pLspJeEkDJYTF2B50tH6k=.sha256"
} }

View File

@ -4,6 +4,9 @@ import * as utils from './utils.js';
let g_hash; let g_hash;
let g_collection_notifies = {}; let g_collection_notifies = {};
tfrpc.register(async function getActiveIdentity() {
return ssb.getActiveIdentity();
});
tfrpc.register(async function getOwnerIdentities() { tfrpc.register(async function getOwnerIdentities() {
return ssb.getOwnerIdentities(); return ssb.getOwnerIdentities();
}); });
@ -54,6 +57,9 @@ core.register('message', async function message_handler(message) {
await tfrpc.rpc.hash_changed(message.hash); 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) { tfrpc.register(function set_hash(hash) {
if (g_hash != hash) { if (g_hash != hash) {

View File

@ -10,7 +10,6 @@
window.litDisableBundleWarning = true; window.litDisableBundleWarning = true;
</script> </script>
<script src="tf-collection.js" type="module"></script> <script src="tf-collection.js" type="module"></script>
<script src="tf-id-picker.js" type="module"></script>
<script src="tf-wiki-doc.js" type="module"></script> <script src="tf-wiki-doc.js" type="module"></script>
<script src="tf-wiki-app.js" type="module"></script> <script src="tf-wiki-app.js" type="module"></script>
</body> </body>

View File

@ -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`
<link rel="stylesheet" href="tildefriends.css" />
<select @change=${this.changed} style="max-width: 100%">
${(this.ids ?? []).map(
(id) =>
html`<option ?selected=${id == this.selected} value=${id}>
${id}
</option>`
)}
</select>
`;
}
}
customElements.define('tf-id-picker', TfIdentityPickerElement);

View File

@ -31,13 +31,16 @@ class TfCollectionsAppElement extends LitElement {
tfrpc.register(function hash_changed(hash) { tfrpc.register(function hash_changed(hash) {
self.notify_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)); tfrpc.rpc.get_hash().then((hash) => self.notify_hash_changed(hash));
} }
async load() { async load() {
this.ids = await tfrpc.rpc.getIdentities(); this.ids = await tfrpc.rpc.getIdentities();
this.owner_ids = await tfrpc.rpc.getOwnerIdentities(); 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(); let ids = [...new Set([...this.owner_ids, this.whoami])].sort();
this.following = Object.keys(await tfrpc.rpc.following(ids, 1)).sort(); this.following = Object.keys(await tfrpc.rpc.following(ids, 1)).sort();
@ -273,9 +276,6 @@ class TfCollectionsAppElement extends LitElement {
margin-right: 16px; margin-right: 16px;
} }
</style> </style>
<div>
<tf-id-picker .ids=${this.ids} selected=${this.whoami} @change=${this.on_whoami_changed} ?hidden=${!this.ids?.length}></tf-id-picker>
</div>
<div> <div>
${keyed( ${keyed(
this.whoami, this.whoami,