fix bug save when nagivating away

master
Niko PLP 4 months ago
parent 86a64d7ef5
commit 30f93e0797
  1. 2
      ng-app/index-web.html
  2. 2
      ng-app/src/apps/MdSource.svelte
  3. 3
      ng-app/src/apps/MilkDownEditor.svelte
  4. 2
      ng-app/src/apps/PostMdViewer.svelte
  5. 1
      ng-app/src/apps/YMapEditor.svelte
  6. 1
      ng-app/src/apps/YMapViewer.svelte
  7. 3
      ng-app/src/locales/en.json
  8. 14
      ng-app/src/store.ts
  9. 9
      ng-app/src/tab.ts
  10. 2
      ng-app/src/workertest.js
  11. 1
      ng-repo/src/errors.rs
  12. 5
      ng-verifier/src/commits/transaction.rs
  13. 7
      ng-verifier/src/verifier.rs

@ -119,7 +119,7 @@
if (RegExp().hasIndices === undefined) return false; if (RegExp().hasIndices === undefined) return false;
try { try {
if (Worker === undefined) return false; if (Worker === undefined) return false;
new Worker(URL.createObjectURL(new Blob(['console.log("webworker ok");'], {type: 'application/javascript'}))); new Worker(URL.createObjectURL(new Blob([';'], {type: 'application/javascript'})));
if (typeof WebAssembly === "object" if (typeof WebAssembly === "object"
&& typeof WebAssembly.instantiate === "function") { && typeof WebAssembly.instantiate === "function") {
const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)); const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));

@ -104,6 +104,7 @@
} }
onMount(async ()=>{ onMount(async ()=>{
if (editor) await editor.destroy();
await setup(); await setup();
}); });
@ -112,6 +113,7 @@
ydoc.destroy(); ydoc.destroy();
commits.discrete?.deregisterOnUpdate(); commits.discrete?.deregisterOnUpdate();
if (editor) await editor.destroy(); if (editor) await editor.destroy();
editor = undefined;
}); });

@ -181,7 +181,7 @@
} }
onMount(async ()=>{ onMount(async ()=>{
if (editor) await editor.destroy();
await setup(); await setup();
}); });
@ -189,6 +189,7 @@
onDestroy(async ()=>{ onDestroy(async ()=>{
ydoc.destroy(); ydoc.destroy();
if (editor) await editor.destroy(); if (editor) await editor.destroy();
editor = undefined;
}); });
</script> </script>

@ -129,6 +129,7 @@
} }
onMount(async ()=>{ onMount(async ()=>{
if (editor) await editor.destroy();
await setup(); await setup();
}); });
@ -137,6 +138,7 @@
ydoc.destroy(); ydoc.destroy();
try { try {
if (editor) await editor.destroy(); if (editor) await editor.destroy();
editor = undefined;
} catch(e) { } catch(e) {
console.log(e); console.log(e);
} }

@ -254,6 +254,7 @@
onDestroy(async ()=>{ onDestroy(async ()=>{
ydoc.destroy(); ydoc.destroy();
await editor.destroy(); await editor.destroy();
editor = undefined;
}); });
function onRenderMenu(items, context) { function onRenderMenu(items, context) {

@ -125,6 +125,7 @@
onDestroy(async ()=>{ onDestroy(async ()=>{
ydoc.destroy(); ydoc.destroy();
await editor.destroy(); await editor.destroy();
editor = undefined;
}); });
const edit = () => { const edit = () => {

@ -19,7 +19,7 @@
"pro": "Pro", "pro": "Pro",
"media": "Media", "media": "Media",
"chart": "Chart", "chart": "Chart",
"viz": "Vizualitation", "viz": "Visualization",
"diagram": "Diagram", "diagram": "Diagram",
"other": "Other file formats", "other": "Other file formats",
"data": "Data", "data": "Data",
@ -555,6 +555,7 @@
"DecryptionError": "Error with decryption.", "DecryptionError": "Error with decryption.",
"InvalidValue": "The value is invalid.", "InvalidValue": "The value is invalid.",
"ConnectionNotFound": "The connection was not found.", "ConnectionNotFound": "The connection was not found.",
"InvalidSecurityImage": "The security image you chose is not valid.",
"InvalidKey": "The key is invalid.", "InvalidKey": "The key is invalid.",
"InvalidInvitation": "The invitation is invalid.", "InvalidInvitation": "The invitation is invalid.",
"InvalidCreateAccount": "An error occurred creating the account.", "InvalidCreateAccount": "An error occurred creating the account.",

@ -17,7 +17,7 @@ import {
} from "svelte/store"; } from "svelte/store";
import { register, init, locale, format } from "svelte-i18n"; import { register, init, locale, format } from "svelte-i18n";
import ng from "./api"; import ng from "./api";
import { persistent_error, update_class, update_branch_display, open_branch, tab_update, change_nav_bar, cur_branch, cur_tab, show_modal_create, cur_tab_update, nav_bar,in_memory_save } from "./tab"; import { persistent_error, update_class, update_branch_display, open_branch, tab_update, change_nav_bar, cur_branch, cur_tab, show_modal_create, save, nav_bar,in_memory_save } from "./tab";
import { encode } from "./base64url"; import { encode } from "./base64url";
let all_branches = {}; let all_branches = {};
@ -47,6 +47,7 @@ init({
export const display_error = (error: string) => { export const display_error = (error: string) => {
if (error.message) return error.message; if (error.message) return error.message;
if (error.includes(" ")) return error; if (error.includes(" ")) return error;
if (error.includes("\"")) return error;
//console.log(error); //console.log(error);
// TODO: Check, if error tranlsation does not exist // TODO: Check, if error tranlsation does not exist
const parts = error.split(":"); const parts = error.split(":");
@ -143,6 +144,7 @@ export const toast_success = (text) => {
} }
export const openModalCreate = async () => { export const openModalCreate = async () => {
await save();
await reset_toasts() await reset_toasts()
show_modal_create.set(true); show_modal_create.set(true);
} }
@ -464,6 +466,7 @@ export const sparql_update = async function(sparql:string) {
} }
export const branch_subscribe = function(nuri:string, in_tab:boolean) { export const branch_subscribe = function(nuri:string, in_tab:boolean) {
//console.log("branch_subscribe", nuri) //console.log("branch_subscribe", nuri)
// const { subscribe, set, update } = writable([]); // create the underlying writable store // const { subscribe, set, update } = writable([]); // create the underlying writable store
@ -492,12 +495,14 @@ export const branch_subscribe = function(nuri:string, in_tab:boolean) {
// // update, // // update,
// }; // };
open_branch(nuri, in_tab);
return { return {
load: async () => { load: async () => {
//console.log("load upper"); //console.log("load upper");
await save();
open_branch(nuri, in_tab);
let already_subscribed = all_branches[nuri]; let already_subscribed = all_branches[nuri];
if (!already_subscribed) return; if (!already_subscribed) return;
if (already_subscribed.load) { if (already_subscribed.load) {
@ -696,7 +701,10 @@ export const branch_subscribe = function(nuri:string, in_tab:boolean) {
}); });
} else { } else {
console.error(e); console.error(e);
// TODO: display persistent_error persistent_error(nuri, {
title: get(format)("errors.an_error_occurred"),
desc: display_error(e)
});
} }
} }
// this is in case decrease has been called before the load function returned. // this is in case decrease has been called before the load function returned.

@ -335,9 +335,11 @@ export const save = async () => {
nav_bar.update((o) => { if (o.save === true) o.save = false; return o; }); nav_bar.update((o) => { if (o.save === true) o.save = false; return o; });
if (in_memory_save.length > 0) { if (in_memory_save.length > 0) {
await in_memory_save_callback(in_memory_save); let temp = in_memory_save;
}
in_memory_save = []; in_memory_save = [];
await in_memory_save_callback(temp);
}
} }
export const set_header_in_view = function(val) { export const set_header_in_view = function(val) {
@ -469,7 +471,8 @@ export const cur_tab_update = function( fn ) {
export const live_editing = writable(false); export const live_editing = writable(false);
export const showMenu = () => { export const showMenu = async () => {
await save();
show_modal_menu.set(true); show_modal_menu.set(true);
cur_tab_update(ct => { cur_tab_update(ct => {
ct.show_menu = true; ct.show_menu = true;

@ -1 +1 @@
console.log("workertest ok"); ;

@ -405,6 +405,7 @@ impl From<NgError> for VerifierError {
NgError::BranchNotFound => VerifierError::BranchNotFound, NgError::BranchNotFound => VerifierError::BranchNotFound,
NgError::SerializationError => VerifierError::SerializationError, NgError::SerializationError => VerifierError::SerializationError,
NgError::PermissionDenied => VerifierError::PermissionDenied, NgError::PermissionDenied => VerifierError::PermissionDenied,
NgError::VerifierError(e) => e,
// NgError::JsStorageReadError // NgError::JsStorageReadError
// NgError::JsStorageWriteError(String) // NgError::JsStorageWriteError(String)
// NgError::JsStorageKeyNotFound // NgError::JsStorageKeyNotFound

@ -229,7 +229,10 @@ impl Verifier {
(BranchCrdt::YMap(_), DiscreteTransaction::YMap(v)) => DiscretePatch::YMap(v), (BranchCrdt::YMap(_), DiscreteTransaction::YMap(v)) => DiscretePatch::YMap(v),
(BranchCrdt::YText(_), DiscreteTransaction::YText(v)) => DiscretePatch::YText(v), (BranchCrdt::YText(_), DiscreteTransaction::YText(v)) => DiscretePatch::YText(v),
(BranchCrdt::YXml(_), DiscreteTransaction::YXml(v)) => DiscretePatch::YXml(v), (BranchCrdt::YXml(_), DiscreteTransaction::YXml(v)) => DiscretePatch::YXml(v),
_ => return Err(VerifierError::InvalidCommit), _ => {
//log_debug!("{:?} {:?}", crdt, patch);
return Err(VerifierError::InvalidCommit);
}
}; };
self.push_app_response( self.push_app_response(
branch_id, branch_id,

@ -1415,6 +1415,7 @@ impl Verifier {
let broker_id = if as_publisher { let broker_id = if as_publisher {
if branch_info.topic_priv_key.is_none() { if branch_info.topic_priv_key.is_none() {
// we need to subscribe as publisher, but we cant // we need to subscribe as publisher, but we cant
log_debug!("no topic_priv_key");
return Err(NgError::PermissionDenied); return Err(NgError::PermissionDenied);
} }
Some(remote_broker.broker_peer_id()) Some(remote_broker.broker_peer_id())
@ -1990,8 +1991,7 @@ impl Verifier {
repo_id, repo_id,
Arc::clone(&store), Arc::clone(&store),
) )
.await .await?;
.map_err(|e| NgError::BootstrapError(e.to_string()))?;
let mut store_branch = None; let mut store_branch = None;
@ -2028,8 +2028,7 @@ impl Verifier {
repo_id, repo_id,
Arc::clone(&store), Arc::clone(&store),
) )
.await .await?;
.map_err(|e| NgError::BootstrapError(e.to_string()))?;
} }
} }

Loading…
Cancel
Save