Open PWA on last opened page
This commit is contained in:
+14
-2
@@ -34,6 +34,7 @@ import { createEditorState } from "./editor_state.ts";
|
||||
import { OpenPages } from "./open_pages.ts";
|
||||
import { MainUI } from "./editor_ui.tsx";
|
||||
import { DexieMQ } from "../plugos/lib/mq.dexie.ts";
|
||||
import { async } from "https://cdn.skypack.dev/-/regenerator-runtime@v0.13.9-4Dxus9nU31cBsHxnWq2H/dist=es2020,mode=imports/optimized/regenerator-runtime.js";
|
||||
const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/;
|
||||
|
||||
const autoSaveInterval = 1000;
|
||||
@@ -222,10 +223,10 @@ export class Client {
|
||||
// Reset for next sync cycle
|
||||
this.system.plugsUpdated = false;
|
||||
|
||||
this.ui.viewDispatch({ type: "sync-change", synced: true });
|
||||
this.ui.viewDispatch({ type: "sync-change", syncSuccess: true });
|
||||
});
|
||||
this.eventHook.addLocalListener("sync:error", (_name) => {
|
||||
this.ui.viewDispatch({ type: "sync-change", synced: false });
|
||||
this.ui.viewDispatch({ type: "sync-change", syncSuccess: false });
|
||||
});
|
||||
this.eventHook.addLocalListener("sync:conflict", (name) => {
|
||||
this.flashNotification(
|
||||
@@ -303,7 +304,18 @@ export class Client {
|
||||
scrollIntoView: true,
|
||||
});
|
||||
}
|
||||
await this.kvStore.set("lastOpenedPage", pageName);
|
||||
});
|
||||
|
||||
if (location.hash === "#boot") {
|
||||
(async () => {
|
||||
// Cold start PWA load
|
||||
const lastPage = await this.kvStore.get("lastOpenedPage");
|
||||
if (lastPage) {
|
||||
await this.navigate(lastPage);
|
||||
}
|
||||
})().catch(console.error);
|
||||
}
|
||||
}
|
||||
|
||||
initSpace() {
|
||||
|
||||
@@ -19,7 +19,7 @@ export type ActionButton = {
|
||||
export function TopBar({
|
||||
pageName,
|
||||
unsavedChanges,
|
||||
synced,
|
||||
syncFailures,
|
||||
isLoading,
|
||||
notifications,
|
||||
onRename,
|
||||
@@ -33,7 +33,7 @@ export function TopBar({
|
||||
}: {
|
||||
pageName?: string;
|
||||
unsavedChanges: boolean;
|
||||
synced: boolean;
|
||||
syncFailures: number;
|
||||
isLoading: boolean;
|
||||
notifications: Notification[];
|
||||
darkMode: boolean;
|
||||
@@ -78,7 +78,7 @@ export function TopBar({
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div id="sb-top" className={synced ? undefined : "sb-sync-error"}>
|
||||
<div id="sb-top" className={syncFailures > 1 ? "sb-sync-error" : undefined}>
|
||||
{lhs}
|
||||
<div className="main">
|
||||
<div className="inner">
|
||||
|
||||
+1
-1
@@ -178,7 +178,7 @@ export class MainUI {
|
||||
<TopBar
|
||||
pageName={viewState.currentPage}
|
||||
notifications={viewState.notifications}
|
||||
synced={viewState.synced}
|
||||
syncFailures={viewState.syncFailures}
|
||||
unsavedChanges={viewState.unsavedChanges}
|
||||
isLoading={viewState.isLoading}
|
||||
vimMode={viewState.uiOptions.vimMode}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
}
|
||||
],
|
||||
"capture_links": "new-client",
|
||||
"start_url": "/",
|
||||
"start_url": "/#boot",
|
||||
"display": "standalone",
|
||||
"scope": "/",
|
||||
"theme_color": "#e1e1e1",
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ export default function reducer(
|
||||
case "sync-change":
|
||||
return {
|
||||
...state,
|
||||
synced: action.synced,
|
||||
syncFailures: action.syncSuccess ? 0 : state.syncFailures + 1,
|
||||
};
|
||||
case "start-navigate":
|
||||
return {
|
||||
|
||||
+3
-3
@@ -52,7 +52,7 @@ export type AppViewState = {
|
||||
showCommandPalette: boolean;
|
||||
showCommandPaletteContext?: string;
|
||||
unsavedChanges: boolean;
|
||||
synced: boolean;
|
||||
syncFailures: number; // Reset everytime a sync succeeds
|
||||
progressPerc?: number;
|
||||
panels: { [key: string]: PanelConfig };
|
||||
allPages: PageMeta[];
|
||||
@@ -91,7 +91,7 @@ export const initialViewState: AppViewState = {
|
||||
showPageNavigator: false,
|
||||
showCommandPalette: false,
|
||||
unsavedChanges: false,
|
||||
synced: true,
|
||||
syncFailures: 0,
|
||||
uiOptions: {
|
||||
vimMode: false,
|
||||
darkMode: false,
|
||||
@@ -124,7 +124,7 @@ export type Action =
|
||||
| { type: "pages-listed"; pages: PageMeta[] }
|
||||
| { type: "page-changed" }
|
||||
| { type: "page-saved" }
|
||||
| { type: "sync-change"; synced: boolean }
|
||||
| { type: "sync-change"; syncSuccess: boolean }
|
||||
| { type: "start-navigate" }
|
||||
| { type: "stop-navigate" }
|
||||
| {
|
||||
|
||||
Reference in New Issue
Block a user