toggle live edit

master
Niko PLP 5 months ago
parent 434201c657
commit c7eda5198b
  1. 21
      ng-app/src/apps/CodeMirrorEditor.svelte
  2. 2
      ng-app/src/lib/FullLayout.svelte
  3. 10
      ng-app/src/store.ts
  4. 49
      ng-app/src/tab.ts
  5. 4
      ng-net/src/actors/app/request.rs
  6. 2
      ng-sdk-js/src/lib.rs
  7. 20
      ng-verifier/src/verifier.rs

@ -12,13 +12,17 @@
<script lang="ts">
import { onMount, tick, onDestroy } from "svelte";
import {
sparql_query,
toast_error,
toast_success,
reset_toasts,
display_error,
live_discrete_update
live_discrete_update,
discrete_update
} from "../store";
import {
cur_tab_register_on_save,
cur_tab_deregister_on_save
} from "../tab";
import * as Y from 'yjs'
// @ts-ignore
@ -36,18 +40,27 @@
ydoc.on('update', async (update, origin) => {
if (!origin.local) {
try {
await live_discrete_update(update, "YText", commits.heads);
await discrete_update(update, "YText", commits.heads);
} catch (e){
toast_error(display_error(e));
}
}
})
ydoc.on('destroy', () => {
ydoc.on('destroy', async () => {
commits.discrete?.deregisterOnUpdate();
await cur_tab_deregister_on_save();
})
onMount(()=>{
cur_tab_register_on_save(async (updates)=>{
let update = Y.mergeUpdates(updates);
await live_discrete_update(update, "YText", commits.heads);
});
let history = commits.discrete?.registerOnUpdate((update) => {
Y.applyUpdate(ydoc, update.YText, {local:true})
});

@ -37,7 +37,7 @@
import { onMount, onDestroy, tick } from "svelte";
import { cur_tab, cur_viewer, cur_editor, toggle_graph_discrete, cur_tab_update, get_class, get_app, all_tabs, live_editing,
available_editors, available_viewers, set_editor, set_viewer, set_view_or_edit, toggle_live_edit,
has_editor_chat, all_files_count, all_comments_count, nav_bar, save, hideMenu, show_modal_menu, show_modal_create,
has_editor_chat, all_files_count, all_comments_count, hideMenu, show_modal_menu, show_modal_create,
cur_tab_branch_nuri, cur_tab_doc_can_edit, cur_tab_doc_is_member, cur_tab_right_pane, cur_tab_folders_pane,
cur_tab_toc_pane, cur_tab_show_menu, cur_tab_branch_has_discrete, cur_tab_graph_or_discrete, cur_tab_view_or_edit } from "../tab";
import {

@ -17,7 +17,7 @@ import {
} from "svelte/store";
import { register, init, locale, format } from "svelte-i18n";
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 } from "./tab";
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 { encode } from "./base64url";
let all_branches = {};
@ -395,7 +395,13 @@ export const digest_to_string = function(digest) {
return encode(buffer.buffer);
};
export const discrete_update = async (update) => {
export const discrete_update = async (update, crdt, heads) => {
if (get(cur_tab).doc.live_edit) {
await live_discrete_update(update, crdt, heads);
} else {
in_memory_save.push(update);
nav_bar.update((o) => { o.save = true; return o; });
}
// if cur_tab.doc.live_edit => send directly to verifier (with live_discrete_update)
// else, save the update locally with the API.
// and nav_bar.update((o) => { o.save = true; return o; });

@ -260,8 +260,6 @@ export const all_tabs = writable({
description: "",
app: "", // current app being used
onSave: (updates) => {},
updates: [],
},
view_or_edit: true, // true=> view, false=> edit
graph_viewer: "", // selected viewer
@ -306,11 +304,29 @@ export const all_tabs = writable({
}
});
export const cur_tab_register_on_save = (f:(updates) => {}) => {
cur_tab_update((old)=>{
old.branch.onSave = f;
return old;
});
export let in_memory_save = [];
let in_memory_save_callback = async (updates) => {};
export const cur_tab_register_on_save = (f:(updates) => Promise<void>) => {
console.log("cur_tab_register_on_save")
in_memory_save_callback = f;
in_memory_save = [];
}
export const cur_tab_deregister_on_save = async () => {
await save();
in_memory_save_callback = async (updates) => {};
}
export const save = async () => {
// saving the doc
// TODO fetch updates from local storage
nav_bar.update((o) => { if (o.save === true) o.save = false; return o; });
if (in_memory_save.length > 0) {
await in_memory_save_callback(in_memory_save);
}
in_memory_save = [];
}
export const set_header_in_view = function(val) {
@ -465,11 +481,8 @@ export const nav_bar = writable({
live_editing.subscribe((val) => {
cur_tab_update((old)=> {
old.doc.live_edit = val;
if (val) {
//TODO: send all the updates with live_discrete_update
}
nav_bar.update((o) => {
o.save = old.doc.live_edit ? undefined : ( old.branch.updates.length > 0 ? true : false )
o.save = old.doc.live_edit ? undefined : ( in_memory_save.length > 0 ? true : false )
return o;
});
return old;
@ -525,12 +538,6 @@ export const persistent_error = (nuri, pe) => {
});
}
export const save = async () => {
// saving the doc
// fetch updates from local storage
get(cur_tab).branch.onSave([]);
}
export const all_files_count = derived(cur_tab, ($cur_tab) => {
let total = $cur_tab.branch.files;
return total ? `(${total})` : "";
@ -545,12 +552,18 @@ export const has_editor_chat = derived(cur_tab, ($cur_tab) => {
return $cur_tab.doc.can_edit && $cur_tab.store.store_type !== "private" && $cur_tab.store.store_type !== "dialog";
});
export const toggle_live_edit = () => {
export const toggle_live_edit = async () => {
let is_live;
cur_tab_update(ct => {
ct.doc.live_edit = !ct.doc.live_edit;
is_live = ct.doc.live_edit;
live_editing.set(ct.doc.live_edit);
return ct;
});
if (is_live) {
//send all the updates with live_discrete_update
await save();
}
}
export const set_viewer = (app_name: string) => {

@ -63,7 +63,7 @@ impl TryFrom<ProtocolMessage> for AppResponse {
if let AppMessageContentV0::Response(res) = msg.try_into()? {
Ok(res)
} else {
log_info!("INVALID AppMessageContentV0::Response");
log_err!("INVALID AppMessageContentV0::Response");
Err(ProtocolError::InvalidValue)
}
}
@ -83,7 +83,7 @@ impl TryFrom<ProtocolMessage> for AppMessageContentV0 {
Err(ProtocolError::ServerError)
}
} else {
log_info!("INVALID AppMessageContentV0 {:?}", msg);
log_err!("INVALID AppMessageContentV0 {:?}", msg);
Err(ProtocolError::InvalidValue)
}
}

@ -1022,7 +1022,7 @@ async fn app_request_stream_(
spawn_and_log_error(inner_task(reader, callback.clone(), canceller_tx.clone()));
let cb = Closure::once(move || {
log_info!("trying to cancel");
log_debug!("trying to cancel");
//sender.close_channel()
let _ = canceller_tx.unbounded_send(());
canceller_tx.close_channel();

@ -227,7 +227,7 @@ impl Verifier {
// );
if let Some(sender) = self.branch_subscriptions.get_mut(branch) {
if sender.is_closed() {
log_info!("closed so removed {}", branch);
log_debug!("closed so removed {}", branch);
self.branch_subscriptions.remove(branch);
} else {
let _ = sender.send(response).await;
@ -381,7 +381,7 @@ impl Verifier {
.await;
let fnonce = Box::new(move || {
log_info!("CLOSE_CHANNEL of subscription for branch {}", branch_id);
log_debug!("CLOSE_CHANNEL of subscription for branch {}", branch_id);
if !tx.is_closed() {
tx.close_channel();
}
@ -439,7 +439,7 @@ impl Verifier {
let stores = user_storage.get_all_store_and_repo_ids()?;
for (store, repos) in stores.iter() {
log_info!("LOADING STORE: {}", store);
log_debug!("LOADING STORE: {}", store);
let repo = user_storage
.load_store(store, Arc::clone(self.block_storage.as_ref().unwrap()))?;
self.stores.insert(
@ -1073,9 +1073,9 @@ impl Verifier {
let user = self.user_id().clone();
let broker = BROKER.read().await;
log_info!("looping on branches {:?}", branches);
log_debug!("looping on branches {:?}", branches);
for (repo, branch, publisher) in branches {
log_info!("open_branch_ repo {} branch {}", repo, branch);
log_debug!("open_branch_ repo {} branch {}", repo, branch);
let _e = self
.open_branch_(
&repo,
@ -1087,7 +1087,7 @@ impl Verifier {
false,
)
.await;
log_info!(
log_debug!(
"END OF open_branch_ repo {} branch {} with {:?}",
repo,
branch,
@ -1585,7 +1585,7 @@ impl Verifier {
let (store, msg, branch_secret) = {
//log_info!("do_sync_req_if_needed for branch {}", branch_id);
if remote_commits_nbr == 0 || remote_heads.is_empty() {
log_info!("branch is new on the broker. doing nothing");
log_debug!("branch is new on the broker. doing nothing");
return Ok(());
}
@ -1860,7 +1860,7 @@ impl Verifier {
}
}
log_info!("loaded from read_cap {}", repo_id);
log_debug!("loaded from read_cap {}", repo_id);
// TODO: deal with AddSignerCap that are saved on rocksdb for now, but do not make it to the Verifier.repos
return Ok((repo_id.clone(), store_branch));
@ -2128,7 +2128,7 @@ impl Verifier {
pub async fn send_outbox(&mut self) -> Result<(), NgError> {
let ret = self.take_events_from_outbox();
if ret.is_err() {
log_info!(
log_debug!(
"take_events_from_outbox returned {:}",
ret.as_ref().unwrap_err()
);
@ -2231,7 +2231,7 @@ impl Verifier {
.await?;
for file in commit.files() {
log_info!("PUT FILE {:?}", file.id);
log_debug!("PUT FILE {:?}", file.id);
self.put_all_blocks_of_file(&file, &repo_id, &store_repo)
.await?;
}

Loading…
Cancel
Save