Run prettier.

This commit is contained in:
2024-02-24 11:09:34 -05:00
parent 8e7e0ed490
commit d5267be38c
90 changed files with 5789 additions and 2265 deletions

View File

@ -31,7 +31,7 @@ class TfCollectionsAppElement extends LitElement {
tfrpc.register(function hash_changed(hash) {
self.notify_hash_changed(hash);
});
tfrpc.rpc.get_hash().then(hash => self.notify_hash_changed(hash));
tfrpc.rpc.get_hash().then((hash) => self.notify_hash_changed(hash));
}
async load() {
@ -49,10 +49,16 @@ class TfCollectionsAppElement extends LitElement {
let max_rowid;
let wikis;
let start_whoami = this.whoami;
while (true)
{
while (true) {
console.log('read_wikis', this.whoami);
[max_rowid, wikis] = await tfrpc.rpc.collection(this.following, 'wiki', undefined, max_rowid, wikis, false);
[max_rowid, wikis] = await tfrpc.rpc.collection(
this.following,
'wiki',
undefined,
max_rowid,
wikis,
false
);
console.log('read ->', wikis);
if (this.whoami !== start_whoami) {
break;
@ -70,9 +76,14 @@ class TfCollectionsAppElement extends LitElement {
let start_id = this.wiki.id;
let max_rowid;
let wiki_docs;
while (true)
{
[max_rowid, wiki_docs] = await tfrpc.rpc.collection(this.wiki?.editors, 'wiki-doc', this.wiki?.id, max_rowid, wiki_docs);
while (true) {
[max_rowid, wiki_docs] = await tfrpc.rpc.collection(
this.wiki?.editors,
'wiki-doc',
this.wiki?.id,
max_rowid,
wiki_docs
);
if (this.wiki?.id !== start_id) {
break;
}
@ -92,7 +103,7 @@ class TfCollectionsAppElement extends LitElement {
let hash = this.hash ?? '';
hash = hash.charAt(0) == '#' ? hash.substring(1) : hash;
let slash = hash.indexOf('/');
return slash != -1 ? hash.substring(slash + 1) : undefined;
return slash != -1 ? hash.substring(slash + 1) : undefined;
}
update_wiki() {
@ -128,7 +139,11 @@ class TfCollectionsAppElement extends LitElement {
}
update_hash() {
tfrpc.rpc.set_hash(this.wiki_doc ? `${this.wiki.name}/${this.wiki_doc.name}` : `${this.wiki.name}`);
tfrpc.rpc.set_hash(
this.wiki_doc
? `${this.wiki.name}/${this.wiki_doc.name}`
: `${this.wiki.name}`
);
}
async on_wiki_changed(event) {
@ -174,7 +189,7 @@ class TfCollectionsAppElement extends LitElement {
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);
editors = editors.filter((x) => x !== id);
}
await tfrpc.rpc.appendMessage(this.whoami, {
type: 'wiki',
@ -252,34 +267,45 @@ class TfCollectionsAppElement extends LitElement {
<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, html`<tf-collection
.collection=${this.wikis}
whoami=${this.whoami}
selected_id=${this.wiki?.id}
@create=${this.on_wiki_create}
@rename=${this.on_wiki_rename}
@tombstone=${this.on_wiki_tombstone}
@change=${this.on_wiki_changed}></tf-collection>`)}
${keyed(this.wiki_doc?.id, html`<tf-collection
.collection=${this.wiki_docs}
whoami=${this.whoami}
selected_id=${(this.wiki_doc && this.wiki_doc?.parent == this.wiki?.id) ? this.wiki_doc?.id : ''}
@create=${this.on_wiki_doc_create}
@rename=${this.on_wiki_doc_rename}
@tombstone=${this.on_wiki_doc_tombstone}
@change=${this.on_wiki_doc_changed}></tf-collection>`)}
<button @click=${() => self.expand_editors = !self.expand_editors}>${this.wiki?.editors?.length} editor${this.wiki?.editors?.length > 1 ? 's' : ''}</button>
${keyed(
this.whoami,
html`<tf-collection
.collection=${this.wikis}
whoami=${this.whoami}
selected_id=${this.wiki?.id}
@create=${this.on_wiki_create}
@rename=${this.on_wiki_rename}
@tombstone=${this.on_wiki_tombstone}
@change=${this.on_wiki_changed}
></tf-collection>`
)}
${keyed(
this.wiki_doc?.id,
html`<tf-collection
.collection=${this.wiki_docs}
whoami=${this.whoami}
selected_id=${this.wiki_doc &&
this.wiki_doc?.parent == this.wiki?.id
? this.wiki_doc?.id
: ''}
@create=${this.on_wiki_doc_create}
@rename=${this.on_wiki_doc_rename}
@tombstone=${this.on_wiki_doc_tombstone}
@change=${this.on_wiki_doc_changed}
></tf-collection>`
)}
<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>`)}
${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>
<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.adding_editor = false)}>x</button>
</div>
</li>
</ul>
@ -288,25 +314,54 @@ class TfCollectionsAppElement extends LitElement {
</div>
<div style="display: flex; flex-direction: row">
<div style="flex: 0 0">
${Object.values(this.wikis || {}).sort((x, y) => x.name.localeCompare(y.name)).map(wiki => html`
<div class="toc ${self.wiki?.id === wiki.id ? 'selected' : ''}" style="white-space: nowrap; cursor: pointer" @click=${() => self.on_wiki_changed({detail: {value: wiki}})}>${wiki.name}</div>
<ul>
${Object.values(self.wiki_docs || {}).filter(doc => doc.parent === wiki?.id).sort((x, y) => x.name.localeCompare(y.name)).map(doc => html`
<li class="toc ${self.wiki_doc?.id === doc.id ? 'selected' : ''}" style="white-space: nowrap; cursor: pointer; list-style: none; text-indent: -1rem" @click=${() => self.on_wiki_doc_changed({detail: {value: doc}})}>${doc?.private ? '🔒' : '📄'} ${doc.name}</li>
`)}
</ul>
`)}
${Object.values(this.wikis || {})
.sort((x, y) => x.name.localeCompare(y.name))
.map(
(wiki) => html`
<div
class="toc ${self.wiki?.id === wiki.id ? 'selected' : ''}"
style="white-space: nowrap; cursor: pointer"
@click=${() => self.on_wiki_changed({detail: {value: wiki}})}
>
${wiki.name}
</div>
<ul>
${Object.values(self.wiki_docs || {})
.filter((doc) => doc.parent === wiki?.id)
.sort((x, y) => x.name.localeCompare(y.name))
.map(
(doc) => html`
<li
class="toc ${self.wiki_doc?.id === doc.id
? 'selected'
: ''}"
style="white-space: nowrap; cursor: pointer; list-style: none; text-indent: -1rem"
@click=${() =>
self.on_wiki_doc_changed({detail: {value: doc}})}
>
${doc?.private ? '🔒' : '📄'} ${doc.name}
</li>
`
)}
</ul>
`
)}
</div>
${this.wiki_doc && this.wiki_doc.parent === this.wiki?.id ? html`
<tf-wiki-doc
style="width: 100%"
whoami=${this.whoami}
.wiki=${this.wiki}
.value=${this.wiki_doc}></tf-wiki-doc>
` : undefined}
${
this.wiki_doc && this.wiki_doc.parent === this.wiki?.id
? html`
<tf-wiki-doc
style="width: 100%"
whoami=${this.whoami}
.wiki=${this.wiki}
.value=${this.wiki_doc}
></tf-wiki-doc>
`
: undefined
}
</div>
`;
}
}
customElements.define('tf-collections-app', TfCollectionsAppElement);
customElements.define('tf-collections-app', TfCollectionsAppElement);