Skip to content
Repos

DevPlaceApp

C++ 1.4 KB51 lines Opens in site

Directory Raw Download

#pragma once
// Spec: FR-SHELL-01, FR-PUSH-01. Root application: four tabs, routing, startup sequence, unread polling.
#include <memory>

#include "net/HttpTypes.hpp"
#include "screens/Router.hpp"
#include "ui/App.hpp"
#include "ui/Controls.hpp"

namespace dp {

class DevPlaceApp : public ui::App, public Router {
 public:
  enum Tab { Posts = 0, Messages = 1, Notifications = 2, Settings = 3 };

  DevPlaceApp();
  ~DevPlaceApp() override;

  // Startup per INV-shell 1: sign in with stored credentials then load the feed, or load the feed anonymously.
  void start();

  ui::ViewPtr body(ui::Size window) override;
  bool dark(bool systemDark) override;
  bool onKeyDown(std::uint32_t key, std::uint16_t mods) override;
  void onForeground() override;
  std::string windowTitle() override;
  bool busy() override;

  // Router
  void openPost(const PostDestination& destination) override;
  void openConversation(const User& user) override;
  void openOwnProfile() override;
  void presentLogin() override;
  void openUrl(const std::string& url) override;

  void selectTab(Tab tab);
  Tab selectedTab() const { return static_cast<Tab>(tab_); }
  ui::Navigator& navigator(Tab tab) { return *navs_[static_cast<std::size_t>(tab)]; }

 private:
  void openPendingConversationIfNeeded();
  void schedulePoll();

  std::shared_ptr<ui::Navigator> navs_[4];
  int tab_ = Posts;
  int observerId_ = 0;
  bool loggedInSeen_ = false;
  CancelPtr poll_;
};

}  // namespace dp
42.4ms