diff --git a/apps/collections.json b/apps/collections.json index 35c3bbc5..a06fde65 100644 --- a/apps/collections.json +++ b/apps/collections.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "📦", - "previous": "&eNhxb2nCe0HSz+sMeiFDY/S8clbarp6P0wmYzBEQ1gI=.sha256" + "previous": "&JGlOM9T/I5L3daDq44CL/khzQy5OhBOFO3SXa5pUEnM=.sha256" } \ No newline at end of file diff --git a/apps/collections/app.js b/apps/collections/app.js index 6d41c18d..aaed4288 100644 --- a/apps/collections/app.js +++ b/apps/collections/app.js @@ -2,6 +2,10 @@ import * as tfrpc from '/tfrpc.js'; let g_hash; +tfrpc.register(async function getOwnerIdentities() { + return ssb.getOwnerIdentities(); +}); + tfrpc.register(async function getIdentities() { return ssb.getIdentities(); }); diff --git a/apps/collections/index.html b/apps/collections/index.html index 66c3cf92..8a087680 100644 --- a/apps/collections/index.html +++ b/apps/collections/index.html @@ -6,7 +6,7 @@ - + diff --git a/apps/collections/tf-collections.js b/apps/collections/tf-collection.js similarity index 72% rename from apps/collections/tf-collections.js rename to apps/collections/tf-collection.js index cb4288b2..7149ad4e 100644 --- a/apps/collections/tf-collections.js +++ b/apps/collections/tf-collection.js @@ -5,11 +5,14 @@ class TfCollectionElement extends LitElement { static get properties() { return { whoami: {type: String}, - collections: {type: Object}, + ids: {type: Array}, + collections: {type: Array}, collections_loading: {type: Number}, type: {type: String}, parent: {type: String}, selectname: {type: String}, + selectid: {type: String}, + is_creating: {type: Boolean}, }; } @@ -19,6 +22,7 @@ class TfCollectionElement extends LitElement { this.loaded = this.load(); this.type = 'collection'; this.collections_loading = 0; + console.log('CONSTRUCTOR'); } process_message(message) { @@ -36,10 +40,11 @@ class TfCollectionElement extends LitElement { async load() { try { + console.log('loading...'); this.collections_loading++; - if (this.whoami) { - let following = await tfrpc.rpc.following([this.whoami], 2); - this.following = following; + if (this.ids) { + let visible = this.ids; + this.visible = visible; if (this.type) { let collections = await tfrpc.rpc.query(` SELECT messages.id, author, content, timestamp @@ -48,7 +53,7 @@ class TfCollectionElement extends LitElement { json_extract(content, '$.type') = ?2 AND (?3 IS NULL OR json_extract(content, '$.parent') = ?3) ORDER BY timestamp - `, [JSON.stringify(following), this.type, this.parent]); + `, [JSON.stringify(visible), this.type, this.parent]); this.by_id = {}; for (let collection of collections) { this.process_message(collection); @@ -56,7 +61,6 @@ class TfCollectionElement extends LitElement { this.collections = Object.values(this.by_id); } } - console.log('loaded', this.collections); } finally { this.collections_loading--; } @@ -77,11 +81,9 @@ class TfCollectionElement extends LitElement { } notify_new_message(message) { - console.log('got notify new message', message); - if (this.following && - this.following.indexOf(message.author) != -1 && + if (this.visible && + this.visible.indexOf(message.author) != -1 && JSON.parse(message.content).type == this.type) { - console.log('processing message', message); this.process_message(message); this.collections = [...Object.values(this.by_id)]; } @@ -110,6 +112,7 @@ class TfCollectionElement extends LitElement { } set_selected(id, value, by_user) { + this.selectedid = id; this.dispatchEvent(new CustomEvent('selected', { bubbles: true, detail: { @@ -144,23 +147,36 @@ class TfCollectionElement extends LitElement { `; } + on_selected(event) { + if (this.collections) { + for (let collection of this.collections) { + if (collection.id === event.srcElement.value) { + this.set_selected(collection.id, collection, true); + break; + } + } + } + } + render() { + let self = this; let state = JSON.stringify([this.whoami, this.ids, this.parent]); if (state !== this.loaded_for) { this.loaded_for = state; - console.log('start load', state); this.loaded = this.load(); } return html` -

${this.type}s

-
${this.whoami} ${this.selectname}
-
${this.parent}
- - ${this.collections_loading ? html`
Loading...
` : html` - + ${this.collections_loading > 0 ? html`
Loading...
` : html` + `} + + + + + + `; } } diff --git a/apps/collections/tf-collections-app.js b/apps/collections/tf-collections-app.js index 10918543..8c7ff358 100644 --- a/apps/collections/tf-collections-app.js +++ b/apps/collections/tf-collections-app.js @@ -5,6 +5,7 @@ class TfCollectionsAppElement extends LitElement { static get properties() { return { ids: {type: Array}, + owner_ids: {type: Array}, whoami: {type: String}, wiki: {type: Object}, wiki_doc: {type: Object}, @@ -15,6 +16,7 @@ class TfCollectionsAppElement extends LitElement { constructor() { super(); this.ids = []; + this.owner_ids = []; this.load(); let self = this; tfrpc.register(function notify_new_message(message) { @@ -28,6 +30,7 @@ class TfCollectionsAppElement extends LitElement { async load() { this.ids = await tfrpc.rpc.getIdentities(); + this.owner_ids = await tfrpc.rpc.getOwnerIdentities(); this.whoami = await tfrpc.rpc.localStorageGet('collections_whoami'); } @@ -103,11 +106,33 @@ class TfCollectionsAppElement extends LitElement { let self = this; console.log('render', this.wiki?.name, this.wiki_doc?.name, this.hash); return html` -

Hello! ${this.hash}

- - - ${this.wiki?.id ? html`` : undefined} - ${this.wiki_doc && this.wiki_doc.parent === this.wiki?.id ? html`` : undefined} +
+ +
+
+ + ${this.wiki?.id ? html` + + ` : undefined} +
+ ${this.wiki_doc && this.wiki_doc.parent === this.wiki?.id ? html` + + ` : undefined} `; } } diff --git a/apps/collections/tf-wiki-doc.js b/apps/collections/tf-wiki-doc.js index e50b1cd8..1b2307e9 100644 --- a/apps/collections/tf-wiki-doc.js +++ b/apps/collections/tf-wiki-doc.js @@ -44,11 +44,12 @@ class TfWikiDocElement extends LitElement { this.load_blob(); } return html` -
WIKI DOC ${this.value.name}
-
${JSON.stringify(this.value, null, 2)}
-
- -
${this.blob}
+
+ +
${this.blob}
+
`; }