Support removing editors, I think, and include wikis from the app owner and from the authenticated user.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4629 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-11-12 20:17:23 +00:00
parent 5b2ace80d4
commit d467c4dd8a
3 changed files with 34 additions and 11 deletions

View File

@ -1,5 +1,5 @@
{
"type": "tildefriends-app",
"emoji": "📝",
"previous": "&Unu5AZjyD0RF/QzPh2/u7DuU8IPuSFSjYFkmiWAWcqk=.sha256"
"previous": "&G+R9QBUONLBiFGEecnE0w/qJPLOlj3WqtVUVemBdpbo=.sha256"
}

View File

@ -7,9 +7,9 @@
<tf-collections-app></tf-collections-app>
<script src="commonmark.min.js"></script>
<script>window.litDisableBundleWarning = true;</script>
<script src="tf-collections-app.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-app.js" type="module"></script>
</body>
</html>

View File

@ -17,6 +17,7 @@ class TfCollectionsAppElement extends LitElement {
hash: {type: String},
adding_editor: {type: Boolean},
expand_editors: {type: Boolean},
};
}
@ -37,7 +38,8 @@ class TfCollectionsAppElement extends LitElement {
this.ids = await tfrpc.rpc.getIdentities();
this.owner_ids = await tfrpc.rpc.getOwnerIdentities();
this.whoami = await tfrpc.rpc.localStorageGet('collections_whoami');
this.following = Object.keys(await tfrpc.rpc.following([this.whoami], 2)).sort();
let ids = [...new Set([...this.owner_ids, this.whoami])].sort();
this.following = Object.keys(await tfrpc.rpc.following(ids, 2)).sort();
await this.read_wikis();
await this.read_Wiki_docs();
@ -168,6 +170,20 @@ class TfCollectionsAppElement extends LitElement {
this.adding_editor = false;
}
async on_remove_editor(id) {
if (confirm(`Are you sure you want to remove ${id} as an editor?`)) {
let editors = [...this.wiki.editors];
if (editors.indexOf(id) != -1) {
editors = editors.filter(x => x !== id);
}
await tfrpc.rpc.appendMessage(this.whoami, {
type: 'wiki',
key: this.wiki.id,
editors: editors,
});
}
}
async on_wiki_tombstone(event) {
await tfrpc.rpc.appendMessage(this.whoami, {
type: 'wiki',
@ -244,14 +260,21 @@ class TfCollectionsAppElement extends LitElement {
@rename=${this.on_wiki_doc_rename}
@tombstone=${this.on_wiki_doc_tombstone}
@change=${this.on_wiki_doc_changed}></tf-collection>`)}
<div ?hidden=${!this.wiki?.editors}>
Editors: ${this.wiki?.editors}
<button @click=${() => self.adding_editor = true} ?hidden=${this.wiki?.editors?.indexOf(this.whoami) == -1 || this.adding_editor}>+</button>
<div ?hidden=${!this.adding_editor}>
<label for="add_editor">Add Editor:</label>
<input type="text" id="add_editor"></input>
<button @click=${this.on_add_editor}>Add Editor</button>
<button @click=${() => self.adding_editor = false}>x</button>
<button @click=${() => self.expand_editors = !self.expand_editors}>${this.wiki?.editors?.length} editor${this.wiki?.editors?.length > 1 ? 's' : ''}</button>
<div ?hidden=${!this.wiki?.editors || !this.expand_editors}>
<div>
<ul>
${this.wiki?.editors.map(id => html`<li><button ?hidden=${id == this.whoami} @click=${() => self.on_remove_editor(id)}>x</button> ${id}</li>`)}
<li>
<button @click=${() => self.adding_editor = true} ?hidden=${this.wiki?.editors?.indexOf(this.whoami) == -1 || this.adding_editor}>+</button>
<div ?hidden=${!this.adding_editor}>
<label for="add_editor">Add Editor:</label>
<input type="text" id="add_editor"></input>
<button @click=${this.on_add_editor}>Add Editor</button>
<button @click=${() => self.adding_editor = false}>x</button>
</div>
</li>
</ul>
</div>
</div>
</div>