mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-24 11:31:28 +01:00
Comments: an edit's button reads Save, a new comment's Post (trials)
This commit is contained in:
6 files changed
+23
-4
No files matched your search
@@ -65,6 +65,7 @@ craft_ui::words! {
|
||||
add_comment: "comments.add" = "Add a comment";
|
||||
reply: "comments.reply" = "Add a reply";
|
||||
post: "comments.post" = "Post";
|
||||
save: "comments.save" = "Save";
|
||||
cancel: "comments.cancel" = "Cancel";
|
||||
more: "comments.more" = "More";
|
||||
edit: "comments.edit" = "Edit";
|
||||
|
||||
@@ -413,11 +413,11 @@ impl CommentRow<'_> {
|
||||
Some((editing, draft)) if editing == index => {
|
||||
let field = sink.field(Slot::EditField, strip(at, room), &words.edit, draft, EDIT_LINES);
|
||||
let y = at.y + field + st.gap;
|
||||
let (post_size, cancel_size) = (sink.push_size(Slot::EditPost, &words.post), sink.push_size(Slot::EditCancel, &words.cancel));
|
||||
let (post_size, cancel_size) = (sink.push_size(Slot::EditPost, &words.save), sink.push_size(Slot::EditCancel, &words.cancel));
|
||||
let right = at.x + room;
|
||||
let cancel = Rect::from_min_size(Pos2::new(right - cancel_size.x, y), cancel_size);
|
||||
let post = Rect::from_min_size(Pos2::new(cancel.left() - st.gap - post_size.x, y), post_size);
|
||||
sink.push(Slot::EditPost, post, &words.post, !draft.trim().is_empty());
|
||||
sink.push(Slot::EditPost, post, &words.save, !draft.trim().is_empty());
|
||||
sink.push(Slot::EditCancel, cancel, &words.cancel, true);
|
||||
y + post_size.y.max(cancel_size.y)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ craft_ui::words! {
|
||||
reply: "thread.reply" = "Reply";
|
||||
add_comment: "thread.addComment" = "Add a comment";
|
||||
post: "thread.post" = "Post";
|
||||
save: "thread.save" = "Save";
|
||||
edit: "thread.edit" = "Edit";
|
||||
delete: "thread.delete" = "Delete";
|
||||
delete_thread: "thread.deleteThread" = "Delete thread";
|
||||
|
||||
@@ -367,7 +367,9 @@ impl CommentComposer<'_> {
|
||||
posted.clone_from(&text);
|
||||
}
|
||||
Row::new().show(ui, |ui, _| {
|
||||
let post = Button::new(words.post.clone()).enabled(text.is_some()).show(ui);
|
||||
// An edit saves; a new comment posts.
|
||||
let word = if kind == ComposerDraft::New { &words.post } else { &words.save };
|
||||
let post = Button::new(word.clone()).enabled(text.is_some()).show(ui);
|
||||
if clicked(&post) && text.is_some() {
|
||||
posted.clone_from(&text);
|
||||
}
|
||||
|
||||
@@ -284,6 +284,7 @@ fn a_heading_folds_its_page_and_a_double_click_edits_a_card() {
|
||||
let note = card(&fixture, "Note 2.").expect("card 2").center();
|
||||
fixture.click_at(note).click_at(note).settle();
|
||||
assert_eq!(state.borrow().editing, Some((ThreadId(2), 0, "Note 2.".to_owned())), "the double click opens the comment's editor");
|
||||
assert!(fixture.by_label("Save").is_some(), "the editor's button is Save, as production's");
|
||||
}
|
||||
|
||||
/// The Own header draws its Sort, filter and Pages buttons and the Hosted one none; the host's rows follow a
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
|
||||
use craft_review::ui::{CommentComposer, ComposerClose, NOTE_POPUP_LIMITS, NoteDrafts, NotePopup, NotePopupMessage};
|
||||
use craft_review::ui::{CommentComposer, ComposerClose, ComposerDraft, NOTE_POPUP_LIMITS, NoteDrafts, NotePopup, NotePopupMessage};
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::contract::overlay::PlacementKind;
|
||||
@@ -309,3 +309,17 @@ fn the_title_band_runs_under_the_close_control() {
|
||||
let widest = bands.iter().map(|r| r.width()).fold(0.0, f32::max);
|
||||
assert!((widest - rect.width()).abs() < 1.5, "the band covers the window's width, close control included: {bands:?}");
|
||||
}
|
||||
|
||||
/// A composer that edits an existing comment saves it; one that starts a comment posts it.
|
||||
#[trial]
|
||||
fn an_edit_composer_reads_save_and_a_new_one_reads_post() {
|
||||
for (kind, word, other) in [(ComposerDraft::New, "Post", "Save"), (ComposerDraft::Edit, "Save", "Post")] {
|
||||
let mut draft = String::from("text");
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let _ = CommentComposer::new(Some(pos2(200.0, 200.0)), &mut draft).draft_kind(kind).show(ui);
|
||||
});
|
||||
fixture.room(vec2(800.0, 600.0)).settle();
|
||||
assert!(fixture.by_label(word).is_some(), "{kind:?}: the button reads {word}");
|
||||
assert!(fixture.by_label(other).is_none(), "{kind:?}: not {other}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user