misc fixes:

- sw: ensure db is inited before api listAll() call
- ui: init dbworker earlier, on app load
- typo: fix date created -> date loader
This commit is contained in:
Ilya Kreymer
2020-05-26 15:42:19 -07:00
parent 03023523b7
commit dd746e1d55
7 changed files with 74 additions and 53 deletions
+2 -1
View File
@@ -1,7 +1,7 @@
import { LitElement, html, css } from 'lit-element'; import { LitElement, html, css } from 'lit-element';
import { wrapCss, rwpLogo, IS_APP } from './misc'; import { wrapCss, rwpLogo, IS_APP } from './misc';
import { registerSW } from './pageutils'; import { registerSW, initDBWorker } from './pageutils';
import prettyBytes from 'pretty-bytes'; import prettyBytes from 'pretty-bytes';
@@ -25,6 +25,7 @@ class App extends LitElement
this.inited = false; this.inited = false;
registerSW(__SW_NAME__); registerSW(__SW_NAME__);
initDBWorker();
} }
static get properties() { static get properties() {
+2 -3
View File
@@ -17,8 +17,6 @@ class CollIndex extends LitElement
this.colls = []; this.colls = [];
this.sortedColls = []; this.sortedColls = [];
//this.sortKey = localStorage.getItem("index:sortKey") || "title";
//this.sortDesc = localStorage.getItem("index:sortDesc") === "1";
this.hideHeader = localStorage.getItem("index:hideHeader") === "1"; this.hideHeader = localStorage.getItem("index:hideHeader") === "1";
@@ -34,7 +32,7 @@ class CollIndex extends LitElement
name: "Source"}, name: "Source"},
{key: "ctime", {key: "ctime",
name: "Date Created"}, name: "Date Loaded"},
{key: "size", {key: "size",
name: "Total Size"} name: "Total Size"}
@@ -213,6 +211,7 @@ class CollIndex extends LitElement
<span>${this.hideHeader ? 'Expand' : 'Collapse'}</span> <span>${this.hideHeader ? 'Expand' : 'Collapse'}</span>
</a> </a>
<wr-sorter id="index" <wr-sorter id="index"
defaultKey="title"
.sortKeys="${CollIndex.sortKeys}" .sortKeys="${CollIndex.sortKeys}"
.data="${this.colls}" .data="${this.colls}"
@sort-changed="${(e) => this.sortedColls = e.detail.sortedData}"> @sort-changed="${(e) => this.sortedColls = e.detail.sortedData}">
+5 -13
View File
@@ -1,20 +1,12 @@
import { LitElement, html, css } from 'lit-element'; import { LitElement, html, css } from 'lit-element';
import { wrapCss } from './misc'; import { wrapCss } from './misc';
import { parseURLSchemeHostPath } from './pageutils'; import { parseURLSchemeHostPath, initDBWorker } from './pageutils';
let dbworker = null;
// =========================================================================== // ===========================================================================
class Loader extends LitElement class Loader extends LitElement
{ {
static initDBWorker() {
if (dbworker === null) {
dbworker = new Worker(__SW_NAME__);
}
}
constructor() { constructor() {
super(); super();
this.progress = 0; this.progress = 0;
@@ -24,7 +16,7 @@ class Loader extends LitElement
this.state = "waiting"; this.state = "waiting";
this.loadInfo = null; this.loadInfo = null;
Loader.initDBWorker(); this.dbworker = initDBWorker();
} }
static get properties() { static get properties() {
@@ -47,7 +39,7 @@ class Loader extends LitElement
} }
initMessages() { initMessages() {
dbworker.addEventListener("message", (event) => { this.dbworker.addEventListener("message", (event) => {
switch (event.data.msg_type) { switch (event.data.msg_type) {
case "collProgress": case "collProgress":
if (event.data.name === this.coll) { if (event.data.name === this.coll) {
@@ -119,7 +111,7 @@ You can select a file to upload from the main page by clicking the \'Choose File
msg.extraConfig = this.loadInfo.extraConfig; msg.extraConfig = this.loadInfo.extraConfig;
} }
dbworker.postMessage(msg); this.dbworker.postMessage(msg);
} }
googledriveInit() { googledriveInit() {
@@ -137,7 +129,7 @@ You can select a file to upload from the main page by clicking the \'Choose File
} }
onCancel() { onCancel() {
dbworker.postMessage({"msg_type": "cancelLoad", "name": this.coll}); this.dbworker.postMessage({"msg_type": "cancelLoad", "name": this.coll});
} }
updated(changedProperties) { updated(changedProperties) {
+7 -3
View File
@@ -191,6 +191,7 @@ class Pages extends LitElement
<div class="panel-block status"> <div class="panel-block status">
<span class="num-results">${this.formatResults()}</span> <span class="num-results">${this.formatResults()}</span>
<wr-sorter id="pages" <wr-sorter id="pages"
defaultKey="title"
.sortKeys="${Pages.sortKeys}" .sortKeys="${Pages.sortKeys}"
.data="${this.filteredPages}" .data="${this.filteredPages}"
@sort-changed="${(e) => this.sortedPages = e.detail.sortedData}" @sort-changed="${(e) => this.sortedPages = e.detail.sortedData}"
@@ -286,13 +287,16 @@ class PageEntry extends LitElement
render() { render() {
const p = this.page; const p = this.page;
const date = new Date(p.ts); let date = null;
try {
date = new Date(p.ts);
} catch (e) { }
return html` return html`
<div class="columns"> <div class="columns">
<div class="column col-date is-one-fifth"> <div class="column col-date is-one-fifth">
<div>${date.toLocaleDateString()}</div> <div>${date ? date.toLocaleDateString() : ""}</div>
<div>${date.toLocaleTimeString()}</div> <div>${date ? date.toLocaleTimeString() : ""}</div>
</div> </div>
<div class="column"> <div class="column">
<a @click="${this.onReplay}" data-url="${p.url}" data-ts="${getTS(date.toISOString())}" href="#"> <a @click="${this.onReplay}" data-url="${p.url}" data-ts="${getTS(date.toISOString())}" href="#">
+24 -1
View File
@@ -1,5 +1,7 @@
import { register } from 'register-service-worker'; import { register } from 'register-service-worker';
// ===========================================================================
async function registerSW(name = "sw.js", scope = "./") { async function registerSW(name = "sw.js", scope = "./") {
let resolve, reject; let resolve, reject;
@@ -24,6 +26,18 @@ async function registerSW(name = "sw.js", scope = "./") {
await p; await p;
} }
// ===========================================================================
let dbworker = null;
function initDBWorker() {
if (dbworker === null) {
dbworker = new Worker(__SW_NAME__);
}
return dbworker;
}
// ===========================================================================
async function digestMessage(message, hashtype) { async function digestMessage(message, hashtype) {
const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
const hashBuffer = await crypto.subtle.digest(hashtype, msgUint8); // hash the message const hashBuffer = await crypto.subtle.digest(hashtype, msgUint8); // hash the message
@@ -32,6 +46,8 @@ async function digestMessage(message, hashtype) {
return hashHex; return hashHex;
} }
// ===========================================================================
function tsToDate(ts) { function tsToDate(ts) {
if (!ts) { if (!ts) {
return ""; return "";
@@ -51,10 +67,14 @@ function tsToDate(ts) {
return new Date(datestr); return new Date(datestr);
}; };
// ===========================================================================
function getTS(iso) { function getTS(iso) {
return iso.replace(/[-:T]/g, '').slice(0, 14); return iso.replace(/[-:T]/g, '').slice(0, 14);
} }
// ===========================================================================
async function sourceToId(url) { async function sourceToId(url) {
try { try {
url = new URL(url, window.location.origin).href; url = new URL(url, window.location.origin).href;
@@ -65,6 +85,8 @@ async function sourceToId(url) {
return {url, coll}; return {url, coll};
} }
// ===========================================================================
// simple parse of scheme, host, rest of path // simple parse of scheme, host, rest of path
// not using URL due to different browser behavior // not using URL due to different browser behavior
function parseURLSchemeHostPath(url) { function parseURLSchemeHostPath(url) {
@@ -97,4 +119,5 @@ function parseURLSchemeHostPath(url) {
} }
export { digestMessage, tsToDate, getTS, sourceToId, parseURLSchemeHostPath, registerSW }; export { digestMessage, tsToDate, getTS, sourceToId, parseURLSchemeHostPath,
registerSW, initDBWorker };
+1 -1
View File
File diff suppressed because one or more lines are too long
+33 -31
View File
File diff suppressed because one or more lines are too long