#pragma once // Spec: PG-04, FR-CREATE-01, INV-posts 4 (CreatePost screen and view model) and 10 (poll creation). // Create and edit a post. Presented by other screens as a sheet: // Overlays::instance().sheet(makeCreatePostScreen(editing), SheetStyle::FullScreen); // For a completion callback (Swift onComplete) build the class directly: // auto screen = std::make_shared(editing); screen->setOnComplete([...]{...}); // Create mode keeps drafts (SettingsStore draftPostTitle / draftPostMessage, written on every change); edit mode // prefills topic, title and content, hides attachments and poll, never touches drafts. Unsubmitted attachments are // deleted when the screen disappears or is destroyed. // DIFF: the topic and project pickers show only the selected value after the "Topic" / "Link to Project" label. #include #include #include #include #include #include "model/PostDetail.hpp" #include "model/PostTopic.hpp" #include "model/Project.hpp" #include "screens/components/AttachmentUploader.hpp" #include "screens/components/CreatePoll.hpp" #include "ui/Navigation.hpp" #include "ui/TextInput.hpp" namespace dp { class CreatePostScreen : public ui::Screen { public: explicit CreatePostScreen(std::optional editing = std::nullopt); ~CreatePostScreen() override; // ---- ui::Screen ---- ui::ViewPtr body() override; std::string title() const override; TitleMode titleMode() const override { return TitleMode::Inline; } ui::ViewPtr toolbarLeading() override; ui::ViewPtr toolbarTrailing() override; void onAppear() override; void onDisappear() override; bool busy() const override { return isLoading_ || projectsLoading_ || uploader_.isUploading(); } // ---- view model ---- bool isEditing() const { return editing_.has_value(); } bool isLoading() const { return isLoading_; } bool canSubmit() const; void submit(); void setTitle(const std::string& value); // writes the draft in create mode void setMessage(const std::string& value); void setTopic(PostTopic topic) { topic_ = topic; } void setSelectedProject(std::optional id) { selectedProjectId_ = std::move(id); } void addPoll(); void removePoll(); void loadProjects(); void setOnComplete(std::function fn) { onComplete_ = std::move(fn); } const std::string& postTitle() const { return title_; } const std::string& message() const { return message_; } PostTopic topic() const { return topic_; } bool isPollAdded() const { return isPollAdded_; } CreatePoll& poll() { return poll_; } AttachmentUploader& uploader() { return uploader_; } const std::vector& projects() const { return projects_; } const std::optional& selectedProject() const { return selectedProjectId_; } private: ui::ViewPtr topicArea(); ui::ViewPtr titleArea(); ui::ViewPtr messageArea(); ui::ViewPtr attachmentsArea(); ui::ViewPtr pollArea(); ui::ViewPtr projectArea(); void resetFields(); void dismiss(); void cleanup(); std::optional editing_; PostTopic topic_ = PostTopic::Random; std::string title_; std::string message_; bool isPollAdded_ = false; CreatePoll poll_; AttachmentUploader uploader_; std::vector projects_; std::optional selectedProjectId_; bool isLoading_ = false; bool projectsLoading_ = false; bool projectsRequested_ = false; std::function onComplete_; std::shared_ptr titleHandle_ = std::make_shared(); std::shared_ptr messageHandle_ = std::make_shared(); std::shared_ptr alive_ = std::make_shared(true); }; } // namespace dp