| 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 |
#![allow(clippy::needless_pass_by_value)] |
| 49 |
|
| 50 |
use std::collections::HashMap; |
| 51 |
|
| 52 |
use quasi_declare::declare; |
| 53 |
use quasi_notifs::pane; |
| 54 |
use quasi_router::layout::{Contrast, ThemeVariant}; |
| 55 |
use quasi_router::screen::{Choice, ThemeChoice}; |
| 56 |
use quasi_router::{Action, Node, RegionKind, Response, RouteError, Router, Slot}; |
| 57 |
|
| 58 |
use crate::notifs::NOTIFS; |
| 59 |
|
| 60 |
use crate::commands::{all_config, write_config}; |
| 61 |
use crate::state::AppState; |
| 62 |
|
| 63 |
pub(crate) mod about; |
| 64 |
pub(crate) mod email; |
| 65 |
pub(crate) mod sharing; |
| 66 |
pub(crate) mod sync; |
| 67 |
|
| 68 |
#[cfg(test)] |
| 69 |
mod tests; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
const SECTION_REGION: &str = "settings-content"; |
| 76 |
|
| 77 |
|
| 78 |
struct Section { |
| 79 |
|
| 80 |
slug: &'static str, |
| 81 |
|
| 82 |
title: &'static str, |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
at: Option<&'static str>, |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
const SECTIONS: [Section; 8] = [ |
| 108 |
Section { |
| 109 |
slug: "appearance", |
| 110 |
title: "Appearance", |
| 111 |
at: None, |
| 112 |
}, |
| 113 |
Section { |
| 114 |
slug: "notifications", |
| 115 |
title: "Notifications", |
| 116 |
at: None, |
| 117 |
}, |
| 118 |
Section { |
| 119 |
slug: "planning", |
| 120 |
title: "Planning & Review", |
| 121 |
at: None, |
| 122 |
}, |
| 123 |
|
| 124 |
|
| 125 |
Section { |
| 126 |
slug: "email", |
| 127 |
title: "Email", |
| 128 |
at: None, |
| 129 |
}, |
| 130 |
|
| 131 |
|
| 132 |
Section { |
| 133 |
slug: "data", |
| 134 |
title: "Import & Export", |
| 135 |
at: Some("/data"), |
| 136 |
}, |
| 137 |
|
| 138 |
Section { |
| 139 |
slug: "about", |
| 140 |
title: "About", |
| 141 |
at: None, |
| 142 |
}, |
| 143 |
|
| 144 |
Section { |
| 145 |
slug: "sync", |
| 146 |
title: "Sync", |
| 147 |
at: None, |
| 148 |
}, |
| 149 |
|
| 150 |
Section { |
| 151 |
slug: "sharing", |
| 152 |
title: "Sharing", |
| 153 |
at: None, |
| 154 |
}, |
| 155 |
]; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
fn default_for(key: &str) -> &'static str { |
| 163 |
match key { |
| 164 |
"theme" => "system", |
| 165 |
"event_lead_minutes" => "15", |
| 166 |
"work_start_hour" => "9", |
| 167 |
"work_end_hour" => "17", |
| 168 |
|
| 169 |
|
| 170 |
_ => "enabled", |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
fn value_of<'a>(config: &'a HashMap<String, String>, key: &str) -> &'a str { |
| 176 |
config.get(key).map_or_else( |
| 177 |
|| { |
| 178 |
|
| 179 |
default_for(key) |
| 180 |
}, |
| 181 |
String::as_str, |
| 182 |
) |
| 183 |
} |
| 184 |
|
| 185 |
declare! { |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
shape choice_field( |
| 195 |
config: &HashMap<String, String>, |
| 196 |
key: &'static str, |
| 197 |
label: &str, |
| 198 |
choices: Vec<Choice>, |
| 199 |
) -> Field; |
| 200 |
|
| 201 |
field Select key label { |
| 202 |
options choices; |
| 203 |
value value_of(config, key); |
| 204 |
writes Action::post("/settings/config/{key}"); |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
fn theme_choices(app: &AppState) -> Vec<ThemeChoice> { |
| 224 |
makeover::theme_options(&app.theme_dirs) |
| 225 |
.into_iter() |
| 226 |
.map(|theme| { |
| 227 |
ThemeChoice::new( |
| 228 |
theme.id, |
| 229 |
theme.name, |
| 230 |
variant_of(theme.variant), |
| 231 |
tier_of(theme.contrast), |
| 232 |
) |
| 233 |
}) |
| 234 |
.collect() |
| 235 |
} |
| 236 |
|
| 237 |
declare! { |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
shape theme_field(app: &AppState, config: &HashMap<String, String>) -> Field; |
| 251 |
|
| 252 |
field Theme "theme" "Theme" { |
| 253 |
themes theme_choices(app); |
| 254 |
following Choice::new(makeover::FOLLOW, "Follow System"); |
| 255 |
value value_of(config, "theme"); |
| 256 |
writes Action::post("/settings/config/theme"); |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
fn variant_of(variant: makeover::Variant) -> ThemeVariant { |
| 268 |
match variant { |
| 269 |
makeover::Variant::Light => ThemeVariant::Light, |
| 270 |
makeover::Variant::Dark => ThemeVariant::Dark, |
| 271 |
makeover::Variant::HighContrast => ThemeVariant::HighContrast, |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
fn tier_of(tier: makeover::ContrastTier) -> Contrast { |
| 279 |
match tier { |
| 280 |
makeover::ContrastTier::Low => Contrast::Low, |
| 281 |
makeover::ContrastTier::Standard => Contrast::Standard, |
| 282 |
makeover::ContrastTier::High => Contrast::High, |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
declare! { |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
shape appearance(app: &AppState, config: &HashMap<String, String>) -> Vec<Node>; |
| 317 |
|
| 318 |
section "Appearance"; |
| 319 |
include theme_field(app, config); |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
fn lead_choices() -> Vec<Choice> { |
| 328 |
[5, 10, 15, 30, 60] |
| 329 |
.into_iter() |
| 330 |
.map(|minutes| { |
| 331 |
let label = if minutes == 60 { |
| 332 |
"1 hour".to_owned() |
| 333 |
} else { |
| 334 |
format!("{minutes} minutes") |
| 335 |
}; |
| 336 |
let label = if minutes == 15 { |
| 337 |
format!("{label} (default)") |
| 338 |
} else { |
| 339 |
label |
| 340 |
}; |
| 341 |
Choice::new(minutes.to_string(), label) |
| 342 |
}) |
| 343 |
.collect() |
| 344 |
} |
| 345 |
|
| 346 |
declare! { |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
shape notifications(config: &HashMap<String, String>) -> Vec<Node>; |
| 378 |
|
| 379 |
section "Notifications"; |
| 380 |
include pane::pane(&NOTIFS, config, &Action::post("/settings/notifications")); |
| 381 |
|
| 382 |
section "Events tab"; |
| 383 |
field Select "event_lead_minutes" "Event indicator lead time" { |
| 384 |
options lead_choices(); |
| 385 |
value value_of(config, "event_lead_minutes"); |
| 386 |
hint "How far in advance the Events tab dot turns yellow. This is the \ |
| 387 |
indicator, not a notification."; |
| 388 |
writes Action::post("/settings/config/event_lead_minutes"); |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
fn hour_choices() -> Vec<Choice> { |
| 397 |
(0..24) |
| 398 |
.map(|hour| { |
| 399 |
let label = match hour { |
| 400 |
0 => "12:00 AM".to_owned(), |
| 401 |
1..=11 => format!("{hour}:00 AM"), |
| 402 |
12 => "12:00 PM".to_owned(), |
| 403 |
_ => format!("{}:00 PM", hour - 12), |
| 404 |
}; |
| 405 |
Choice::new(hour.to_string(), label) |
| 406 |
}) |
| 407 |
.collect() |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
fn on_off() -> Vec<Choice> { |
| 412 |
vec![ |
| 413 |
Choice::new("enabled", "Enabled (default)"), |
| 414 |
Choice::new("disabled", "Disabled"), |
| 415 |
] |
| 416 |
} |
| 417 |
|
| 418 |
declare! { |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
shape planning(config: &HashMap<String, String>) -> Vec<Node>; |
| 427 |
|
| 428 |
section "Planning & Review"; |
| 429 |
|
| 430 |
include choice_field(config, "work_start_hour", "Work day starts", hour_choices()) |
| 431 |
.hint("Controls when plan and review nudge dots appear."); |
| 432 |
include choice_field(config, "work_end_hour", "Work day ends", hour_choices()); |
| 433 |
include choice_field(config, "plan_nudges", "Plan nudges", on_off()); |
| 434 |
include choice_field(config, "review_nudges", "Review nudges", on_off()); |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
fn section_of(slug: &str) -> Result<&'static Section, RouteError> { |
| 444 |
SECTIONS |
| 445 |
.iter() |
| 446 |
.find(|section| section.at.is_none() && section.slug == slug) |
| 447 |
.ok_or_else(|| RouteError::not_found("no such settings section")) |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
fn section_for_key(key: &str) -> &'static str { |
| 457 |
match key { |
| 458 |
"event_lead_minutes" => "notifications", |
| 459 |
"work_start_hour" | "work_end_hour" | "plan_nudges" | "review_nudges" => "planning", |
| 460 |
_ => "appearance", |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
fn section_path(section: &Section) -> String { |
| 469 |
section |
| 470 |
.at |
| 471 |
.map_or_else(|| format!("/settings/{}", section.slug), ToOwned::to_owned) |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
fn is_showing(item: &Section, section: &Section) -> bool { |
| 480 |
item.at.is_none() && item.slug == section.slug |
| 481 |
} |
| 482 |
|
| 483 |
|
| 484 |
struct Showing { |
| 485 |
section: &'static Section, |
| 486 |
body: Vec<Node>, |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
fn read(state: &AppState, slug: &str) -> Result<Showing, RouteError> { |
| 496 |
let section = section_of(slug)?; |
| 497 |
let config = all_config(state).map_err(|error| RouteError::internal(error.to_string()))?; |
| 498 |
let body = match section.slug { |
| 499 |
"notifications" => notifications(&config), |
| 500 |
"planning" => planning(&config), |
| 501 |
"email" => email::pane(&email::accounts(state)?), |
| 502 |
"about" => about::pane(state), |
| 503 |
"sync" => sync::pane(state), |
| 504 |
"sharing" => sharing::sharing_pane(&sharing::read(state)?), |
| 505 |
_ => appearance(state, &config), |
| 506 |
}; |
| 507 |
Ok(Showing { section, body }) |
| 508 |
} |
| 509 |
|
| 510 |
declare! { |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
pub(super) shape screen(section: &Section, body: Vec<Node>) -> Screen; |
| 515 |
|
| 516 |
screen sidebar_content "Settings" { |
| 517 |
at_place super::shell::SETTINGS; |
| 518 |
|
| 519 |
region "settings-nav" as Sidebar { |
| 520 |
list { |
| 521 |
for item in SECTIONS.iter() { |
| 522 |
row item.title { |
| 523 |
current is_showing(item, section); |
| 524 |
activate to get section_path(item); |
| 525 |
} |
| 526 |
} |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
region SECTION_REGION as Pane { |
| 531 |
extend body; |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
|
| 537 |
pub(super) fn showing(state: &AppState, slug: &str) -> Result<Response, RouteError> { |
| 538 |
let showing = read(state, slug)?; |
| 539 |
Ok(screen(showing.section, showing.body).into()) |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
fn index(state: &AppState, _request: quasi_router::Request) -> Result<Response, RouteError> { |
| 544 |
showing(state, "appearance") |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
fn set_update_check( |
| 553 |
state: &AppState, |
| 554 |
request: quasi_router::Request, |
| 555 |
) -> Result<Response, RouteError> { |
| 556 |
let on = request.payload.get(about::UPDATE_CHECK).unwrap_or_default() != "disabled"; |
| 557 |
let said = about::write(state, on)?; |
| 558 |
Ok(Response::fragment( |
| 559 |
SECTION_REGION, |
| 560 |
Node::Region(Slot::new(SECTION_REGION, RegionKind::Pane).extend(about::pane(state))), |
| 561 |
) |
| 562 |
.toast(quasi_router::layout::Tone::Success, said)) |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
fn sync_pane(state: &AppState, said: String) -> Result<Response, RouteError> { |
| 571 |
Ok(Response::fragment( |
| 572 |
SECTION_REGION, |
| 573 |
Node::Region(Slot::new(SECTION_REGION, RegionKind::Pane).extend(sync::pane(state))), |
| 574 |
) |
| 575 |
.toast(quasi_router::layout::Tone::Success, said)) |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
fn sharing_pane(state: &AppState, said: &str) -> Result<Response, RouteError> { |
| 583 |
Ok(Response::fragment( |
| 584 |
SECTION_REGION, |
| 585 |
Node::Region( |
| 586 |
Slot::new(SECTION_REGION, RegionKind::Pane) |
| 587 |
.extend(sharing::sharing_pane(&sharing::read(state)?)), |
| 588 |
), |
| 589 |
) |
| 590 |
.toast(quasi_router::layout::Tone::Success, said)) |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
fn queue_group(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 595 |
let said = sharing::create_group(state, &request)?; |
| 596 |
sharing_pane(state, said) |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
fn queue_member(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 601 |
let said = sharing::add_member(state, &request)?; |
| 602 |
sharing_pane(state, said) |
| 603 |
} |
| 604 |
|
| 605 |
|
| 606 |
fn cancel_queued(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 607 |
let said = sharing::cancel(state, &request)?; |
| 608 |
sharing_pane(state, said) |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
fn queue_invite(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 613 |
let said = sharing::create_invite(state, &request)?; |
| 614 |
sharing_pane(state, said) |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
fn queue_revoke(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 619 |
let said = sharing::revoke_invite(state, &request)?; |
| 620 |
sharing_pane(state, said) |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
fn queue_confirm(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 625 |
let said = sharing::confirm_invite(state, &request)?; |
| 626 |
sharing_pane(state, said) |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
fn queue_preview(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 631 |
let said = sharing::preview_invite(state, &request)?; |
| 632 |
sharing_pane(state, said) |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
fn queue_accept(state: &AppState, _request: quasi_router::Request) -> Result<Response, RouteError> { |
| 637 |
let said = sharing::accept_invite(state)?; |
| 638 |
sharing_pane(state, said) |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
fn drop_preview(state: &AppState, _request: quasi_router::Request) -> Result<Response, RouteError> { |
| 643 |
let said = sharing::dismiss_preview(state)?; |
| 644 |
sharing_pane(state, said) |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
fn set_sync_auto(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 649 |
let on = request.payload.get(sync::AUTO_SYNC).unwrap_or_default() != "disabled"; |
| 650 |
let said = sync::set_auto(state, on)?; |
| 651 |
sync_pane(state, said.to_owned()) |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
fn set_sync_interval( |
| 656 |
state: &AppState, |
| 657 |
request: quasi_router::Request, |
| 658 |
) -> Result<Response, RouteError> { |
| 659 |
let minutes = request |
| 660 |
.payload |
| 661 |
.get(sync::INTERVAL) |
| 662 |
.unwrap_or_default() |
| 663 |
.parse() |
| 664 |
.unwrap_or(5); |
| 665 |
let said = sync::set_interval(state, minutes)?; |
| 666 |
sync_pane(state, said) |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
fn disconnect_sync( |
| 671 |
state: &AppState, |
| 672 |
_request: quasi_router::Request, |
| 673 |
) -> Result<Response, RouteError> { |
| 674 |
let said = sync::disconnect(state)?; |
| 675 |
sync_pane(state, said.to_owned()) |
| 676 |
} |
| 677 |
|
| 678 |
|
| 679 |
fn section(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 680 |
let slug = request |
| 681 |
.captures |
| 682 |
.get("section") |
| 683 |
.ok_or_else(|| RouteError::not_found("no section"))?; |
| 684 |
showing(state, slug) |
| 685 |
} |
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
fn set(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 704 |
let key = request |
| 705 |
.captures |
| 706 |
.get("key") |
| 707 |
.ok_or_else(|| RouteError::not_found("no config key"))? |
| 708 |
.to_owned(); |
| 709 |
let value = request |
| 710 |
.payload |
| 711 |
.get(Node::SELECTED) |
| 712 |
.ok_or_else(|| RouteError::internal("the control sent no value"))?; |
| 713 |
|
| 714 |
write_config(state, &key, value).map_err(|error| RouteError::internal(error.to_string()))?; |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
showing(state, section_for_key(&key)) |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
fn set_notifications( |
| 736 |
state: &AppState, |
| 737 |
request: quasi_router::Request, |
| 738 |
) -> Result<Response, RouteError> { |
| 739 |
for kind in NOTIFS.kinds() { |
| 740 |
let key = quasi_notifs::config::enabled_key(kind.id); |
| 741 |
let on = request |
| 742 |
.payload |
| 743 |
.get(key.as_str()) |
| 744 |
.is_some_and(|v| v == "true"); |
| 745 |
write_config(state, &key, &on.to_string()) |
| 746 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
for knob in kind.options { |
| 753 |
let key = quasi_notifs::config::knob_key(kind.id, knob.id); |
| 754 |
if let Some(value) = request.payload.get(key.as_str()) { |
| 755 |
write_config(state, &key, value) |
| 756 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 757 |
} |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
showing(state, "notifications") |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
#[must_use] |
| 766 |
pub fn routes(router: Router<AppState>) -> Router<AppState> { |
| 767 |
let router = router |
| 768 |
.get("/settings", index) |
| 769 |
.post("/settings/config/{key}", set) |
| 770 |
.post("/settings/notifications", set_notifications); |
| 771 |
|
| 772 |
|
| 773 |
let router = email::routes(router) |
| 774 |
.post("/settings/about/update-check", set_update_check) |
| 775 |
.post("/settings/sync/auto", set_sync_auto) |
| 776 |
.post("/settings/sync/interval", set_sync_interval) |
| 777 |
.post("/settings/sync/disconnect", disconnect_sync) |
| 778 |
|
| 779 |
|
| 780 |
.post("/settings/sharing/groups", queue_group) |
| 781 |
.post("/settings/sharing/members", queue_member) |
| 782 |
.post("/settings/sharing/queue/{id}/cancel", cancel_queued) |
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
.post("/settings/sharing/invites/preview", queue_preview) |
| 788 |
.post("/settings/sharing/invites/accept", queue_accept) |
| 789 |
.post("/settings/sharing/invites/dismiss", drop_preview) |
| 790 |
.post("/settings/sharing/invites", queue_invite) |
| 791 |
.post( |
| 792 |
"/settings/sharing/invites/{group_id}/{invitation_id}/revoke", |
| 793 |
queue_revoke, |
| 794 |
) |
| 795 |
.post( |
| 796 |
"/settings/sharing/invites/{group_id}/{invitation_id}/confirm", |
| 797 |
queue_confirm, |
| 798 |
); |
| 799 |
router.get("/settings/{section}", section) |
| 800 |
} |
| 801 |
|