Skip to content
Repos

DevPlaceApp

C++ 1.9 KB59 lines Opens in site

Directory Raw Download

#pragma once
// Spec: INV-posts 1 (FeedView + ViewModel). The feed: cards, pull to refresh, infinite scroll, reselect, new post
// button, alert on errors. FR-FEED-01.
#include <memory>
#include <optional>
#include <string>

#include "model/Post.hpp"
#include "screens/comments/CommentsSession.hpp"
#include "screens/post/ScrollDriver.hpp"
#include "ui/Navigation.hpp"

namespace dp {

class FeedScreen : public ui::Screen {
 public:
  // loadOnAppear: standalone use (--screen feed) where nothing else loads the first page.
  explicit FeedScreen(bool loadOnAppear = false);
  ~FeedScreen() override;

  ui::ViewPtr body() override;
  std::string title() const override;
  TitleMode titleMode() const override { return TitleMode::Inline; }
  void onAppear() override;
  void onReselect() override;
  bool busy() const override;

  // FeedVM.swift: first page into AppState (load), refresh (published after 300 ms) and loadMore (guarded).
  void load();
  void refresh();
  void loadMore();
  bool isRefreshing() const { return refreshing_; }
  bool isLoadingMore() const { return loadingMore_; }
  // The first page of `next` replaces the feed after the publish delay; errors alert.
  CommentsSession& session() { return session_; }

 private:
  ui::ViewPtr content();
  ui::ViewPtr newPostButton();
  void openPost(const std::string& slug, const std::optional<std::string>& scrollToCommentId);
  void openEditor(const Post& post);
  void presentCreate();
  void followMentionList();

  CommentsSession session_;
  ScrollDriver scroll_{"feed-scroll"};
  bool loadOnAppear_;
  bool didAppear_ = false;
  bool loading_ = false;
  bool refreshing_ = false;
  bool loadingMore_ = false;
  bool stalled_ = false;          // the last load-more brought no new post: wait for the next appearance
  int pendingPublishes_ = 0;
  float lastMentionHeight_ = 0;
  bool followPending_ = false;
  std::shared_ptr<bool> alive_ = std::make_shared<bool>(true);
};

}  // namespace dp
59.1ms