Fix annotation editing to use denotate+annotate instead of modifying in plac
This commit is contained in:
@@ -30,11 +30,15 @@ pub(super) struct AnnotationView {
|
||||
pub(super) origin: AnnotationOrigin,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(super) enum AnnotationOrigin {
|
||||
Original,
|
||||
Added,
|
||||
Deleted,
|
||||
Modified {
|
||||
original_entry: DateTime<Utc>,
|
||||
original_text: String,
|
||||
},
|
||||
}
|
||||
|
||||
fn annotation_id(entry: DateTime<Utc>, text: &str, index: usize) -> AnnotationId {
|
||||
@@ -96,4 +100,21 @@ impl AnnotationState {
|
||||
item.origin = AnnotationOrigin::Deleted;
|
||||
Some(item.created_at)
|
||||
}
|
||||
|
||||
pub(super) fn mark_modified(&mut self, id: AnnotationId) -> bool {
|
||||
if let Some(index) = self.items.iter().position(|item| item.id == id) {
|
||||
let item = &mut self.items[index];
|
||||
match item.origin {
|
||||
AnnotationOrigin::Original => {
|
||||
item.origin = AnnotationOrigin::Modified {
|
||||
original_entry: item.created_at,
|
||||
original_text: item.text.to_string(),
|
||||
};
|
||||
return true;
|
||||
}
|
||||
_ => return false,
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +226,13 @@ pub(super) fn build_task_update(
|
||||
update.annotations_delete.push(annotation.created_at);
|
||||
}
|
||||
AnnotationOrigin::Original => {}
|
||||
AnnotationOrigin::Modified {
|
||||
original_entry,
|
||||
original_text: _,
|
||||
} => {
|
||||
update.annotations_delete.push(original_entry);
|
||||
update.annotations_add.push(annotation.text.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1708,24 +1708,50 @@ impl TaskDetailModal {
|
||||
if i < visible.len() {
|
||||
let (actual_index, ann) = visible[i];
|
||||
|
||||
if ann.origin == AnnotationOrigin::Added {
|
||||
self.state.inline_edit =
|
||||
Some(InlineEditTarget::Annotation(actual_index));
|
||||
match ann.origin {
|
||||
AnnotationOrigin::Added => {
|
||||
self.state.inline_edit =
|
||||
Some(InlineEditTarget::Annotation(actual_index));
|
||||
|
||||
let ann_value = ann.text.to_string();
|
||||
self.entities.annotation_input.update(cx, |input, cx| {
|
||||
input.set_value(ann_value, cx);
|
||||
});
|
||||
let ann_value = ann.text.to_string();
|
||||
self.entities.annotation_input.update(cx, |input, cx| {
|
||||
input.set_value(ann_value, cx);
|
||||
});
|
||||
|
||||
self.enter_edit_field(window, cx);
|
||||
self.enter_edit_field(window, cx);
|
||||
|
||||
return CommandResult::Handled;
|
||||
} else {
|
||||
let toast_host = cx.global::<ToastGlobal>().host.clone();
|
||||
cx.update_entity(&toast_host, |host, cx| {
|
||||
host.push(ToastKind::Error, "Cannot edit original annotations", cx);
|
||||
});
|
||||
return CommandResult::Handled;
|
||||
return CommandResult::Handled;
|
||||
}
|
||||
AnnotationOrigin::Original => {
|
||||
let ann_id = ann.id;
|
||||
let ann_value = ann.text.to_string();
|
||||
self.state.annotations.mark_modified(ann_id);
|
||||
|
||||
self.state.inline_edit =
|
||||
Some(InlineEditTarget::Annotation(actual_index));
|
||||
|
||||
self.entities.annotation_input.update(cx, |input, cx| {
|
||||
input.set_value(ann_value, cx);
|
||||
});
|
||||
|
||||
self.enter_edit_field(window, cx);
|
||||
|
||||
return CommandResult::Handled;
|
||||
}
|
||||
AnnotationOrigin::Modified { .. } => {
|
||||
self.state.inline_edit =
|
||||
Some(InlineEditTarget::Annotation(actual_index));
|
||||
|
||||
let ann_value = ann.text.to_string();
|
||||
self.entities.annotation_input.update(cx, |input, cx| {
|
||||
input.set_value(ann_value, cx);
|
||||
});
|
||||
|
||||
self.enter_edit_field(window, cx);
|
||||
|
||||
return CommandResult::Handled;
|
||||
}
|
||||
AnnotationOrigin::Deleted => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user