| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
use makeover_layout as layout; |
| 56 |
use quasi_declare::declare; |
| 57 |
use quasi_router::screen::Tag; |
| 58 |
use quasi_router::{Node, RegionKind, Slot}; |
| 59 |
use quasi_webview::Webview; |
| 60 |
|
| 61 |
use crate::types::ProjectCard; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
pub const REGION: &str = "user-projects"; |
| 68 |
|
| 69 |
|
| 70 |
const APPLY: &str = "/dashboard?tab=settings§ion=creator"; |
| 71 |
|
| 72 |
|
| 73 |
const NEW_PROJECT: &str = "/dashboard/new-project"; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
#[must_use] |
| 81 |
pub fn fragment(projects: &[ProjectCard], can_create_projects: bool) -> String { |
| 82 |
use quasi_axum::Serves as _; |
| 83 |
|
| 84 |
let mut slot = Slot::new(REGION, RegionKind::Pane); |
| 85 |
for node in body(projects, can_create_projects) { |
| 86 |
slot = slot.with(node); |
| 87 |
} |
| 88 |
Webview::new().fragment(&Node::Region(slot)) |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
#[must_use] |
| 95 |
pub fn fill(projects: &[ProjectCard], can_create_projects: bool) -> String { |
| 96 |
use quasi_axum::Serves as _; |
| 97 |
|
| 98 |
let mut out = String::new(); |
| 99 |
for node in body(projects, can_create_projects) { |
| 100 |
out.push_str(&Webview::new().fragment(&node)); |
| 101 |
} |
| 102 |
out |
| 103 |
} |
| 104 |
|
| 105 |
declare! { |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
shape body(projects: &[ProjectCard], can_create_projects: bool) -> Vec<Node>; |
| 112 |
|
| 113 |
link "Docs: Projects" to get "/docs/projects" navigating; |
| 114 |
section "Your Projects"; |
| 115 |
include start_act(can_create_projects); |
| 116 |
|
| 117 |
include getting_started(can_create_projects) when projects.is_empty(); |
| 118 |
|
| 119 |
list { |
| 120 |
for project in projects.iter() { |
| 121 |
include card(project); |
| 122 |
} |
| 123 |
} unless projects.is_empty(); |
| 124 |
} |
| 125 |
|
| 126 |
declare! { |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
shape start_act(can_create_projects: bool) -> Node; |
| 136 |
|
| 137 |
given can_create_projects { |
| 138 |
true -> act "New Project" to external NEW_PROJECT; |
| 139 |
false -> act "Apply for Creator Access" to external APPLY; |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
fn made(project: &ProjectCard) -> String { |
| 149 |
let mut meta = format!( |
| 150 |
"{} ยท Created {}", |
| 151 |
project.project_type, project.created_date |
| 152 |
); |
| 153 |
if let Some(updated) = &project.updated_date { |
| 154 |
meta.push_str(" ยท Last updated "); |
| 155 |
meta.push_str(updated); |
| 156 |
} |
| 157 |
meta |
| 158 |
} |
| 159 |
|
| 160 |
declare! { |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
shape card(project: &ProjectCard) -> Row; |
| 168 |
|
| 169 |
row project.title.clone() { |
| 170 |
meta made(project); |
| 171 |
meta project.stats.clone() unless project.stats.is_empty(); |
| 172 |
token Tag::badge(project.status.clone()).tone(tone(project.status_tone)); |
| 173 |
|
| 174 |
act "View" to external "/p/{project.slug}"; |
| 175 |
act "Edit" to external "/dashboard/project/{project.slug}"; |
| 176 |
act "Delete" to delete "/api/projects/{project.id}" { |
| 177 |
tone Danger; |
| 178 |
confirm "Delete this project? This cannot be undone."; |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
fn tone(status_tone: &str) -> layout::Tone { |
| 190 |
match status_tone { |
| 191 |
"success" => layout::Tone::Success, |
| 192 |
"warning" => layout::Tone::Warning, |
| 193 |
"danger" => layout::Tone::Danger, |
| 194 |
"info" => layout::Tone::Info, |
| 195 |
_ => layout::Tone::Neutral, |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
declare! { |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
shape getting_started(can_create_projects: bool) -> Node; |
| 207 |
|
| 208 |
region "user-projects-getting-started" as Pane { |
| 209 |
empty "Welcome to Makenotwork. A project groups your work. Think of it as an \ |
| 210 |
album, podcast feed, or product line. Each project contains items: \ |
| 211 |
individual tracks, episodes, downloads, or posts."; |
| 212 |
|
| 213 |
include super::own_prose( |
| 214 |
"1. Create a project\n\ |
| 215 |
2. Add items: audio, video, text, or software\n\ |
| 216 |
3. Set prices (or keep them free) and publish\n\ |
| 217 |
4. Connect your payment account, 0% platform fee" |
| 218 |
); |
| 219 |
|
| 220 |
given can_create_projects { |
| 221 |
true -> act "Create Your First Project" to external NEW_PROJECT; |
| 222 |
false -> act "Apply for Creator Access" to external APPLY; |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
#[cfg(test)] |
| 228 |
mod tests { |
| 229 |
use super::*; |
| 230 |
use quasi_axum::Serves; |
| 231 |
|
| 232 |
fn project(title: &str) -> ProjectCard { |
| 233 |
ProjectCard { |
| 234 |
id: crate::db::ProjectId::from(uuid::Uuid::nil()), |
| 235 |
title: title.into(), |
| 236 |
project_type: "Album".into(), |
| 237 |
created_date: "Aug 1, 2026".into(), |
| 238 |
updated_date: Some("Aug 20, 2026".into()), |
| 239 |
stats: "3 items".into(), |
| 240 |
status: "Published".into(), |
| 241 |
status_tone: "success", |
| 242 |
slug: "an-album".into(), |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
fn render(nodes: &[Node]) -> String { |
| 247 |
let mut out = String::new(); |
| 248 |
for node in nodes { |
| 249 |
out.push_str(&Webview::new().fragment(node)); |
| 250 |
} |
| 251 |
out |
| 252 |
} |
| 253 |
|
| 254 |
#[test] |
| 255 |
fn the_strip_and_this_panel_agree_about_the_region() { |
| 256 |
|
| 257 |
|
| 258 |
let strip = include_str!("user_tabs.rs"); |
| 259 |
assert!(strip.contains("user_projects::REGION"), "{REGION}"); |
| 260 |
} |
| 261 |
|
| 262 |
#[test] |
| 263 |
fn no_quasi_route_answers_this_address_so_the_strip_must_still_fetch_it() { |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
assert!( |
| 271 |
!crate::quasi::PATHS.contains(&"/dashboard/tabs/projects"), |
| 272 |
"mounted now: give the Projects tab `screen: Some(..)` in user_tabs" |
| 273 |
); |
| 274 |
} |
| 275 |
|
| 276 |
#[test] |
| 277 |
fn a_project_offers_view_edit_and_a_confirmed_delete() { |
| 278 |
let html = render(&[Node::list([card(&project("An Album"))])]); |
| 279 |
|
| 280 |
assert!(html.contains("An Album"), "{html}"); |
| 281 |
assert!(html.contains("href=\"/p/an-album\""), "{html}"); |
| 282 |
assert!( |
| 283 |
html.contains("href=\"/dashboard/project/an-album\""), |
| 284 |
"{html}" |
| 285 |
); |
| 286 |
assert!( |
| 287 |
html.contains(&format!( |
| 288 |
"hx-delete=\"/api/projects/{}\"", |
| 289 |
crate::db::ProjectId::from(uuid::Uuid::nil()) |
| 290 |
)), |
| 291 |
"{html}" |
| 292 |
); |
| 293 |
assert!(html.contains("This cannot be undone."), "{html}"); |
| 294 |
} |
| 295 |
|
| 296 |
#[test] |
| 297 |
fn the_meta_line_drops_the_stats_part_rather_than_drawing_an_empty_one() { |
| 298 |
let mut bare = project("Bare"); |
| 299 |
bare.stats = String::new(); |
| 300 |
|
| 301 |
let with = render(&[Node::list([card(&project("With"))])]); |
| 302 |
let without = render(&[Node::list([card(&bare)])]); |
| 303 |
|
| 304 |
assert!(with.contains("3 items"), "{with}"); |
| 305 |
assert!(!without.contains("3 items"), "{without}"); |
| 306 |
|
| 307 |
assert!(without.contains("Created Aug 1, 2026"), "{without}"); |
| 308 |
} |
| 309 |
|
| 310 |
#[test] |
| 311 |
fn an_account_with_no_projects_gets_the_guide_and_no_empty_list() { |
| 312 |
let html = render(&body(&[], true)); |
| 313 |
|
| 314 |
assert!(html.contains("Welcome to Makenotwork."), "{html}"); |
| 315 |
assert!(html.contains("Create Your First Project"), "{html}"); |
| 316 |
|
| 317 |
|
| 318 |
assert!(!html.contains("role=\"list\""), "{html}"); |
| 319 |
} |
| 320 |
|
| 321 |
#[test] |
| 322 |
fn a_reader_who_cannot_create_projects_is_offered_the_application_instead() { |
| 323 |
let listed = render(&body(&[project("An Album")], false)); |
| 324 |
let empty = render(&body(&[], false)); |
| 325 |
|
| 326 |
for html in [&listed, &empty] { |
| 327 |
assert!(html.contains("Apply for Creator Access"), "{html}"); |
| 328 |
assert!(!html.contains("New Project"), "{html}"); |
| 329 |
assert!(!html.contains("Create Your First Project"), "{html}"); |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
#[test] |
| 334 |
fn a_project_title_cannot_smuggle_markup() { |
| 335 |
let html = render(&[Node::list([card(&project("<script>x()</script>"))])]); |
| 336 |
assert!(!html.contains("<script>x()"), "{html}"); |
| 337 |
} |
| 338 |
|
| 339 |
#[test] |
| 340 |
fn the_inline_fill_carries_no_region_because_the_strip_draws_one() { |
| 341 |
let inline = fill(&[project("An Album")], true); |
| 342 |
assert!(!inline.contains(&format!("id=\"{REGION}\"")), "{inline}"); |
| 343 |
assert!(inline.contains("An Album"), "{inline}"); |
| 344 |
} |
| 345 |
} |
| 346 |
|