| 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_router::screen::{Act, Row, Tag}; |
| 57 |
use quasi_router::{Action, Node, RegionKind, Slot}; |
| 58 |
use quasi_webview::Webview; |
| 59 |
|
| 60 |
use crate::types::ProjectCard; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
pub const REGION: &str = "user-projects"; |
| 67 |
|
| 68 |
|
| 69 |
const APPLY: &str = "/dashboard?tab=settings§ion=creator"; |
| 70 |
|
| 71 |
|
| 72 |
const NEW_PROJECT: &str = "/dashboard/new-project"; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
#[must_use] |
| 80 |
pub fn fragment(projects: &[ProjectCard], can_create_projects: bool) -> String { |
| 81 |
use quasi_axum::Serves as _; |
| 82 |
|
| 83 |
let mut slot = Slot::new(REGION, RegionKind::Pane); |
| 84 |
for node in body(projects, can_create_projects) { |
| 85 |
slot = slot.with(node); |
| 86 |
} |
| 87 |
Webview::new().fragment(&Node::Region(slot)) |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
#[must_use] |
| 94 |
pub fn fill(projects: &[ProjectCard], can_create_projects: bool) -> String { |
| 95 |
use quasi_axum::Serves as _; |
| 96 |
|
| 97 |
let mut out = String::new(); |
| 98 |
for node in body(projects, can_create_projects) { |
| 99 |
out.push_str(&Webview::new().fragment(&node)); |
| 100 |
} |
| 101 |
out |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
fn body(projects: &[ProjectCard], can_create_projects: bool) -> Vec<Node> { |
| 106 |
let mut out = vec![ |
| 107 |
Node::Link { |
| 108 |
text: "Docs: Projects".into(), |
| 109 |
action: Action::get("/docs/projects").navigating(), |
| 110 |
}, |
| 111 |
Node::section("Your Projects"), |
| 112 |
start_act(can_create_projects), |
| 113 |
]; |
| 114 |
|
| 115 |
if projects.is_empty() { |
| 116 |
out.push(getting_started(can_create_projects)); |
| 117 |
return out; |
| 118 |
} |
| 119 |
|
| 120 |
out.push(Node::list(projects.iter().map(card))); |
| 121 |
out |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
fn start_act(can_create_projects: bool) -> Node { |
| 129 |
if can_create_projects { |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
Node::act("New Project", Action::external(NEW_PROJECT)) |
| 135 |
} else { |
| 136 |
Node::act("Apply for Creator Access", Action::external(APPLY)) |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
fn card(project: &ProjectCard) -> Row { |
| 142 |
let mut meta = format!( |
| 143 |
"{} · Created {}", |
| 144 |
project.project_type, project.created_date |
| 145 |
); |
| 146 |
if let Some(updated) = &project.updated_date { |
| 147 |
meta.push_str(" · Last updated "); |
| 148 |
meta.push_str(updated); |
| 149 |
} |
| 150 |
|
| 151 |
let mut row = Row::new(project.title.clone()).meta(meta); |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
if !project.stats.is_empty() { |
| 158 |
row = row.meta(project.stats.clone()); |
| 159 |
} |
| 160 |
|
| 161 |
let mut badge = Tag::badge(project.status.clone()); |
| 162 |
badge.tone = tone(project.status_tone); |
| 163 |
|
| 164 |
row.token(badge) |
| 165 |
.act(Act::new( |
| 166 |
"View", |
| 167 |
Action::external(format!("/p/{}", project.slug)), |
| 168 |
)) |
| 169 |
.act(Act::new( |
| 170 |
"Edit", |
| 171 |
Action::external(format!("/dashboard/project/{}", project.slug)), |
| 172 |
)) |
| 173 |
.act( |
| 174 |
Act::new( |
| 175 |
"Delete", |
| 176 |
Action::delete(format!("/api/projects/{}", project.id)), |
| 177 |
) |
| 178 |
.tone(layout::Tone::Danger) |
| 179 |
.confirm("Delete this project? This cannot be undone."), |
| 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 |
|
| 200 |
fn getting_started(can_create_projects: bool) -> Node { |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
Node::Region( |
| 206 |
Slot::new("user-projects-getting-started", RegionKind::Pane) |
| 207 |
.with(Node::StandIn { |
| 208 |
state: layout::Readiness::Empty, |
| 209 |
message: "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 |
.into(), |
| 213 |
act: None, |
| 214 |
}) |
| 215 |
.with(Node::rich( |
| 216 |
"1. Create a project\n\ |
| 217 |
2. Add items: audio, video, text, or software\n\ |
| 218 |
3. Set prices (or keep them free) and publish\n\ |
| 219 |
4. Connect your payment account, 0% platform fee", |
| 220 |
)) |
| 221 |
.with(if can_create_projects { |
| 222 |
Node::act("Create Your First Project", Action::external(NEW_PROJECT)) |
| 223 |
} else { |
| 224 |
Node::act("Apply for Creator Access", Action::external(APPLY)) |
| 225 |
}), |
| 226 |
) |
| 227 |
} |
| 228 |
|
| 229 |
#[cfg(test)] |
| 230 |
mod tests { |
| 231 |
use super::*; |
| 232 |
use quasi_axum::Serves; |
| 233 |
|
| 234 |
fn project(title: &str) -> ProjectCard { |
| 235 |
ProjectCard { |
| 236 |
id: crate::db::ProjectId::from(uuid::Uuid::nil()), |
| 237 |
title: title.into(), |
| 238 |
project_type: "Album".into(), |
| 239 |
created_date: "Aug 1, 2026".into(), |
| 240 |
updated_date: Some("Aug 20, 2026".into()), |
| 241 |
stats: "3 items".into(), |
| 242 |
status: "Published".into(), |
| 243 |
status_tone: "success", |
| 244 |
slug: "an-album".into(), |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
fn render(nodes: &[Node]) -> String { |
| 249 |
let mut out = String::new(); |
| 250 |
for node in nodes { |
| 251 |
out.push_str(&Webview::new().fragment(node)); |
| 252 |
} |
| 253 |
out |
| 254 |
} |
| 255 |
|
| 256 |
#[test] |
| 257 |
fn the_strip_and_this_panel_agree_about_the_region() { |
| 258 |
|
| 259 |
|
| 260 |
let strip = include_str!("user_tabs.rs"); |
| 261 |
assert!(strip.contains("user_projects::REGION"), "{REGION}"); |
| 262 |
} |
| 263 |
|
| 264 |
#[test] |
| 265 |
fn no_quasi_route_answers_this_address_so_the_strip_must_still_fetch_it() { |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
assert!( |
| 273 |
!crate::quasi::PATHS.contains(&"/dashboard/tabs/projects"), |
| 274 |
"mounted now: give the Projects tab `screen: Some(..)` in user_tabs" |
| 275 |
); |
| 276 |
} |
| 277 |
|
| 278 |
#[test] |
| 279 |
fn a_project_offers_view_edit_and_a_confirmed_delete() { |
| 280 |
let html = render(&[Node::list([card(&project("An Album"))])]); |
| 281 |
|
| 282 |
assert!(html.contains("An Album"), "{html}"); |
| 283 |
assert!(html.contains("href=\"/p/an-album\""), "{html}"); |
| 284 |
assert!( |
| 285 |
html.contains("href=\"/dashboard/project/an-album\""), |
| 286 |
"{html}" |
| 287 |
); |
| 288 |
assert!( |
| 289 |
html.contains(&format!( |
| 290 |
"hx-delete=\"/api/projects/{}\"", |
| 291 |
crate::db::ProjectId::from(uuid::Uuid::nil()) |
| 292 |
)), |
| 293 |
"{html}" |
| 294 |
); |
| 295 |
assert!(html.contains("This cannot be undone."), "{html}"); |
| 296 |
} |
| 297 |
|
| 298 |
#[test] |
| 299 |
fn the_meta_line_drops_the_stats_part_rather_than_drawing_an_empty_one() { |
| 300 |
let mut bare = project("Bare"); |
| 301 |
bare.stats = String::new(); |
| 302 |
|
| 303 |
let with = render(&[Node::list([card(&project("With"))])]); |
| 304 |
let without = render(&[Node::list([card(&bare)])]); |
| 305 |
|
| 306 |
assert!(with.contains("3 items"), "{with}"); |
| 307 |
assert!(!without.contains("3 items"), "{without}"); |
| 308 |
|
| 309 |
assert!(without.contains("Created Aug 1, 2026"), "{without}"); |
| 310 |
} |
| 311 |
|
| 312 |
#[test] |
| 313 |
fn an_account_with_no_projects_gets_the_guide_and_no_empty_list() { |
| 314 |
let html = render(&body(&[], true)); |
| 315 |
|
| 316 |
assert!(html.contains("Welcome to Makenotwork."), "{html}"); |
| 317 |
assert!(html.contains("Create Your First Project"), "{html}"); |
| 318 |
|
| 319 |
|
| 320 |
assert!(!html.contains("role=\"list\""), "{html}"); |
| 321 |
} |
| 322 |
|
| 323 |
#[test] |
| 324 |
fn a_reader_who_cannot_create_projects_is_offered_the_application_instead() { |
| 325 |
let listed = render(&body(&[project("An Album")], false)); |
| 326 |
let empty = render(&body(&[], false)); |
| 327 |
|
| 328 |
for html in [&listed, &empty] { |
| 329 |
assert!(html.contains("Apply for Creator Access"), "{html}"); |
| 330 |
assert!(!html.contains("New Project"), "{html}"); |
| 331 |
assert!(!html.contains("Create Your First Project"), "{html}"); |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
#[test] |
| 336 |
fn a_project_title_cannot_smuggle_markup() { |
| 337 |
let html = render(&[Node::list([card(&project("<script>x()</script>"))])]); |
| 338 |
assert!(!html.contains("<script>x()"), "{html}"); |
| 339 |
} |
| 340 |
|
| 341 |
#[test] |
| 342 |
fn the_inline_fill_carries_no_region_because_the_strip_draws_one() { |
| 343 |
let inline = fill(&[project("An Album")], true); |
| 344 |
assert!(!inline.contains(&format!("id=\"{REGION}\"")), "{inline}"); |
| 345 |
assert!(inline.contains("An Album"), "{inline}"); |
| 346 |
} |
| 347 |
} |
| 348 |
|