wip
This commit is contained in:
parent
5c2842c995
commit
1d6ba99a36
8 changed files with 945 additions and 83 deletions
|
|
@ -23,7 +23,7 @@ export class Notes2 {
|
|||
this.startNode = new Node(this, nodeID ? parseInt(nodeID) : 0)
|
||||
}//}}}
|
||||
|
||||
treeGet() {
|
||||
treeGet() {//{{{
|
||||
const req = {}
|
||||
API.query('POST', '/node/tree', req)
|
||||
.then(response => {
|
||||
|
|
@ -31,7 +31,7 @@ export class Notes2 {
|
|||
nodeStore.add(response.Nodes)
|
||||
})
|
||||
.catch(e => console.log(e.type, e.error))
|
||||
}
|
||||
}//}}}
|
||||
}
|
||||
|
||||
class Tree extends Component {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { API } from 'api'
|
||||
|
||||
export class NodeStore {
|
||||
constructor() {
|
||||
if (!('indexedDB' in window)) {
|
||||
|
|
@ -6,7 +8,6 @@ export class NodeStore {
|
|||
|
||||
this.db = null
|
||||
}
|
||||
|
||||
async initializeDB() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let req = indexedDB.open('notes', 2)
|
||||
|
|
@ -60,7 +61,7 @@ export class NodeStore {
|
|||
}
|
||||
|
||||
records.forEach(record => {
|
||||
let addReq = nodeStore.add(record)
|
||||
let addReq = nodeStore.put(record)
|
||||
addReq.onsuccess = (event) => {
|
||||
console.log('OK!', record.ID, record.Name)
|
||||
}
|
||||
|
|
@ -74,14 +75,42 @@ export class NodeStore {
|
|||
}
|
||||
})
|
||||
}
|
||||
async get(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Node is always returned from IndexedDB if existing there.
|
||||
// Otherwise an attempt to get it from backend is executed.
|
||||
const trx = this.db.transaction('nodes', 'readonly')
|
||||
const nodeStore = trx.objectStore('nodes')
|
||||
const getRequest = nodeStore.get(id)
|
||||
getRequest.onsuccess = (event) => {
|
||||
// Node found in IndexedDB and returned.
|
||||
if (event.target.result !== undefined) {
|
||||
resolve(event.target.result)
|
||||
return
|
||||
}
|
||||
|
||||
// Node not found and a request to the backend is made.
|
||||
API.query("POST", `/node/retrieve/${id}`, {})
|
||||
.then(res => {
|
||||
const trx = this.db.transaction('nodes', 'readwrite')
|
||||
const nodeStore = trx.objectStore('nodes')
|
||||
const putRequest = nodeStore.put(res.Node)
|
||||
putRequest.onsuccess = () => resolve(res.Node)
|
||||
putRequest.onerror = (event) => {
|
||||
reject(event.target.error)
|
||||
}
|
||||
})
|
||||
.catch(e => reject(e))
|
||||
}
|
||||
})
|
||||
}
|
||||
async getTreeNodes() {
|
||||
return new Promise((resolve, reject)=>{
|
||||
return new Promise((resolve, reject) => {
|
||||
let trx = this.db.transaction('nodes', 'readonly')
|
||||
let nodeStore = trx.objectStore('nodes')
|
||||
let req = nodeStore.getAll()
|
||||
req.onsuccess = (event)=>resolve(event.target.result)
|
||||
req.onerror = (event)=>reject(event.target.error)
|
||||
req.onsuccess = (event) => resolve(event.target.result)
|
||||
req.onerror = (event) => reject(event.target.error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,28 @@
|
|||
const CACHE_NAME = 'notes2-{{ .VERSION }}'
|
||||
const CACHED_ASSETS = [
|
||||
'/',
|
||||
'/notes2',
|
||||
|
||||
'/css/{{ .VERSION }}/main.css',
|
||||
'/css/{{ .VERSION }}/notes2.css',
|
||||
|
||||
'/js/{{ .VERSION }}/lib/preact/preact.mjs',
|
||||
'/js/{{ .VERSION }}/lib/htm/htm.mjs',
|
||||
'/js/{{ .VERSION }}/lib/preact/devtools.mjs',
|
||||
'/js/{{ .VERSION }}/lib/signals/signals.mjs',
|
||||
'/js/{{ .VERSION }}/lib/signals/signals-core.mjs',
|
||||
'/js/{{ .VERSION }}/lib/preact/hooks.mjs',
|
||||
|
||||
'/js/{{ .VERSION }}/api.mjs',
|
||||
'/js/{{ .VERSION }}/node_store.mjs',
|
||||
'/js/{{ .VERSION }}/app.mjs',
|
||||
'/js/{{ .VERSION }}/key.mjs',
|
||||
'/js/{{ .VERSION }}/crypto.mjs',
|
||||
'/js/{{ .VERSION }}/checklist.mjs',
|
||||
|
||||
'/images/{{ .VERSION }}/leaf.svg',
|
||||
'/images/{{ .VERSION }}/collapsed.svg',
|
||||
'/images/{{ .VERSION }}/expanded.svg',
|
||||
]
|
||||
|
||||
async function precache() {
|
||||
|
|
@ -40,6 +61,6 @@ self.addEventListener('activate', event => {
|
|||
})
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
//console.log('SERVICE WORKER: fetch')
|
||||
console.log('SERVICE WORKER: fetch')
|
||||
event.respondWith(fetchAsset(event))
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue