1use super::{Chapter, FilterValue, Listing, Manga};
2use serde::{Deserialize, Serialize};
3
4extern crate alloc;
5use alloc::{string::String, vec::Vec};
6
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12pub enum HomePartialResult {
13 Layout(HomeLayout),
14 Component(HomeComponent),
15}
16
17#[derive(Default, Clone, Debug, PartialEq, Serialize, Deserialize)]
19pub struct HomeLayout {
20 pub components: Vec<HomeComponent>,
22}
23
24#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
26pub struct HomeComponent {
27 pub title: Option<String>,
29 pub subtitle: Option<String>,
31 pub value: HomeComponentValue,
33}
34
35impl Default for HomeComponent {
36 fn default() -> Self {
37 Self {
38 title: None,
39 subtitle: None,
40 value: HomeComponentValue::empty_scroller(),
41 }
42 }
43}
44
45#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
47pub enum HomeComponentValue {
48 ImageScroller {
52 links: Vec<Link>,
53 auto_scroll_interval: Option<f32>,
54 width: Option<i32>,
55 height: Option<i32>,
56 },
57 BigScroller {
62 entries: Vec<Manga>,
63 auto_scroll_interval: Option<f32>,
64 },
65 Scroller {
69 entries: Vec<Link>,
70 listing: Option<Listing>,
71 },
72 MangaList {
74 ranking: bool,
76 page_size: Option<i32>,
77 entries: Vec<Link>,
78 listing: Option<Listing>,
79 },
80 MangaChapterList {
84 page_size: Option<i32>,
85 entries: Vec<MangaWithChapter>,
86 listing: Option<Listing>,
87 },
88 Filters(Vec<FilterItem>),
90 Links(Vec<Link>),
94}
95
96impl HomeComponentValue {
97 pub fn empty_image_scroller() -> Self {
99 Self::ImageScroller {
100 links: Vec::new(),
101 auto_scroll_interval: None,
102 width: None,
103 height: None,
104 }
105 }
106
107 pub fn empty_big_scroller() -> Self {
109 Self::BigScroller {
110 entries: Vec::new(),
111 auto_scroll_interval: None,
112 }
113 }
114
115 pub fn empty_scroller() -> Self {
117 Self::Scroller {
118 entries: Vec::new(),
119 listing: None,
120 }
121 }
122
123 pub fn empty_manga_list() -> Self {
125 Self::MangaList {
126 ranking: false,
127 page_size: None,
128 entries: Vec::new(),
129 listing: None,
130 }
131 }
132
133 pub fn empty_manga_chapter_list() -> Self {
135 Self::MangaChapterList {
136 page_size: None,
137 entries: Vec::new(),
138 listing: None,
139 }
140 }
141
142 pub fn empty_filters() -> Self {
144 Self::Filters(Vec::new())
145 }
146
147 pub fn empty_links() -> Self {
149 Self::Links(Vec::new())
150 }
151}
152
153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
155pub struct MangaWithChapter {
156 pub manga: Manga,
157 pub chapter: Chapter,
158}
159
160#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
162pub struct FilterItem {
163 pub title: String,
164 pub values: Option<Vec<FilterValue>>,
165}
166
167impl From<String> for FilterItem {
168 fn from(title: String) -> Self {
169 Self {
170 title,
171 values: None,
172 }
173 }
174}
175
176impl From<&str> for FilterItem {
177 fn from(title: &str) -> Self {
178 Self {
179 title: String::from(title),
180 values: None,
181 }
182 }
183}
184
185#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
187pub struct Link {
188 pub title: String,
189 pub subtitle: Option<String>,
190 pub image_url: Option<String>,
191 pub value: Option<LinkValue>,
192}
193
194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
196pub enum LinkValue {
197 Url(String),
198 Listing(Listing),
199 Manga(Manga),
200}
201
202impl Default for LinkValue {
203 fn default() -> Self {
204 Self::Url(String::new())
205 }
206}
207
208impl From<Manga> for Link {
209 fn from(value: Manga) -> Self {
210 Link {
211 title: value.title.clone(),
212 subtitle: value
213 .authors
214 .as_ref()
215 .map(|a| a.join(", "))
216 .or(value.description.clone()),
217 image_url: value.cover.clone(),
218 value: Some(LinkValue::Manga(value)),
219 }
220 }
221}