embed: support referencing specific pages by index into page list, eg. url="page:0" will load the first page

sorter: use defaultKey / defaultDesc for url-resources sorter
This commit is contained in:
Ilya Kreymer
2020-09-06 20:42:32 -07:00
parent a3214dc081
commit 3f5431b7d7
5 changed files with 92 additions and 83 deletions
+10 -1
View File
@@ -1,7 +1,7 @@
import { LitElement, html, css, query } from 'lit-element';
import { wrapCss, rwpLogo, IS_APP } from './misc';
import { sourceToId, tsToDate } from './pageutils';
import { sourceToId, tsToDate, getPageDateTS } from './pageutils';
import fasBook from '@fortawesome/fontawesome-free/svgs/solid/book.svg';
@@ -247,6 +247,15 @@ class Coll extends LitElement
};
}
if (this.tabData.url.startsWith("page:")) {
const pageIndex = Number(this.tabData.url.slice("page:".length));
if (!isNaN(pageIndex) && pageIndex < this.collInfo.pages.length) {
const page = this.collInfo.pages[pageIndex];
this.tabData.url = page.url;
this.tabData.ts = getPageDateTS(page).timestamp;
}
}
if (!this.hasStory && this.tabData.view === "story") {
this.tabData.view = "pages";
}
+2 -15
View File
@@ -4,7 +4,7 @@ import { LitElement, html, css } from 'lit-element';
import "keyword-mark-element/lib/keyword-mark.js";
import { getTS } from './pageutils';
import { getPageDateTS } from './pageutils';
import { wrapCss } from './misc';
@@ -163,25 +163,12 @@ class PageEntry extends LitElement
//this.updateFavIcon();
this.deleting = false;
const res = this.getDateTS();
const res = getPageDateTS(this.page);
this.timestamp = res.timestamp;
this.date = res.date;
}
}
getDateTS() {
let date = null;
let ts = this.page.ts;
try {
date = new Date(this.page.ts || this.page.date);
} catch (e) {
}
const timestamp = (date && !isNaN(date)) ? getTS(date.toISOString()) : "";
return {date, timestamp};
}
render() {
const p = this.page;
const date = this.date;
+14 -1
View File
@@ -72,6 +72,19 @@ function tsToDate(ts) {
return new Date(datestr);
};
// ===========================================================================
function getPageDateTS(page) {
let date = null;
try {
date = new Date(page.ts || page.date);
} catch (e) {
}
const timestamp = (date && !isNaN(date)) ? getTS(date.toISOString()) : "";
return {date, timestamp};
}
// ===========================================================================
function getTS(iso) {
@@ -120,5 +133,5 @@ function parseURLSchemeHostPath(url) {
}
export { digestMessage, tsToDate, getTS, sourceToId, parseURLSchemeHostPath,
export { digestMessage, tsToDate, getTS, getPageDateTS, sourceToId, parseURLSchemeHostPath,
registerSW, initDBWorker };
+4 -4
View File
@@ -62,8 +62,8 @@ class URLResources extends LitElement
this.tryMore = false;
this.loading = false;
this.sortKey = "url";
this.sortDesc = false;
this.sortKey = null;
this.sortDesc = null;
}
static get properties() {
@@ -307,8 +307,8 @@ class URLResources extends LitElement
<div class="sort-header is-hidden-tablet">
<wr-sorter id="urls"
defaultKey="url"
.sortKey="${this.sortKey}"
.sortDesc="${this.sortDesc}"
defaultKey="${this.sortKey ? this.sortKey : "url"}"
?defaultDesc="${this.sortDesc !== null ? this.sortDesc : false}"
.sortKeys="${URLResources.sortKeys}"
.data="${this.filteredResults}"
@sort-changed="${this.onSortChanged}">