Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
Add delete button
Browse files Browse the repository at this point in the history
  • Loading branch information
valpackett committed Jul 8, 2018
1 parent 1c35f4b commit cabd444
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/micro-panel-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ export default class MicroPanelEditor extends LitElement {
return {
micropub: String, media: String, mediatoken: String,
defaultctype: String,
originalUrl: String,
entry: Object,
entryIsModified: Boolean, requestInFlight: Boolean,
entryIsNew: Boolean, entryIsModified: Boolean,
requestInFlight: Boolean,
cats: Array,
}
}
Expand All @@ -55,7 +57,7 @@ export default class MicroPanelEditor extends LitElement {
}
}

_render ({ micropub, media, mediatoken, entry, entryIsModified, cats }) {
_render ({ micropub, media, mediatoken, originalUrl, entry, entryIsNew, entryIsModified, cats }) {
return html`
${sharedStyles}
<style>
Expand All @@ -81,7 +83,10 @@ export default class MicroPanelEditor extends LitElement {
<header class="bar header-bar inverted">
<button on-click=${_ => this.close()} class="icon-button">${iconCode(icons.close)}</button>
<slot name="title"><h1>micro-panel editor</h1></slot>
${this.entryIsNew ? html`
${originalUrl ? html`
<button on-click=${_ => this.deleteEntry()}>Delete</button>
` : ''}
${entryIsNew ? html`
<button on-click=${_ => this.createEntry()} disabled?=${!entryIsModified}>Create</button>
` : html`
<button on-click=${_ => this.updateEntry()} disabled?=${!entryIsModified}>Save</button>
Expand Down Expand Up @@ -168,13 +173,26 @@ export default class MicroPanelEditor extends LitElement {
return alert('Somehow, an entry with no URL! I have no idea how to save that.')
}
this._post({
'action': 'update',
action: 'update',
url,
replace: this.entry.properties,
'delete': this.entry['x-micro-panel-deleted-properties'] || [],
})
}

deleteEntry () {
if (!this.originalUrl) {
return alert('Somehow, an entry with no URL! I have no idea how to delete that.')
}
if (!confirm('Delete this entry?')) {
return
}
this._post({
action: 'delete',
url: this.originalUrl
})
}

async _post (data) {
this.requestInFlight = true
let resp
Expand Down

0 comments on commit cabd444

Please sign in to comment.