anaso_site_api_models 0.0.19

API models for Ana.so
Documentation
use serde::{Deserialize, Serialize};

use crate::stela::{Image, Motion};

use super::Section;

/// List of clickable tiles.
#[derive(bon::Builder, Debug, Deserialize, Serialize)]
pub struct SectionTiles {
    /// The list of tiles.
    pub tiles: Vec<Tile>,
    /// How to layout the tiles.
    pub layout: TilesLayout,
}

impl From<SectionTiles> for Section {
    fn from(value: SectionTiles) -> Self {
        Section::Tiles(value.into())
    }
}

/// Individual clickable tile.
///
/// See [`SectionTiles`].
#[derive(bon::Builder, Debug, Deserialize, Serialize)]
pub struct Tile {
    /// Primary text.
    pub header: Option<String>,
    /// Secondary text.
    pub subheader: Option<String>,
    /// What to do when clicked.
    pub motion: Option<Motion>,
    /// Both thumbnail and background.
    pub image: Option<Image>,
    /// Show text instead of thumbnail.
    pub body_text: Option<String>,
}

/// How to layout tiles.
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
pub enum TilesLayout {
    /// Scrolling shelf.
    HorizontalList,
    /// Scrolling list,
    VerticalList,
    /// Grid of tiles.
    Grid,
    /// Fallback.
    #[default]
    #[serde(other)]
    Unknown,
}