forked from cory/tildefriends
		
	Bring back buttons to attach apps.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4014 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		| @@ -61,6 +61,12 @@ tfrpc.register(async function store_blob(blob) { | ||||
| 	} | ||||
| 	return await ssb.blobStore(blob); | ||||
| }); | ||||
| tfrpc.register(async function get_blob(id) { | ||||
| 	return utf8Decode(await ssb.blobGet(id)); | ||||
| }); | ||||
| tfrpc.register(function apps() { | ||||
| 	return core.apps(); | ||||
| }); | ||||
| ssb.addEventListener('broadcasts', async function() { | ||||
| 	await tfrpc.rpc.set('broadcasts', await ssb.getBroadcasts()); | ||||
| }); | ||||
|   | ||||
| @@ -12,6 +12,7 @@ class TfComposeElement extends LitElement { | ||||
| 			root: {type: String}, | ||||
| 			branch: {type: String}, | ||||
| 			mentions: {type: Object}, | ||||
| 			apps: {type: Object}, | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -23,6 +24,7 @@ class TfComposeElement extends LitElement { | ||||
| 		this.root = undefined; | ||||
| 		this.branch = undefined; | ||||
| 		this.mentions = {}; | ||||
| 		this.apps = undefined; | ||||
| 	} | ||||
|  | ||||
| 	changed(event) { | ||||
| @@ -183,6 +185,55 @@ class TfComposeElement extends LitElement { | ||||
| 			</div>`; | ||||
| 	} | ||||
|  | ||||
| 	render_attach_app() { | ||||
| 		let self = this; | ||||
|  | ||||
| 		async function attach_selected_app() { | ||||
| 			let name = self.renderRoot.getElementById('select').value; | ||||
| 			let id = self.apps[name]; | ||||
| 			let mentions = {}; | ||||
| 			mentions[id] = { | ||||
| 				name: name, | ||||
| 				link: id, | ||||
| 				type: 'application/tildefriends', | ||||
| 			}; | ||||
| 			if (name && id) { | ||||
| 				let app = JSON.parse(await tfrpc.rpc.get_blob(id)); | ||||
| 				for (let entry of Object.entries(app.files)) { | ||||
| 					mentions[entry[1]] = { | ||||
| 						name: entry[0], | ||||
| 						link: entry[1], | ||||
| 					}; | ||||
| 				} | ||||
| 			} | ||||
| 			this.mentions = Object.assign(this.mentions || {}, mentions); | ||||
| 			this.apps = null; | ||||
| 		} | ||||
|  | ||||
| 		if (this.apps) { | ||||
| 			return html` | ||||
| 				<div> | ||||
| 					<select id="select"> | ||||
| 						${Object.keys(self.apps).map(app => html`<option value=${app}>${app}</option>`)} | ||||
| 					</select> | ||||
| 					<input type="button" value="Attach" @click=${attach_selected_app}></input> | ||||
| 					<input type="button" value="Cancel" @click=${() => this.apps = null}></input> | ||||
| 				</div> | ||||
| 				`; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	render_attach_app_button() { | ||||
| 		async function attach_app() { | ||||
| 			this.apps = await tfrpc.rpc.apps(); | ||||
| 		} | ||||
| 		if (!this.apps) { | ||||
| 			return html`<input type="button" value="Attach App" @click=${attach_app}></input>` | ||||
| 		} else { | ||||
| 			return html`<input type="button" value="Discard App" @click=${() => this.apps = null}></input>` | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	render() { | ||||
| 		let self = this; | ||||
| 		let result = html` | ||||
| @@ -191,8 +242,10 @@ class TfComposeElement extends LitElement { | ||||
| 				<div id="preview" style="flex: 1 0 50%"></div> | ||||
| 			</div> | ||||
| 			${Object.values(this.mentions).map(x => self.render_mention(x))} | ||||
| 			${this.render_attach_app()} | ||||
| 			<input type="button" value="Submit" @click=${this.submit}></input> | ||||
| 			<input type="button" value="Attach" @click=${this.attach}></input> | ||||
| 			${this.render_attach_app_button()} | ||||
| 			<input type="button" value="Discard" @click=${this.discard}></input> | ||||
| 		`; | ||||
| 		return result; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user