|
1 |
+ |
//! The projects screen, described rather than built.
|
|
2 |
+ |
//!
|
|
3 |
+ |
//! <!-- wiki: quasi-overview -->
|
|
4 |
+ |
//!
|
|
5 |
+ |
//! The proving ground for [`quasi_webview`], chosen 2026-08-08 over testing the
|
|
6 |
+ |
//! renderer against only an app written to make it pass. Behind the `quasi`
|
|
7 |
+ |
//! feature, which is off: nothing in a default build reaches this module, and
|
|
8 |
+ |
//! the shipped app is `frontend/js/projects.js` exactly as before.
|
|
9 |
+ |
//!
|
|
10 |
+ |
//! # What it is for
|
|
11 |
+ |
//!
|
|
12 |
+ |
//! Not to replace the screen. To find out what a real screen needs that the
|
|
13 |
+ |
//! description layer cannot say, while that is still cheap to fix. Two things
|
|
14 |
+ |
//! turned up immediately and are recorded in [`row_for`], because a finding
|
|
15 |
+ |
//! that lives only in a commit message is a finding nobody acts on.
|
|
16 |
+ |
//!
|
|
17 |
+ |
//! # The shape
|
|
18 |
+ |
//!
|
|
19 |
+ |
//! Three routes, which is the whole screen:
|
|
20 |
+ |
//!
|
|
21 |
+ |
//! - `GET /projects` — the document.
|
|
22 |
+ |
//! - `GET /projects/list` — the grid alone, which is what the two filters swap.
|
|
23 |
+ |
//! - `GET /projects/{id}` — the detail pane.
|
|
24 |
+ |
//!
|
|
25 |
+ |
//! The filters are routes rather than local state, per decision 2. `projects.js`
|
|
26 |
+ |
//! holds `showSharedOnly` and `showRetired` in module scope and re-renders from a
|
|
27 |
+ |
//! cached list; here they are query params, so the same screen is reachable by
|
|
28 |
+ |
//! address and no state has to survive between two clicks.
|
|
29 |
+ |
|
|
30 |
+ |
// Handlers take their params by value because `quasi_router::Handler` is a
|
|
31 |
+ |
// plain `fn(&S, Params)` pointer, so the signature is the router's and not a
|
|
32 |
+ |
// choice made here. Same allow, for the same reason, as quasi-axum's tests.
|
|
33 |
+ |
#![allow(clippy::needless_pass_by_value)]
|
|
34 |
+ |
|
|
35 |
+ |
use std::sync::Arc;
|
|
36 |
+ |
|
|
37 |
+ |
use goingson_core::{Project, ProjectStatus, ProjectType};
|
|
38 |
+ |
use quasi_router::screen::{Act, Row};
|
|
39 |
+ |
use quasi_router::{Action, Node, RegionKind, Response, RouteError, Router, Screen, Slot};
|
|
40 |
+ |
|
|
41 |
+ |
use crate::state::{AppState, DESKTOP_USER_ID};
|
|
42 |
+ |
|
|
43 |
+ |
#[cfg(test)]
|
|
44 |
+ |
mod tests;
|
|
45 |
+ |
|
|
46 |
+ |
/// Whether a project has stopped being worked on.
|
|
47 |
+ |
///
|
|
48 |
+ |
/// `projects.js:isRetired` reads the same two statuses. Duplicated rather than
|
|
49 |
+ |
/// shared because the JS is what ships; when this module replaces it, this is
|
|
50 |
+ |
/// the copy that survives.
|
|
51 |
+ |
fn retired(project: &Project) -> bool {
|
|
52 |
+ |
matches!(
|
|
53 |
+ |
project.status,
|
|
54 |
+ |
ProjectStatus::Completed | ProjectStatus::Archived
|
|
55 |
+ |
)
|
|
56 |
+ |
}
|
|
57 |
+ |
|
|
58 |
+ |
/// The display name of a project type.
|
|
59 |
+ |
fn type_label(project_type: &ProjectType) -> &'static str {
|
|
60 |
+ |
match project_type {
|
|
61 |
+ |
ProjectType::SideProject => "Side Project",
|
|
62 |
+ |
ProjectType::Job => "Job",
|
|
63 |
+ |
ProjectType::Company => "Company",
|
|
64 |
+ |
ProjectType::Essay => "Essay",
|
|
65 |
+ |
ProjectType::Article => "Article",
|
|
66 |
+ |
ProjectType::Painting => "Painting",
|
|
67 |
+ |
ProjectType::Other => "Other",
|
|
68 |
+ |
}
|
|
69 |
+ |
}
|
|
70 |
+ |
|
|
71 |
+ |
/// The display name of a project status.
|
|
72 |
+ |
fn status_label(status: &ProjectStatus) -> &'static str {
|
|
73 |
+ |
match status {
|
|
74 |
+ |
ProjectStatus::Active => "Active",
|
|
75 |
+ |
ProjectStatus::OnHold => "On Hold",
|
|
76 |
+ |
ProjectStatus::Completed => "Completed",
|
|
77 |
+ |
ProjectStatus::Archived => "Archived",
|
|
78 |
+ |
}
|
|
79 |
+ |
}
|
|
80 |
+ |
|
|
81 |
+ |
/// One project as a row.
|
|
82 |
+ |
///
|
|
83 |
+ |
/// # The two things the description cannot say
|
|
84 |
+ |
///
|
|
85 |
+ |
/// Both found here, on the first real screen, which is what the proving ground
|
|
86 |
+ |
/// was for.
|
|
87 |
+ |
///
|
|
88 |
+ |
/// **A row carries one trailing fact and this card has two.**
|
|
89 |
+ |
/// `makeover_layout::RowPart` is `Primary | Secondary | Meta | Actions`, taken
|
|
90 |
+ |
/// from Balanced Breakfast as the consumer that had all four. A project card
|
|
91 |
+ |
/// carries a type badge *and* a status badge, and the status badge is toned:
|
|
92 |
+ |
/// `projects.js` runs `statusTone(status)` and colours it. Joined into `meta`
|
|
93 |
+ |
/// here, which keeps both facts and loses the tone — a status reads as text
|
|
94 |
+ |
/// rather than as green or amber. `Node::Token` exists and says exactly the
|
|
95 |
+ |
/// right thing, but only as a node in its own right, never inside a row.
|
|
96 |
+ |
/// Naming it in `makeover-layout` first is what the admission test requires,
|
|
97 |
+ |
/// so this is a finding rather than a patch.
|
|
98 |
+ |
///
|
|
99 |
+ |
/// **A description carries text and this card carries markdown.**
|
|
100 |
+ |
/// `ProjectResponse::description_html` is `docengine::render_standard`, and the
|
|
101 |
+ |
/// card renders it as HTML. Nothing in the vocabulary names rich text, and it
|
|
102 |
+ |
/// should not be smuggled in as a string the renderer trusts — that is the one
|
|
103 |
+ |
/// door through which a description becomes a templating language. The raw
|
|
104 |
+ |
/// description goes into `secondary` as text. A `Region::Bespoke` is the
|
|
105 |
+ |
/// vocabulary's own answer for a place the app fills itself, and it is the
|
|
106 |
+ |
/// shape this wants if it turns out to matter.
|
|
107 |
+ |
fn row_for(project: &Project, selected: bool) -> Row {
|
|
108 |
+ |
let mut row = Row::new(&project.name).meta(format!(
|
|
109 |
+ |
"{} · {}",
|
|
110 |
+ |
type_label(&project.project_type),
|
|
111 |
+ |
status_label(&project.status)
|
|
112 |
+ |
));
|
|
113 |
+ |
|
|
114 |
+ |
if !project.description.is_empty() {
|
|
115 |
+ |
// Text, not the rendered HTML. See the note above.
|
|
116 |
+ |
row = row.secondary(&project.description);
|
|
117 |
+ |
}
|
|
118 |
+ |
|
|
119 |
+ |
row.selected = selected;
|
|
120 |
+ |
row.activate = Some(Action::get(format!("/projects/{}", project.id)));
|
|
121 |
+ |
row
|
|
122 |
+ |
}
|
|
123 |
+ |
|
|
124 |
+ |
/// The grid, filtered the way the screen's two toggles filter it.
|
|
125 |
+ |
fn grid(state: &AppState, shared_only: bool, show_retired: bool) -> Result<Node, RouteError> {
|
|
126 |
+ |
let all = state
|
|
127 |
+ |
.projects
|
|
128 |
+ |
.list_all(DESKTOP_USER_ID)
|
|
129 |
+ |
.map_err(|error| RouteError::internal(error.to_string()))?;
|
|
130 |
+ |
|
|
131 |
+ |
if all.is_empty() {
|
|
132 |
+ |
return Ok(Node::text("No projects yet."));
|
|
133 |
+ |
}
|
|
134 |
+ |
|
|
135 |
+ |
let scoped: Vec<&Project> = all
|
|
136 |
+ |
.iter()
|
|
137 |
+ |
.filter(|project| !shared_only || project.group_id.is_some())
|
|
138 |
+ |
.collect();
|
|
139 |
+ |
|
|
140 |
+ |
if scoped.is_empty() {
|
|
141 |
+ |
return Ok(Node::text(
|
|
142 |
+ |
"No shared projects yet. Share a project from its menu to see it here.",
|
|
143 |
+ |
));
|
|
144 |
+ |
}
|
|
145 |
+ |
|
|
146 |
+ |
let (live, dormant): (Vec<&Project>, Vec<&Project>) =
|
|
147 |
+ |
scoped.into_iter().partition(|project| !retired(project));
|
|
148 |
+ |
|
|
149 |
+ |
if live.is_empty() && !show_retired {
|
|
150 |
+ |
return Ok(Node::text("Every project is completed or archived."));
|
|
151 |
+ |
}
|
|
152 |
+ |
|
|
153 |
+ |
let shown = if show_retired {
|
|
154 |
+ |
live.into_iter().chain(dormant).collect::<Vec<_>>()
|
|
155 |
+ |
} else {
|
|
156 |
+ |
live
|
|
157 |
+ |
};
|
|
158 |
+ |
|
|
159 |
+ |
Ok(Node::list(
|
|
160 |
+ |
shown.into_iter().map(|project| row_for(project, false)),
|
|
161 |
+ |
))
|
|
162 |
+ |
}
|
|
163 |
+ |
|
|
164 |
+ |
/// How many projects are shared into a group, and how many are retired.
|
|
165 |
+ |
///
|
|
166 |
+ |
/// Both counts drive whether a control appears at all, so they are read once
|
|
167 |
+ |
/// per screen rather than per control.
|
|
168 |
+ |
fn counts(state: &AppState) -> Result<(usize, usize), RouteError> {
|
|
169 |
+ |
let all = state
|
|
170 |
+ |
.projects
|
|
171 |
+ |
.list_all(DESKTOP_USER_ID)
|
|
172 |
+ |
.map_err(|error| RouteError::internal(error.to_string()))?;
|
|
173 |
+ |
Ok((
|
|
174 |
+ |
all.iter().filter(|p| p.group_id.is_some()).count(),
|
|
175 |
+ |
all.iter().filter(|p| retired(p)).count(),
|
|
176 |
+ |
))
|
|
177 |
+ |
}
|
|
178 |
+ |
|
|
179 |
+ |
/// Whether a param is on. Absent is off, which is what a URL without it means.
|
|
180 |
+ |
fn flag(params: &quasi_router::Params, name: &str) -> bool {
|
|
181 |
+ |
matches!(params.get(name), Some("1" | "true"))
|
|
182 |
+ |
}
|
|
183 |
+ |
|
|
184 |
+ |
/// The address of the grid under a given pair of filters.
|
|
185 |
+ |
fn list_action(shared_only: bool, show_retired: bool) -> Action {
|
|
186 |
+ |
let mut action = Action::get("/projects/list");
|
|
187 |
+ |
if shared_only {
|
|
188 |
+ |
action = action.with("shared", "1");
|
|
189 |
+ |
}
|
|
190 |
+ |
if show_retired {
|
|
191 |
+ |
action = action.with("retired", "1");
|
|
192 |
+ |
}
|
|
193 |
+ |
action
|
|
194 |
+ |
}
|
|
195 |
+ |
|
|
196 |
+ |
/// The whole screen.
|
|
197 |
+ |
fn index(state: &AppState, params: quasi_router::Params) -> Result<Response, RouteError> {
|
|
198 |
+ |
let shared_only = flag(¶ms, "shared");
|
|
199 |
+ |
let show_retired = flag(¶ms, "retired");
|
|
200 |
+ |
let (shared, dormant) = counts(state)?;
|
|
201 |
+ |
|
|
202 |
+ |
let mut band = Slot::new("projects-band", RegionKind::Band)
|
|
203 |
+ |
.with(Node::page("Projects"))
|
|
204 |
+ |
.with(Node::act("New project", Action::get("/projects/new")));
|
|
205 |
+ |
|
|
206 |
+ |
// The filter surfaces only when sharing is in play, which is the rule
|
|
207 |
+ |
// `projects.js` already applies to the same control.
|
|
208 |
+ |
if shared > 0 || shared_only {
|
|
209 |
+ |
band = band.with(Node::Token {
|
|
210 |
+ |
kind: makeover_layout::Token::Chip { removable: false },
|
|
211 |
+ |
label: "Shared only".into(),
|
|
212 |
+ |
tone: makeover_layout::Tone::Neutral,
|
|
213 |
+ |
latched: shared_only,
|
|
214 |
+ |
action: Some(list_action(!shared_only, show_retired)),
|
|
215 |
+ |
});
|
|
216 |
+ |
}
|
|
217 |
+ |
|
|
218 |
+ |
if dormant > 0 {
|
|
219 |
+ |
band = band.with(Node::Act(Act::new(
|
|
220 |
+ |
if show_retired {
|
|
221 |
+ |
"Hide completed and archived".to_owned()
|
|
222 |
+ |
} else {
|
|
223 |
+ |
format!("Show {dormant} completed or archived")
|
|
224 |
+ |
},
|
|
225 |
+ |
list_action(shared_only, !show_retired),
|
|
226 |
+ |
)));
|
|
227 |
+ |
}
|
|
228 |
+ |
|
|
229 |
+ |
Ok(Screen::list_detail("Projects", false)
|
|
230 |
+ |
.with(band)
|
|
231 |
+ |
.with(Slot::new("projects-grid", RegionKind::Pane).with(grid(
|
|
232 |
+ |
state,
|
|
233 |
+ |
shared_only,
|
|
234 |
+ |
show_retired,
|
|
235 |
+ |
)?))
|
|
236 |
+ |
.with(Slot::new("projects-detail", RegionKind::Pane).with(Node::text("Nothing selected")))
|
|
237 |
+ |
.into())
|
|
238 |
+ |
}
|
|
239 |
+ |
|
|
240 |
+ |
/// The grid alone, which is what a filter toggle replaces.
|
|
241 |
+ |
fn list(state: &AppState, params: quasi_router::Params) -> Result<Response, RouteError> {
|
|
242 |
+ |
let node = grid(state, flag(¶ms, "shared"), flag(¶ms, "retired"))?;
|
|
243 |
+ |
Ok(Response::fragment("projects-grid", node))
|
|
244 |
+ |
}
|
|
245 |
+ |
|
|
246 |
+ |
/// One project's detail pane.
|
|
247 |
+ |
fn detail(state: &AppState, params: quasi_router::Params) -> Result<Response, RouteError> {
|
|
248 |
+ |
let id = params
|
|
249 |
+ |
.get("id")
|
|
250 |
+ |
.ok_or_else(|| RouteError::not_found("no project id"))?;
|
|
251 |
+ |
// `ProjectId` has no `FromStr`, only `From<Uuid>`, so the parse is the
|
|
252 |
+ |
// uuid crate's. Not worth adding one upstream for a single call site.
|
|
253 |
+ |
let id = goingson_core::ProjectId::from(
|
|
254 |
+ |
uuid::Uuid::parse_str(id).map_err(|_| RouteError::not_found("not a project id"))?,
|
|
255 |
+ |
);
|
|
256 |
+ |
|
|
257 |
+ |
let project = state
|
|
258 |
+ |
.projects
|
|
259 |
+ |
.get_by_id(id, DESKTOP_USER_ID)
|
|
260 |
+ |
.map_err(|error| RouteError::internal(error.to_string()))?
|
|
261 |
+ |
.ok_or_else(|| RouteError::not_found("no such project"))?;
|
|
262 |
+ |
|
|
263 |
+ |
let mut slot = Slot::new("projects-detail", RegionKind::Pane)
|
|
264 |
+ |
.with(Node::section(&project.name))
|
|
265 |
+ |
.with(Node::text(format!(
|
|
266 |
+ |
"{} · {}",
|
|
267 |
+ |
type_label(&project.project_type),
|
|
268 |
+ |
status_label(&project.status)
|
|
269 |
+ |
)));
|
|
270 |
+ |
|
|
271 |
+ |
if !project.description.is_empty() {
|
|
272 |
+ |
slot = slot.with(Node::text(&project.description));
|
|
273 |
+ |
}
|
|
274 |
+ |
|
|
275 |
+ |
slot = slot.with(Node::Act(
|
|
276 |
+ |
Act::new(
|
|
277 |
+ |
"Delete project",
|
|
278 |
+ |
Action::post(format!("/projects/{}/delete", project.id)),
|
|
279 |
+ |
)
|
|
280 |
+ |
.tone(makeover_layout::Tone::Danger),
|
|
281 |
+ |
));
|
|
282 |
+ |
|
|
283 |
+ |
Ok(Response::fragment("projects-detail", Node::Region(slot)))
|
|
284 |
+ |
}
|
|
285 |
+ |
|
|
286 |
+ |
/// The projects screen's routes.
|
|
287 |
+ |
#[must_use]
|
|
288 |
+ |
pub fn router() -> Router<AppState> {
|
|
289 |
+ |
Router::<AppState>::new()
|
|
290 |
+ |
.get("/projects", index)
|
|
291 |
+ |
.get("/projects/list", list)
|
|
292 |
+ |
.get("/projects/:id", detail)
|
|
293 |
+ |
}
|
|
294 |
+ |
|
|
295 |
+ |
/// The custom protocol serving the screen inside the app.
|
|
296 |
+ |
///
|
|
297 |
+ |
/// `quasi://localhost/projects`. The assets come from the same scheme, which is
|
|
298 |
+ |
/// the one thing that differs from the same description served over HTTP.
|
|
299 |
+ |
#[must_use]
|
|
300 |
+ |
pub fn protocol(state: Arc<AppState>) -> quasi_tauri::Protocol<AppState, quasi_webview::Webview> {
|
|
301 |
+ |
quasi_tauri::Protocol::new(
|
|
302 |
+ |
"quasi",
|
|
303 |
+ |
router(),
|
|
304 |
+ |
state,
|
|
305 |
+ |
Arc::new(
|
|
306 |
+ |
quasi_webview::Webview::under("quasi://localhost/static").with_shell(
|
|
307 |
+ |
quasi_webview::Shell::under("quasi://localhost/static")
|
|
308 |
+ |
.styled("/static/styles.css"),
|
|
309 |
+ |
),
|
|
310 |
+ |
),
|
|
311 |
+ |
)
|
|
312 |
+ |
}
|