foxygit / Torlinkc Log in
commits tags

/include/torlinkc/ui/sort.hpp · 922 B

raw
#pragma once

#include <optional>
#include <string>
#include <vector>

#include "torlinkc/sources/types.hpp"

namespace torlinkc::ui {

enum class SortField { Size, Seeders, Source, Added };
enum class SortDir { Asc, Desc };

struct SortState {
  SortField field;
  SortDir dir;

  bool operator==(const SortState&) const = default;
};

// nullopt = "none" (the untouched/default order) in the TS original's
// `Sort = SortState | "none"`.
using Sort = std::optional<SortState>;

// The order the `s` key cycles through: untouched, then each field
// ascending then descending, then back to untouched. Ported from
// ui/sort.ts::SORT_CYCLE.
const std::vector<Sort>& sortCycle();

Sort nextSort(const Sort& current);
std::string sortArrow(SortDir dir);
std::string sortLabel(const Sort& sort);

std::vector<TorrentResult> sortResults(const std::vector<TorrentResult>& list, const Sort& sort);

}  // namespace torlinkc::ui