Display Asterisk on Unsaved Documents (#392)

* ability to mark an open document as unsaved

* unsaved detection now being triggered based on layer tree height

* - rust implementation of unsaved markers
- upgraded eslint

* updated eslint in package.json

* - Renamed GetOpenDocumentsList -> UpdateOpenDocumentsList
- is not -> was not

* changed hash to current identifier to better reflect its meaning

* resolve some merge conflicts

* removed console.log statement leftover from debuging
This commit is contained in:
mfish33
2021-11-30 10:06:07 -08:00
committed by Keavon Chambers
parent c3ec2f76e9
commit fc0b951ab6
9 changed files with 88 additions and 52 deletions
+7 -5
View File
@@ -14,15 +14,17 @@ use crate::{
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Document {
pub root: Layer,
/// The state_identifier serves to provide a way to uniquely identify a particular state that the document is in.
/// This identifier is not a hash and is not guaranteed to be equal for equivalent documents.
#[serde(skip)]
pub hasher: DefaultHasher,
pub state_identifier: DefaultHasher,
}
impl Default for Document {
fn default() -> Self {
Self {
root: Layer::new(LayerDataType::Folder(Folder::default()), DAffine2::IDENTITY.to_cols_array()),
hasher: DefaultHasher::new(),
state_identifier: DefaultHasher::new(),
}
}
}
@@ -38,8 +40,8 @@ impl Document {
self.root.cache.clone()
}
pub fn hash(&self) -> u64 {
self.hasher.finish()
pub fn current_state_identifier(&self) -> u64 {
self.state_identifier.finish()
}
pub fn serialize_document(&self) -> String {
@@ -309,7 +311,7 @@ impl Document {
/// Mutate the document by applying the `operation` to it. If the operation necessitates a
/// reaction from the frontend, responses may be returned.
pub fn handle_operation(&mut self, operation: &Operation) -> Result<Option<Vec<DocumentResponse>>, DocumentError> {
operation.pseudo_hash().hash(&mut self.hasher);
operation.pseudo_hash().hash(&mut self.state_identifier);
use DocumentResponse::*;
let responses = match &operation {