Make the wiki app use the global id picker.
This commit is contained in:
parent
96cb6f4b12
commit
b5e966c9a1
@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "tildefriends-app",
|
||||
"emoji": "📝",
|
||||
"previous": "&hTgvoLzZ+6dlqYL7zRDAa91TzptTquAY8MaZ7Gn36Cc=.sha256"
|
||||
"previous": "&DaYqKHRBKhjFGaOzbKZ1+/pLspJeEkDJYTF2B50tH6k=.sha256"
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -10,7 +10,6 @@
|
||||
window.litDisableBundleWarning = true;
|
||||
</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-app.js" type="module"></script>
|
||||
</body>
|
||||
|
@ -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);
|
@ -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;
|
||||
}
|
||||
</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>
|
||||
${keyed(
|
||||
this.whoami,
|
||||
|
Loading…
Reference in New Issue
Block a user