gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit613ae0ec613ae0ecMerge branch 'bs3' into mainTracker613ae0ec/components/main.hl

10.9 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, #55): the service worker opens `/` from its cache without a network; the shell then
  52. // says so. hl:web keeps `__hlOnline` equal to the browser's connection (navigator.onLine and the online/offline events)
  53. // for the shell and its kids; `offline` is derived from it for the View's `if`.
  54. __hlOnline = true
  55. offline = !__hlOnline
  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. }
  245. View {
  246. body {
  247. AppHeader { brand = appTitle search = "/find" searchPlaceholder = "Shows, movies, people"
  248. MainMenu { items = menu }
  249. // 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
  250. // 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).
  251. identSelector { id = "selector" key = selectorKey return = selectorReturn class = selectorClass }
  252. if (loggedIn) {
  253. UserMenu {
  254. a { href = "/my/unwatched" "Unwatched" }
  255. a { href = "/my/schedule" "Schedule" }
  256. a { href = "/my/series" "My series" }
  257. a { href = "/my/shows" "My shows" }
  258. a { href = "/my/movies" "My movies" }
  259. a { id = "settingslink" href = "/settings" "Settings" }
  260. button { id = "logout" type = "button" "Logout" on click(e) { emit doLogout(e) } }
  261. }
  262. }
  263. }
  264. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  265. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  266. if (offline) { offlineNote { id = "offline" "You are offline. Your shows and lists need the network." } }
  267. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  268. // page. NOT the theme's `ContentFirst { Sidebar { … } main { slot } }`: hl:web renders a component's slot children on one
  269. // line, and a page slot that does not start its own line is rendered once per line of the page (WebFramework.hl
  270. // document(): the text before the marker is taken as the indent) — so `main` stands around the shell and the page is the
  271. // shell's slot itself
  272. Sidebar { desktop = "false" MainMenu { items = menu } }
  273. main {
  274. ContentFirst { slot }
  275. }
  276. script { src = identScript }
  277. script { src = "/login.js" }
  278. }
  279. }
  280. showIn = () => {
  281. loggedIn = true
  282. loggedOut = false
  283. selectorClass = 'in'
  284. loginError = ''
  285. hasLoginError = false
  286. }
  287. showOut = () => {
  288. loggedIn = false
  289. loggedOut = true
  290. selectorClass = 'out'
  291. }
  292. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  293. on gotCode(e) {
  294. code = e.target.value
  295. e.target.value = ''
  296. if (code == null || code == '') { return null }
  297. r = emit server trackerLogin(code)
  298. if (r == null || r.error != null) {
  299. loginError = r != null ? r.error : 'the login failed'
  300. hasLoginError = true
  301. return null
  302. }
  303. showIn()
  304. navigate('/')
  305. }
  306. on client trackerSignedIn(tag) {
  307. showIn()
  308. navigate('/')
  309. }
  310. on client trackerSignedOut(tag) {
  311. showOut()
  312. navigate('/')
  313. }
  314. on doLogout(e) {
  315. emit server trackerLogOut()
  316. showOut()
  317. navigate('/')
  318. }
  319. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  320. on server trackerLogin(code, session) {
  321. if (session == null) { return { error = 'no session — reload the page' } }
  322. if (!allowHit('login-face', &session.id, &loginPerMinute, 60000)) { return { error = 'too many login attempts — wait a minute' } }
  323. x = userOfCode(code)
  324. if (x.error != null) { return { error = x.error } }
  325. tag = randomBytes(16)
  326. session.user = { id = x.user.id }
  327. session.data.tag = tag
  328. emit client trackerSignedIn(tag)
  329. return { ok = true }
  330. }
  331. on server trackerLogOut(session) {
  332. if (session == null) { return { error = 'no session' } }
  333. emit client trackerSignedOut(session.data.tag)
  334. session.user = null
  335. return { ok = true }
  336. }

Branches

Latest commits

  • 613ae0ecMerge branch 'bs3' into mainTracker
  • 1383264b|||PR BS3: keep shared synchronous sorting fastTracker
  • 63e5ba1a|||PR BS3: guard boot imports and share resumable sort buffersTracker
  • 310613f1Merge branch 'records-dp72' into mainTracker
  • 6f7b61ba|||PR records: deploy-swap fix live, Kunibert findingsTracker
  • c41587d2Merge branch 'bs2' into mainTracker
  • 0dd538a6|||PR BS2: finish the boot index in slices so a booting instance keeps answeringTracker
  • 019d5cedMerge branch 'records-1110' into mainTracker
  • f88ae8b9|||PR records: day56 toggle live, reviewTracker
  • b6b3bb4dMerge branch 'ap56e' into mainTracker
  • 29a26da9|||PR AP56e: guard hidden show helpers during session syncTracker
  • 7c9ec236|||PR AP56e: re-vendor Hybriel set day56 (source 36ae83a8, bin c1f595a2)Tracker
  • 4b54f6f9Merge branch 'records-audit' into mainTracker
  • cab4a3bc|||PR records: branch audit, PR-onlyTracker
  • 641e1c4cMerge branch 'records-dp71' into mainTracker
  • 85a6e9f5|||PR records: DP71 checked in ChromeTracker
  • f5be5f18records: gitoria PR-only planTracker
  • 46a37036records: DP71 liveTracker
  • 3bcb7039Status/log: DP71 in progressTracker
  • 5b3a5693Log: SR1b merged via PR 2, DP71 startedTracker