#include "screens/create/ComposeLabScreen.hpp" #include "api/mock/MockFixtures.hpp" #include "screens/components/Box.hpp" #include "screens/components/DevPlaceTextEditor.hpp" #include "screens/components/EmojiPicker.hpp" #include "screens/Routes.hpp" #include "screens/components/SelectableTextPopover.hpp" #include "ui/Overlays.hpp" #include "ui/Controls.hpp" #include "ui/Palette.hpp" namespace dp { using namespace ui; namespace { constexpr const char* kSample = "The quick brown fox jumps over the lazy dog. Long press this text to select any part of the raw " "source, copy it or insert it as a quote into the editor below."; } ComposeLabScreen::ComposeLabScreen() : participants_(MockFixtures::userSearch().results) {} std::string ComposeLabScreen::title() const { return "Compose lab"; } ViewPtr ComposeLabScreen::body() { mentions_.update(draft_, caret_, participants_); QuoteComposer quote{true, [this](const std::string& q) { draft_ += q; }}; ViewPtr sample = BoxView(Text(kSample)->maxWidth(Alignment::leading())); ViewPtr popover = SelectableTextPopover(sample, kSample, quote); DevPlaceTextEditorOptions o; o.placeholder = "Write a comment"; o.initialLineCount = 3; o.handle = handle_; o.stateKey = "lab-editor"; o.onCaretChange = [this](int c) { caret_ = c; }; Binding binding{[this] { return draft_; }, [this](const std::string& v) { draft_ = v; }}; ViewPtr editor = DevPlaceTextEditor(binding, o); ViewPtr suggestions = mentions_.view([this, binding](const UserSearch::Result& r) { MentionSuggestions::insertMention(*handle_, binding, r.username); caret_ = handle_->caret(); }); ViewPtr emoji = OnTapRect(Text("Add emoji")->foreground(Palette::accent()), [this](Rect anchor) { presentEmojiPicker(anchor, [this](const std::string& e) { handle_->insertAtCaret(e); }); }); ViewPtr newPost = Button("New post", [] { Overlays::instance().sheet(makeCreatePostScreen(), SheetStyle::FullScreen); }); return ScrollView(ContentColumn(VStack({popover, suggestions, editor, emoji, newPost}, 12, HAlign::Leading) ->maxWidth(Alignment::leading())->padding(16))); } } // namespace dp