gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit0eab858f0eab858fRead only catalog date fields during the episode boot scanmre0eab858f/components/main.hl

11.4 KB

  1. // components/main.hl — THE SHELL (tracker.worldapi.org#32, mission 031): the WorldAPI theme's header and content-first shell
  2. // (theme/shell/*, vendored from layouts.worldapi.org — never edited here) around the slot every page renders into.
  3. // The shell rules live in this file; the theme rules come with theme/theme.hl and its shell files.
  4. // THE HEADER (creator, tracker#32): desktop — brand left, the search field in the middle, the main menu
  5. // Series | Shows | Movies | Genres | People | Franchises (tracker#40), the user icon far right; its dropdown holds the personal lists and ends with
  6. // Settings, Logout. IDENT'S SELECTOR STANDS IN THE HEADER next to it, signed in and signed out (creator 2026-10-24: the theme move hid it
  7. // behind an icon — never again; the gate checks it at 390 and 1280); signed out the selector stands alone (no second "Log in" button — creator 2026-10-24). Phone — ☰ (the sidebar
  8. // overlay with the main menu), brand, the loupe (opens the search field under the bar), the selector, the user icon far right. The header's contents are flush with the content column (the theme's --layout-column).
  9. // THE MARKED MENU ENTRY: a shell is not told the page's path (hl:web gives it only the route params), so MainMenu gets no
  10. // `current`; the Style block marks the entry of the type the page's heading names ("Series | …" → Series) with :has().
  11. // THE SEARCH FIELD sends GET /find?q=… (project.hl findRoute → 302 /search/<text>, components/search.hl).
  12. // THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in calendar/gitoria. Choosing an
  13. // identity fires `ident-login` (one-time code); /login.js hands it to the hidden input #identcode, whose `change`
  14. // goes to the face trackerLogin (server-side exchange, no reload). The element's class is `in` / `out`; /login.js
  15. // mirrors it into the selector's `loggedIn`.
  16. // LOGIN: the selector (the plain link to <ident>/login?key=&return=<public url>/login/callback is the old way, still served)
  17. // (users.hl loginCallbackOf). After a login or logout in this tab the page is fetched again (navigate('/')).
  18. import { navigate } from 'hl:web'
  19. import { appTitle } from '../lib/app.hl'
  20. import { identKey, callbackUrl, selectorScript, userIdOfSession, userOfCode, loginPerMinute } from '../lib/users.hl'
  21. import { allowHit } from '../lib/security.hl'
  22. import { randomBytes } from 'hl:crypto'
  23. import AppHeader from '../theme/shell/app-header.hl'
  24. import MainMenu from '../theme/shell/main-menu.hl'
  25. import UserMenu from '../theme/shell/user-menu.hl'
  26. import Sidebar from '../theme/shell/app-sidebar.hl'
  27. import ContentFirst from '../theme/shell/content-first.hl'
  28. static menu = [
  29. { label = 'Series' href = '/series' }
  30. { label = 'Shows' href = '/shows' }
  31. { label = 'Movies' href = '/movies' }
  32. { label = 'Genres' href = '/genres' }
  33. { label = 'People' href = '/people' }
  34. // tracker#40: the franchises and their timelines were only reachable by a title's widget
  35. { label = 'Franchises' href = '/franchises' }
  36. ]
  37. slot = null
  38. session = null
  39. loggedIn = userIdOfSession(&session) != null
  40. loggedOut = userIdOfSession(&session) == null
  41. selectorClass = loggedIn ? 'in' : 'out'
  42. selectorKey = identKey
  43. // where the selector's sign-in panel (ident#31) sends the browser: the login button's callback, with the page the user is on as `next`
  44. // (the callback takes it back there). No route known (first paint) = no `next` = the start page.
  45. route = null
  46. path = route == null ? '' : route.path
  47. selectorReturn = callbackUrl + (path == '' ? '' : '?next=' + encodeURIComponent(path))
  48. identScript = selectorScript
  49. loginError = ''
  50. hasLoginError = false
  51. // OFFLINE (tracker.worldapi.org#10): the service worker opens `/` from its cache without a network; the shell then
  52. // says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser: `netProbe` runs
  53. // an endless 1 s CSS animation (this file), and each `animationiteration` reads navigator.onLine — a write only when
  54. // it changed. (An `img` error or a socket event would race the hydration and be missed.)
  55. offline = false
  56. // HM49: component rules keep the existing selectors and shared theme variables.
  57. Style {
  58. 'body:has(main h1.typed > type-word.type-series)' {
  59. mainMenu {
  60. 'a[href="/series"]' {
  61. color = 'var(--color-accent)'
  62. }
  63. }
  64. appSidebar {
  65. mainMenu {
  66. 'a[href="/series"]' {
  67. background = 'var(--color-surface)'
  68. }
  69. }
  70. }
  71. }
  72. 'body:has(main h1.typed > type-word.type-show)' {
  73. mainMenu {
  74. 'a[href="/shows"]' {
  75. color = 'var(--color-accent)'
  76. }
  77. }
  78. appSidebar {
  79. mainMenu {
  80. 'a[href="/shows"]' {
  81. background = 'var(--color-surface)'
  82. }
  83. }
  84. }
  85. }
  86. 'body:has(main h1.typed > type-word.type-movie)' {
  87. mainMenu {
  88. 'a[href="/movies"]' {
  89. color = 'var(--color-accent)'
  90. }
  91. }
  92. appSidebar {
  93. mainMenu {
  94. 'a[href="/movies"]' {
  95. background = 'var(--color-surface)'
  96. }
  97. }
  98. }
  99. }
  100. 'body:has(main h1.typed > type-word.type-genre)' {
  101. mainMenu {
  102. 'a[href="/genres"]' {
  103. color = 'var(--color-accent)'
  104. }
  105. }
  106. appSidebar {
  107. mainMenu {
  108. 'a[href="/genres"]' {
  109. background = 'var(--color-surface)'
  110. }
  111. }
  112. }
  113. }
  114. 'body:has(main h1.typed > type-word.type-person)' {
  115. mainMenu {
  116. 'a[href="/people"]' {
  117. color = 'var(--color-accent)'
  118. }
  119. }
  120. appSidebar {
  121. mainMenu {
  122. 'a[href="/people"]' {
  123. background = 'var(--color-surface)'
  124. }
  125. }
  126. }
  127. }
  128. 'body:has(main h1.typed > type-word.type-franchise)' {
  129. mainMenu {
  130. 'a[href="/franchises"]' {
  131. color = 'var(--color-accent)'
  132. }
  133. }
  134. appSidebar {
  135. mainMenu {
  136. 'a[href="/franchises"]' {
  137. background = 'var(--color-surface)'
  138. }
  139. }
  140. }
  141. }
  142. 'body:has(main h1.typed > type-word.type-timeline)' {
  143. mainMenu {
  144. 'a[href="/franchises"]' {
  145. color = 'var(--color-accent)'
  146. }
  147. }
  148. appSidebar {
  149. mainMenu {
  150. 'a[href="/franchises"]' {
  151. background = 'var(--color-surface)'
  152. }
  153. }
  154. }
  155. }
  156. identSelector {
  157. '--ident-accent' = 'var(--color-accent)'
  158. '--ident-accent-text' = 'var(--color-accent-text)'
  159. '--ident-background' = 'var(--color-surface)'
  160. '--ident-border' = 'var(--color-border)'
  161. '--ident-font' = '600 .9rem/1.3 system-ui, sans-serif'
  162. position = 'relative'
  163. flex = '0 1 auto'
  164. minWidth = '0'
  165. }
  166. 'ident-selector::part(button)' {
  167. minHeight = '2.75rem'
  168. padding = '.25rem .6rem'
  169. border = 'none'
  170. whiteSpace = 'nowrap'
  171. }
  172. 'ident-selector::part(status)' {
  173. minHeight = '2.75rem'
  174. padding = '.25rem .6rem'
  175. border = 'none'
  176. whiteSpace = 'nowrap'
  177. overflow = 'hidden'
  178. textOverflow = 'ellipsis'
  179. }
  180. 'ident-selector::part(identity)' {
  181. minHeight = '2.75rem'
  182. border = 'none'
  183. }
  184. 'ident-selector::part(panel)' {
  185. position = 'absolute'
  186. top = '100%'
  187. right = '0'
  188. zIndex = '30'
  189. width = 'min(20rem, calc(100vw - 2 * var(--layout-gutter)))'
  190. maxWidth = 'none'
  191. border = 'none'
  192. boxShadow = '0 .75rem 2rem ' + 'var(--color-background-sunken)'
  193. }
  194. 'body:has(application-header > ident-selector.in)' {
  195. applicationHeader {
  196. @media {
  197. maxWidth = '29.99rem'
  198. gap = '0'
  199. paddingInline = '.25rem'
  200. }
  201. '>' {
  202. 'button.menu-toggle' {
  203. @media {
  204. maxWidth = '29.99rem'
  205. marginLeft = '-.25rem'
  206. }
  207. }
  208. 'a.brand' {
  209. @media {
  210. maxWidth = '29.99rem'
  211. fontSize = '1rem'
  212. }
  213. @media {
  214. maxWidth = '22.99rem'
  215. fontSize = '.85rem'
  216. flexShrink = '0'
  217. }
  218. }
  219. 'button.search-toggle' {
  220. @media {
  221. maxWidth = '22.99rem'
  222. marginInline = '-.125rem'
  223. }
  224. }
  225. }
  226. userMenu {
  227. '>' {
  228. button {
  229. @media {
  230. maxWidth = '29.99rem'
  231. marginRight = '-.25rem'
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. offlineNote {
  239. display = 'block'
  240. padding = '.5rem .75rem'
  241. color = 'var(--color-text-strong)'
  242. background = 'var(--color-surface)'
  243. }
  244. netProbe {
  245. position = 'fixed'
  246. left = '0'
  247. top = '0'
  248. width = '1px'
  249. height = '1px'
  250. opacity = '0'
  251. pointerEvents = 'none'
  252. animation = 'tracker-net-tick 1s linear infinite'
  253. }
  254. '@keyframes tracker-net-tick' {
  255. 'from' {
  256. opacity = '0'
  257. }
  258. to {
  259. opacity = '0'
  260. }
  261. }
  262. }
  263. View {
  264. body {
  265. AppHeader { brand = appTitle search = "/find" searchPlaceholder = "Shows, movies, people"
  266. MainMenu { items = menu }
  267. // ident's selector stands in the header, visible signed in AND signed out, on the phone and on the desktop (signed in it shows the
  268. // chosen identity). /login.js mirrors its state from the class (`in` / `out`). Nothing else stands beside it: no second "Log in" button (creator 2026-10-24).
  269. identSelector { id = "selector" key = selectorKey return = selectorReturn class = selectorClass }
  270. if (loggedIn) {
  271. UserMenu {
  272. a { href = "/my/unwatched" "Unwatched" }
  273. a { href = "/my/schedule" "Schedule" }
  274. a { href = "/my/series" "My series" }
  275. a { href = "/my/shows" "My shows" }
  276. a { href = "/my/movies" "My movies" }
  277. a { id = "settingslink" href = "/settings" "Settings" }
  278. button { id = "logout" type = "button" "Logout" on click(e) { emit doLogout(e) } }
  279. }
  280. }
  281. }
  282. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  283. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  284. if (offline) { offlineNote { id = "offline" "You are offline. Your shows and lists need the network." } }
  285. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  286. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  287. // page. NOT the theme's `ContentFirst { Sidebar { … } main { slot } }`: hl:web renders a component's slot children on one
  288. // line, and a page slot that does not start its own line is rendered once per line of the page (WebFramework.hl
  289. // document(): the text before the marker is taken as the indent) — so `main` stands around the shell and the page is the
  290. // shell's slot itself
  291. Sidebar { desktop = "false" MainMenu { items = menu } }
  292. main {
  293. ContentFirst { slot }
  294. }
  295. script { src = identScript }
  296. script { src = "/login.js" }
  297. }
  298. }
  299. showIn = () => {
  300. loggedIn = true
  301. loggedOut = false
  302. selectorClass = 'in'
  303. loginError = ''
  304. hasLoginError = false
  305. }
  306. showOut = () => {
  307. loggedIn = false
  308. loggedOut = true
  309. selectorClass = 'out'
  310. }
  311. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  312. on gotCode(e) {
  313. code = e.target.value
  314. e.target.value = ''
  315. if (code == null || code == '') { return null }
  316. r = emit server trackerLogin(code)
  317. if (r == null || r.error != null) {
  318. loginError = r != null ? r.error : 'the login failed'
  319. hasLoginError = true
  320. return null
  321. }
  322. showIn()
  323. navigate('/')
  324. }
  325. on client trackerSignedIn(tag) {
  326. showIn()
  327. navigate('/')
  328. }
  329. on client trackerSignedOut(tag) {
  330. showOut()
  331. navigate('/')
  332. }
  333. on netTick(e) {
  334. down = window.navigator.onLine == false
  335. if (down != offline) { offline = down }
  336. }
  337. on doLogout(e) {
  338. emit server trackerLogOut()
  339. showOut()
  340. navigate('/')
  341. }
  342. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  343. on server trackerLogin(code, session) {
  344. if (session == null) { return { error = 'no session — reload the page' } }
  345. if (!allowHit('login-face', &session.id, &loginPerMinute, 60000)) { return { error = 'too many login attempts — wait a minute' } }
  346. x = userOfCode(code)
  347. if (x.error != null) { return { error = x.error } }
  348. tag = randomBytes(16)
  349. session.user = { id = x.user.id }
  350. session.data.tag = tag
  351. emit client trackerSignedIn(tag)
  352. return { ok = true }
  353. }
  354. on server trackerLogOut(session) {
  355. if (session == null) { return { error = 'no session' } }
  356. emit client trackerSignedOut(session.data.tag)
  357. session.user = null
  358. return { ok = true }
  359. }

Branches

Latest commits

  • 0eab858fRead only catalog date fields during the episode boot scanmre
  • cb78a1a0HM65 report missing heap diagnostic package with repromre
  • 89606a5cHM65 briefmre
  • 096ce0d4log: DP69 live on day48mre
  • b3d8a80bDP69 brief, RV48 mergedmre
  • ce6d7d32Merge rv48: Hybriel day48mre
  • 3da2ea86RV48: report day48 cold starts, gates and cleanupmre
  • 8d9ecdfeRV48: re-vendor Hybriel set day48 (source b6a8f429, bin 660a9524)mre
  • 4a802ae7status: RV48 runningmre
  • 0a5412b6RV48 brief, day48 outmre
  • 56665efelog: CB69 mergedmre
  • 05448a98Merge cb69-imports: appTitle in a dependency-free topicmre
  • e55b379dKeep shared app title independent of the route import graphmre
  • 9a99659blog: hybriel#334, batch waits for day48mre
  • 85fa6c9blog: CB68 result, CB69 startedmre
  • 2f07c1b7log: DP68 boot gate failed, CB68mre
  • 9652782dlog: HM59 merged, DP68 startedmre
  • 29867a75Merge hm59-logic: tracker#59 page logic moved to libmre
  • f7bfe90bMove remaining page builders into their topicsmre
  • 7c3991f9log: day46 from Antonmre