@muze-nl/simplystore 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/www/index.html +33 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muze-nl/simplystore",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "main": "src/server.mjs",
5
5
  "type": "module",
6
6
  "scripts": {
package/www/index.html CHANGED
@@ -68,6 +68,12 @@
68
68
  </use></svg>
69
69
  Save
70
70
  </button>
71
+ <button data-simply-command="delete-query" class="ds-button ds-button-icon" disabled>
72
+ <svg class="ds-icon ds-icon-feather">
73
+ <use xlink:href="/assets/feather-sprite.svg#trash-2">
74
+ </use></svg>
75
+ Delete
76
+ </button>
71
77
  <button data-simply-command="load-fixtures" class="ds-button ds-button-icon">
72
78
  <svg class="ds-icon ds-icon-feather">
73
79
  <use xlink:href="/assets/feather-sprite.svg#briefcase">
@@ -148,11 +154,22 @@
148
154
  codeEditor.setValue(query)
149
155
  let button = el.closest('.ds-button')
150
156
  button.querySelector('nav.ds-dropdown-nav').classList.remove('ds-visible')
157
+ this.app.actions.toggleDelete('on')
151
158
  codeEditor.focus()
152
159
  },
153
160
  'save-query': async function() {
154
161
  let name = prompt('Enter the query name:',this.app.view.queryName || 'query')
155
- this.app.actions.saveQuery(name, codeEditor.getValue())
162
+ if (name) {
163
+ this.app.actions.saveQuery(name, codeEditor.getValue())
164
+ this.app.actions.toggleDelete('on')
165
+ }
166
+ },
167
+ 'delete-query': async function() {
168
+ if (confirm('Delete this query: '+this.app.view.queryName+'?')) {
169
+ this.app.actions.deleteQuery(this.app.view.queryName)
170
+ this.app.view.queryName = ''
171
+ this.app.actions.toggleDelete('off')
172
+ }
156
173
  },
157
174
  'load-fixtures': async function() {
158
175
  let fixtures = await this.app.actions.loadFixtures()
@@ -169,6 +186,7 @@
169
186
  return this.app.actions.getQuery(name)
170
187
  },
171
188
  saveQuery: async function(name, query) {
189
+ this.app.view.queryName = name
172
190
  this.app.view.queries = this.app.view.queries.filter(q => q.name!=name)
173
191
  this.app.view.queries.push({
174
192
  name: name,
@@ -176,6 +194,20 @@
176
194
  })
177
195
  localStorage.setItem('queries',JSON.stringify(this.app.view.queries))
178
196
  },
197
+ deleteQuery: async function(name) {
198
+ this.app.view.queries = this.app.view.queries.filter(q => q.name!=name)
199
+ localStorage.setItem('queries',JSON.stringify(this.app.view.queris))
200
+ },
201
+ toggleDelete: async function(state) {
202
+ let deleteButtons = document.querySelectorAll('.ds-button[data-simply-command="delete-query"]')
203
+ if (deleteButtons) {
204
+ if (state==='on') {
205
+ deleteButtons.forEach(b => b.removeAttribute('disabled'))
206
+ } else if (state==='off') {
207
+ deleteButtons.forEach(b => b.setAttribute('disabled','disabled'))
208
+ }
209
+ }
210
+ },
179
211
  loadFixtures: async function() {
180
212
  return this.app.actions.loadQuery('Fixtures')
181
213
  },