neiam
/recourse
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
Log in to mark this repository.
Visual mode: category focus view, topic reader, list/visual preference
da3a685 · gmorell · 2026-12-02 18:25
Message
{commit_body(@commit)}
Files changed
modified
README.md
+27
−0
| 77 | 77 | | `OIDC_ENABLED`, `OIDC_LOGIN_MODE`, `OIDC_*` | off | "Sign in with NEIAM"; see below and the neiam-auth README | |
| 78 | 78 | | `OIDC_PASSWORD_LOGIN` | `true` | `false` hides and refuses password login (implied by `OIDC_LOGIN_MODE=sso_strict`) | |
| 79 | 79 | |
| 80 | +## Visual mode | |
| 81 | + | |
| 82 | +Every category and the home page have a **List / Visual** switch. The choice | |
| 83 | +sticks: on the account when signed in (`users.preferred_view`, like the topic | |
| 84 | +sort), in a `recourse_view` cookie when not; `?view=list|focus` in any URL | |
| 85 | +overrides it. | |
| 86 | + | |
| 87 | +- **`/c/{slug}?view=focus&sort=…`** — the category fills the page. The | |
| 88 | + categories beside it are squares on a rail (the current one has the accent | |
| 89 | + border; on small screens the rail is a horizontal strip), and `..` goes up a | |
| 90 | + level, or to the visual home from a top-level category. The category's own | |
| 91 | + topics are tiles: title, poster and top-replier avatars, replies, views, | |
| 92 | + last activity, tags, reactions, and **new** / **N unread** for signed-in | |
| 93 | + users. Each subcategory is a column of compact topic squares with a "Focus | |
| 94 | + on …" link. Categories the viewer may not see never appear, on the rail or | |
| 95 | + anywhere else. | |
| 96 | +- **`&topic=<id>`** opens the **reader** over the focus view: the topic's posts | |
| 97 | + and a filmstrip of the category's topics in the current sort. **← / →** | |
| 98 | + (or **k / j**) step through them, **Escape** or a click outside closes it, | |
| 99 | + and every step is a URL, so the back button works. Opening a topic in the | |
| 100 | + reader counts a view and marks it read, exactly as the topic page does. | |
| 101 | +- **`/?view=focus`** — the home page as a grid of top-level category tiles, | |
| 102 | + each with its subcategories and latest topics. | |
| 103 | + | |
| 104 | +Modelled on pin_flip's board focus mode and shared pages, and on cartosnap's | |
| 105 | +shared-trip stepping; see `src/handlers/focus.rs`. | |
| 106 | + | |
| 80 | 107 | ## Email verification |
| 81 | 108 | |
| 82 | 109 | New accounts (registration through an invite) start **unverified**: they can |
modified
assets/f/js/src.js
+56
−0
| 23 | 23 | if (ttl > 0) setTimeout(() => alert.remove(), ttl); |
| 24 | 24 | return alert; |
| 25 | 25 | }; |
| 26 | + | |
| 27 | +// Visual mode reader (templates/forum/_reader.html): ←/→ or k/j step through | |
| 28 | +// the category's topics, Escape closes, as cartosnap's shared trip pages | |
| 29 | +// photos and pin_flip's lightbox. The buttons do the work (they swap #reader | |
| 30 | +// and push the URL), so the keys only click them. Ignored while typing. | |
| 31 | +const READER_KEYS = { | |
| 32 | + ArrowRight: "reader-next", | |
| 33 | + j: "reader-next", | |
| 34 | + ArrowLeft: "reader-prev", | |
| 35 | + k: "reader-prev", | |
| 36 | + Escape: "reader-close", | |
| 37 | +}; | |
| 38 | +document.addEventListener("keydown", (e) => { | |
| 39 | + if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return; | |
| 40 | + if (!document.querySelector("#reader [data-reader]")) return; | |
| 41 | + const t = e.target; | |
| 42 | + if (t instanceof Element && t.closest("input, textarea, select, [contenteditable]")) return; | |
| 43 | + const id = READER_KEYS[e.key]; | |
| 44 | + const el = id && document.getElementById(id); | |
| 45 | + if (!el) return; | |
| 46 | + e.preventDefault(); | |
| 47 | + el.click(); | |
| 48 | +}); | |
| 49 | + | |
| 50 | +// After the reader swaps in: move focus into it, show the current topic in | |
| 51 | +// the filmstrip, and stop the page behind it scrolling. On close, give focus | |
| 52 | +// back to the tile that was open. | |
| 53 | +let readerOpener = null; | |
| 54 | +document.addEventListener("htmx:afterSettle", (e) => { | |
| 55 | + const reader = document.querySelector("#reader [data-reader]"); | |
| 56 | + document.documentElement.classList.toggle("overflow-hidden", !!reader); | |
| 57 | + if (reader) { | |
| 58 | + const id = reader.dataset.reader; | |
| 59 | + readerOpener = id; | |
| 60 | + document.getElementById("reader-title")?.focus({ preventScroll: true }); | |
| 61 | + document.getElementById(`strip-${id}`)?.scrollIntoView({ block: "nearest", inline: "center" }); | |
| 62 | + document.getElementById("reader-posts")?.scrollTo(0, 0); | |
| 63 | + } else if (readerOpener && e.detail.target?.id === "reader") { | |
| 64 | + const tile = document.querySelector(`[data-topic="${readerOpener}"]`); | |
| 65 | + readerOpener = null; | |
| 66 | + tile?.focus({ preventScroll: false }); | |
| 67 | + } | |
| 68 | +}); | |
| 69 | +// A reader opened from the URL (?topic=) on a full page load. | |
| 70 | +document.addEventListener("DOMContentLoaded", () => { | |
| 71 | + const reader = document.querySelector("#reader [data-reader]"); | |
| 72 | + if (!reader) return; | |
| 73 | + document.documentElement.classList.add("overflow-hidden"); | |
| 74 | + readerOpener = reader.dataset.reader; | |
| 75 | + document.getElementById("reader-title")?.focus({ preventScroll: true }); | |
| 76 | + document.getElementById(`strip-${reader.dataset.reader}`)?.scrollIntoView({ block: "nearest", inline: "center" }); | |
| 77 | +}); | |
| 78 | +// Back/forward restores a snapshot without settling: re-sync the scroll lock. | |
| 79 | +document.addEventListener("htmx:historyRestore", () => { | |
| 80 | + document.documentElement.classList.toggle("overflow-hidden", !!document.querySelector("#reader [data-reader]")); | |
| 81 | +}); |
modified
migration/src/lib.rs
+4
−0
| 15 | 15 | mod m20240101_000013_user_trust_level; |
| 16 | 16 | mod m20240101_000014_category_min_trust; |
| 17 | 17 | mod m20240101_000015_email_verification; |
| 18 | +mod m20240101_000016_visual_mode; | |
| 18 | 19 | |
| 19 | 20 | pub struct Migrator; |
| 20 | 21 |
| 39 | 40 | Box::new(m20240101_000015_email_verification::Migration), |
| 40 | 41 | // "Sign in with NEIAM" links (neiam-auth), FK to users(id). |
| 41 | 42 | Box::new(neiam_auth::sea_orm::Migration::new("users")), |
| 43 | + // Listed after the OIDC migration so databases that already ran it | |
| 44 | + // apply this one next. | |
| 45 | + Box::new(m20240101_000016_visual_mode::Migration), | |
| 42 | 46 | ] |
| 43 | 47 | } |
| 44 | 48 | } |
added
migration/src/m20240101_000016_visual_mode.rs
+75
−0
| 1 | +//! Visual (focus) mode: each user's default view, and per-topic read state | |
| 2 | +//! for the "new" / "N unread" markers on topic tiles. | |
| 3 | +use sea_orm_migration::prelude::*; | |
| 4 | + | |
| 5 | +#[derive(DeriveMigrationName)] | |
| 6 | +pub struct Migration; | |
| 7 | + | |
| 8 | +#[async_trait::async_trait] | |
| 9 | +impl MigrationTrait for Migration { | |
| 10 | + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | |
| 11 | + manager | |
| 12 | + .alter_table( | |
| 13 | + Table::alter() | |
| 14 | + .table(Users::Table) | |
| 15 | + .add_column(ColumnDef::new(Users::PreferredView).string_len(16).not_null().default("list")) | |
| 16 | + .to_owned(), | |
| 17 | + ) | |
| 18 | + .await?; | |
| 19 | + manager | |
| 20 | + .create_table( | |
| 21 | + Table::create() | |
| 22 | + .table(TopicReads::Table) | |
| 23 | + .if_not_exists() | |
| 24 | + .col(ColumnDef::new(TopicReads::UserId).uuid().not_null()) | |
| 25 | + .col(ColumnDef::new(TopicReads::TopicId).uuid().not_null()) | |
| 26 | + // Highest post_number the user has had on screen. | |
| 27 | + .col(ColumnDef::new(TopicReads::LastReadPostNumber).integer().not_null()) | |
| 28 | + .col(ColumnDef::new(TopicReads::UpdatedAt).timestamp_with_time_zone().not_null()) | |
| 29 | + .primary_key(Index::create().col(TopicReads::UserId).col(TopicReads::TopicId)) | |
| 30 | + .foreign_key( | |
| 31 | + ForeignKey::create() | |
| 32 | + .from(TopicReads::Table, TopicReads::UserId) | |
| 33 | + .to(Users::Table, Users::Id) | |
| 34 | + .on_delete(ForeignKeyAction::Cascade), | |
| 35 | + ) | |
| 36 | + .foreign_key( | |
| 37 | + ForeignKey::create() | |
| 38 | + .from(TopicReads::Table, TopicReads::TopicId) | |
| 39 | + .to(Topics::Table, Topics::Id) | |
| 40 | + .on_delete(ForeignKeyAction::Cascade), | |
| 41 | + ) | |
| 42 | + .to_owned(), | |
| 43 | + ) | |
| 44 | + .await | |
| 45 | + } | |
| 46 | + | |
| 47 | + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | |
| 48 | + manager.drop_table(Table::drop().table(TopicReads::Table).to_owned()).await?; | |
| 49 | + manager | |
| 50 | + .alter_table(Table::alter().table(Users::Table).drop_column(Users::PreferredView).to_owned()) | |
| 51 | + .await | |
| 52 | + } | |
| 53 | +} | |
| 54 | + | |
| 55 | +#[derive(DeriveIden)] | |
| 56 | +enum Users { | |
| 57 | + Table, | |
| 58 | + Id, | |
| 59 | + PreferredView, | |
| 60 | +} | |
| 61 | + | |
| 62 | +#[derive(DeriveIden)] | |
| 63 | +enum Topics { | |
| 64 | + Table, | |
| 65 | + Id, | |
| 66 | +} | |
| 67 | + | |
| 68 | +#[derive(DeriveIden)] | |
| 69 | +enum TopicReads { | |
| 70 | + Table, | |
| 71 | + UserId, | |
| 72 | + TopicId, | |
| 73 | + LastReadPostNumber, | |
| 74 | + UpdatedAt, | |
| 75 | +} |
modified
src/auth/users.rs
+1
−0
| 78 | 78 | is_active: Set(true), |
| 79 | 79 | is_staff: Set(is_staff), |
| 80 | 80 | preferred_sort: Set("latest".to_string()), |
| 81 | + preferred_view: Set("list".to_string()), | |
| 81 | 82 | reaction_notifications: Set(true), |
| 82 | 83 | trust_level: Set(0), |
| 83 | 84 | created_at: Set(now.into()), |
modified
src/entities/mod.rs
+1
−0
Click to load diff…
modified
src/entities/prelude.rs
+1
−0
Click to load diff…
added
src/entities/topic_reads.rs
+34
−0
Click to load diff…
modified
src/entities/users.rs
+2
−0
Click to load diff…
added
src/handlers/focus.rs
+687
−0
Click to load diff…
modified
src/handlers/forum.rs
+216
−120
Click to load diff…
modified
src/handlers/mod.rs
+1
−0
Click to load diff…
added
templates/forum/_reader.html
+74
−0
Click to load diff…
added
templates/forum/_topic_square.html
+15
−0
Click to load diff…
added
templates/forum/_topic_tile.html
+36
−0
Click to load diff…
added
templates/forum/_view_toggle.html
+14
−0
Click to load diff…
modified
templates/forum/category.html
+4
−2
Click to load diff…
added
templates/forum/focus.html
+110
−0
Click to load diff…
modified
templates/forum/home.html
+9
−5
Click to load diff…
added
templates/forum/home_visual.html
+55
−0
Click to load diff…
modified
templates/forum/topic.html
+1
−1
Click to load diff…
modified
templates/root.html
+2
−1
Click to load diff…
modified
tests/templates.rs
+66
−0
Click to load diff…
Parents: 95b0c9a