feat: add db migration progress dialog

This commit is contained in:
thecodrr
2022-07-07 13:29:52 +05:00
parent 932dffb2b4
commit bd8d9bf642

View File

@@ -1,4 +1,6 @@
import { EventSourcePolyfill as EventSource } from "event-source-polyfill";
import { EVENTS } from "notes-core/common";
import { TaskManager } from "./task-manager";
/**
* @type {import("notes-core/api").default}
@@ -11,27 +13,42 @@ async function initializeDatabase(persistence) {
db = new Database(new NNStorage(persistence), EventSource, FS);
// if (isTesting()) {
// db.host({
// API_HOST: "https://api.notesnook.com",
// AUTH_HOST: "https://auth.streetwriters.co",
// SSE_HOST: "https://events.streetwriters.co",
// });
db.host({
API_HOST: "https://api.notesnook.com",
AUTH_HOST: "https://auth.streetwriters.co",
SSE_HOST: "https://events.streetwriters.co",
});
// } else {
// db.host({
// API_HOST: "http://localhost:5264",
// AUTH_HOST: "http://localhost:8264",
// SSE_HOST: "http://localhost:7264",
// });
const base = `http://${process.env.REACT_APP_LOCALHOST}`;
db.host({
API_HOST: `${base}:5264`,
AUTH_HOST: `${base}:8264`,
SSE_HOST: `${base}:7264`,
ISSUES_HOST: `${base}:2624`,
SUBSCRIPTIONS_HOST: `${base}:9264`,
});
// const base = `http://${process.env.REACT_APP_LOCALHOST}`;
// db.host({
// API_HOST: `${base}:5264`,
// AUTH_HOST: `${base}:8264`,
// SSE_HOST: `${base}:7264`,
// ISSUES_HOST: `${base}:2624`,
// SUBSCRIPTIONS_HOST: `${base}:9264`,
// });
// }
db.eventManager.subscribe(EVENTS.databaseMigrating, async ({ from, to }) => {
await TaskManager.startTask({
type: "modal",
title: `Migrating your database`,
subtitle:
"Please do not close your browser/app before the migration is done.",
action: (task) => {
task({ text: `Migrating database from v${from} to v${to}` });
return new Promise((resolve) => {
db.eventManager.subscribe(EVENTS.databaseMigrated, resolve);
});
},
});
});
await db.init();
return db;
}