gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commiteee0b513eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmreeee0b513/components/appsettings.hl

9.4 KB

  1. // components/appsettings.hl — `/inbox/<connection id>`: THE PER-APP PAGE (piece 4 of 6,
  2. // ticket ident#6; CONCEPT.md "Per-app page": "for each app and identity the user has a page
  3. // showing when they registered in that app and all its notifications (by name), each with
  4. // push and email switches, and on top one override for all").
  5. // A connection = one identity in one app (lib/apps.hl connectionsTable); its `created` is
  6. // "when they registered". The switches show the EFFECTIVE setting (the app's preset
  7. // unless the user switched it; lib/notify.hl effectiveOf). THE OVERRIDE: when it is on, its
  8. // push / email switches count for every notification of the app and the per-kind
  9. // switches are locked. Push is impossible for a name the app has not registered.
  10. // Every flip is saved at once (a face) and the server's new state is shown.
  11. //
  12. // Faces are named `inbox…` (a face is found by its EVENT NAME across all files).
  13. parent './main.hl'
  14. import { accountOfSession } from '../lib/accounts.hl'
  15. import { settingsPage, setSwitch, setOverride } from '../lib/notify.hl'
  16. import { disconnectConnection } from '../lib/apps.hl'
  17. import { siteName } from '../project.hl'
  18. import { leadLook, messageLook, noticeLook } from './styles.hl'
  19. session = null
  20. cid = null
  21. me = accountOfSession(&session)
  22. signedIn = me != null
  23. signedOut = me == null
  24. page = me != null && cid != null ? settingsPage(me.id, cid) : null
  25. found = page != null
  26. notFound = me != null && page == null
  27. meEmail = me != null ? me.email : ''
  28. appName = page != null ? page.app : ''
  29. identityName = page != null ? page.identity : ''
  30. since = page != null ? page.since : ''
  31. overrideActive = page != null ? page.overrideActive : 'off'
  32. overridePush = page != null ? page.overridePush : 'off'
  33. overrideEmail = page != null ? page.overrideEmail : 'off'
  34. overrideOn = overrideActive == 'on'
  35. overrideActiveChecked = page != null ? page.overrideActiveChecked : 'false'
  36. overridePushChecked = page != null ? page.overridePushChecked : 'false'
  37. overrideEmailChecked = page != null ? page.overrideEmailChecked : 'false'
  38. kinds = page != null ? page.kinds : []
  39. hasKinds = kinds.length > 0
  40. noKinds = kinds.length == 0
  41. __title = siteName + (page != null ? ' | ' + page.app + ' notifications' : ' | notifications')
  42. message = ''
  43. notice = ''
  44. Style {
  45. pLead = leadLook
  46. pMessage = messageLook
  47. pNotice = noticeLook
  48. '#overridesection' {
  49. marginTop = '.6rem'
  50. }
  51. '#kindssection' {
  52. marginTop = '.6rem'
  53. }
  54. kindMain {
  55. flex = '1 1 12rem'
  56. display = 'grid'
  57. gap = '.15rem'
  58. minWidth = '0'
  59. }
  60. kindName {
  61. fontWeight = '700'
  62. color = 'var(--color-text-strong)'
  63. overflowWrap = 'anywhere'
  64. }
  65. kindPreset {
  66. color = 'var(--color-text-muted)'
  67. fontSize = '.875rem'
  68. overflowWrap = 'anywhere'
  69. }
  70. kindSwitches {
  71. display = 'flex'
  72. flexWrap = 'wrap'
  73. gap = '.5rem 1rem'
  74. }
  75. switchRow {
  76. display = 'flex'
  77. alignItems = 'center'
  78. gap = '.5rem'
  79. }
  80. switchLabel {
  81. fontSize = '.875rem'
  82. color = 'var(--color-text-muted)'
  83. }
  84. // an on/off switch: off = a plain button, on = the accent (aria-checked the data chooses: quoted), locked = aria-disabled
  85. 'button[role="switch"]' {
  86. minWidth = '3.6rem'
  87. fontSize = '.875rem'
  88. color = 'var(--color-text)'
  89. background = 'var(--color-background-sunken)'
  90. }
  91. 'button[role="switch"][aria-checked="true"]' {
  92. color = 'var(--color-accent-text)'
  93. background = 'var(--color-accent)'
  94. }
  95. 'button[role="switch"][aria-disabled="true"]' {
  96. opacity = '.45'
  97. cursor = 'not-allowed'
  98. }
  99. switchOff {
  100. display = 'inline-block'
  101. minWidth = '3.6rem'
  102. textAlign = 'center'
  103. color = 'var(--color-text-muted)'
  104. }
  105. '#overridesection switch-row' {
  106. justifyContent = 'space-between'
  107. maxWidth = '16rem'
  108. }
  109. }
  110. View {
  111. identCard { class = "wide"
  112. if (signedOut) {
  113. h1 { "Notification settings" }
  114. p { id = "signinfirst" Style.pLead "Sign in to ident first: " a { href = "/" "sign in" } "." }
  115. }
  116. if (notFound) {
  117. h1 { "Notification settings" }
  118. p { id = "notfound" Style.pMessage "This app connection does not exist or is not yours." }
  119. p { class = "links" a { href = "/inbox" "Back to the inbox" } }
  120. }
  121. if (found) {
  122. accountBar {
  123. userEmail { id = "meemail" meEmail }
  124. a { id = "toinbox" href = "/inbox" "Inbox" }
  125. }
  126. section { id = "connhead"
  127. h1 { id = "connapp" appName }
  128. p { Style.pLead "Identity " strong { id = "connidentity" identityName } " — registered in this app since " strong { id = "connsince" since } "." }
  129. button { id = "disconnect" type = "button" class = "quiet small danger" "Sign out of this app" on click(e) { emit doDisconnect(e) } }
  130. }
  131. section { id = "overridesection"
  132. h2 { "All notifications" }
  133. p { Style.pLead "One setting for every notification of this app. While it is on, the switches below are locked." }
  134. switchRow {
  135. switchLabel { "Override all" }
  136. button { id = "ovactive" type = "button" role = "switch" "aria-checked" = overrideActiveChecked overrideActive on click(e) { emit flipOverride('active') } }
  137. }
  138. switchRow {
  139. switchLabel { "Push" }
  140. button { id = "ovpush" type = "button" role = "switch" "aria-checked" = overridePushChecked overridePush on click(e) { emit flipOverride('push') } }
  141. }
  142. switchRow {
  143. switchLabel { "Email" }
  144. button { id = "ovemail" type = "button" role = "switch" "aria-checked" = overrideEmailChecked overrideEmail on click(e) { emit flipOverride('email') } }
  145. }
  146. }
  147. section { id = "kindssection"
  148. h2 { "Notifications" }
  149. if (noKinds) { p { id = "nokinds" Style.pLead "This app has not registered or sent any notifications yet." } }
  150. ul { id = "kinds"
  151. for (k of kinds) {
  152. li {
  153. kindMain {
  154. kindName { k.name }
  155. kindPreset { k.preset }
  156. }
  157. kindSwitches {
  158. switchRow {
  159. switchLabel { "Push" }
  160. if (k.canPush) { button { type = "button" name = "push" role = "switch" "aria-checked" = k.pushChecked value = k.name k.push on click(e) { emit flipKind(e.target.value, 'push') } } }
  161. if (k.lockedPush) { button { type = "button" name = "push" role = "switch" "aria-checked" = k.pushChecked "aria-disabled" = "true" value = k.name k.push } }
  162. if (k.noPush) { switchOff { "—" } }
  163. }
  164. switchRow {
  165. switchLabel { "Email" }
  166. if (k.canEmail) { button { type = "button" name = "email" role = "switch" "aria-checked" = k.emailChecked value = k.name k.email on click(e) { emit flipKind(e.target.value, 'email') } } }
  167. if (k.lockedEmail) { button { type = "button" name = "email" role = "switch" "aria-checked" = k.emailChecked "aria-disabled" = "true" value = k.name k.email } }
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }
  174. }
  175. p { id = "notice" Style.pNotice notice }
  176. p { id = "message" Style.pMessage message }
  177. }
  178. }
  179. show = (p) => {
  180. overrideActive = p.overrideActive
  181. overridePush = p.overridePush
  182. overrideEmail = p.overrideEmail
  183. overrideOn = p.overrideActive == 'on'
  184. overrideActiveChecked = p.overrideActiveChecked
  185. overridePushChecked = p.overridePushChecked
  186. overrideEmailChecked = p.overrideEmailChecked
  187. kinds = p.kinds
  188. hasKinds = p.kinds.length > 0
  189. noKinds = p.kinds.length == 0
  190. return null
  191. }
  192. answer = (r) => {
  193. if (r == null) {
  194. message = 'the server did not answer — try again'
  195. return null
  196. }
  197. if (r.error != null) {
  198. message = r.error
  199. return null
  200. }
  201. show(r.page)
  202. notice = 'Saved.'
  203. return null
  204. }
  205. on flipOverride(field) {
  206. message = ''
  207. notice = ''
  208. cur = field == 'active' ? overrideActive : (field == 'push' ? overridePush : overrideEmail)
  209. answer(emit server inboxOverride('' + cid, field, cur != 'on'))
  210. }
  211. kindRow = (name) => {
  212. for (k of kinds) { if (k.name == name) { return k } }
  213. return null
  214. }
  215. on flipKind(name, channel) {
  216. message = ''
  217. notice = ''
  218. k = kindRow(name)
  219. if (k == null) { return null }
  220. cur = channel == 'push' ? k.push : k.email
  221. answer(emit server inboxSwitch('' + cid, name, channel, cur != 'on'))
  222. }
  223. // FORGETS this connection: the app gets a fresh, unrelated id on a later login
  224. on doDisconnect(e) {
  225. message = ''
  226. notice = ''
  227. if (!confirm('Sign out of ' + appName + '? It will no longer recognize this identity.')) { return null }
  228. r = emit server inboxDisconnect('' + cid)
  229. if (r == null) {
  230. message = 'the server did not answer — try again'
  231. return null
  232. }
  233. if (r.error != null) {
  234. message = r.error
  235. return null
  236. }
  237. found = false
  238. notFound = true
  239. notice = 'Signed out of ' + appName + '.'
  240. }
  241. // ---- the faces ------------------------------------------------------------------------
  242. // The LAST parameter is the session; accountOfSession only accepts the framework's own
  243. // Session (hl:web never takes it from the peer, hybriel#16/#31).
  244. on server inboxSwitch(cid, kind, channel, value, session) {
  245. let me = accountOfSession(&session)
  246. if (me == null) { return { error = 'you are not signed in' } }
  247. if (cid == null || hlTypeName(cid) != 'String') { return { error = 'field connection must be a string' } }
  248. return setSwitch(me.id, cid, kind, channel, value)
  249. }
  250. on server inboxOverride(cid, field, value, session) {
  251. let me = accountOfSession(&session)
  252. if (me == null) { return { error = 'you are not signed in' } }
  253. if (cid == null || hlTypeName(cid) != 'String') { return { error = 'field connection must be a string' } }
  254. return setOverride(me.id, cid, field, value)
  255. }
  256. on server inboxDisconnect(cid, session) {
  257. let me = accountOfSession(&session)
  258. if (me == null) { return { error = 'you are not signed in' } }
  259. if (cid == null || hlTypeName(cid) != 'String') { return { error = 'field connection must be a string' } }
  260. return disconnectConnection(me.id, cid)
  261. }

Branches

Latest commits

  • eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmre
  • ccd6d0c4ident#34: browser gate: rowButton finds the row's button by namemre
  • 24dd414eident#34: the shared lead, message and notice looks are statics in components/styles.hl, imported by the components (lib/looks.hl gone)mre
  • 03ed26c7ident#34: access.hl: the remaining lead classes droppedmre
  • 1d066c42ident#34: access.hl drops its unstyled lead class (the shared lead rule would otherwise mute it)mre
  • 1e1dd7b4ident#34: the access page keeps its lead class string (the page has no ident-card, so its lead line was never muted; a shared rule would change the look)mre
  • 89ac6553ident#34: the lead, message and notice lines are named with Style.pLead / pMessage / pNotice (shared bodies in lib/looks.hl) instead of class stringsmre
  • e84be3deident#34: browser gate lists the Edit/Delete buttons by namemre
  • fb7111faident#34: access page: unstyled test-hook classes (idrow, never, who, whoname, appname, neverrevoke) dropped; the tests use element/name selectorsmre
  • 9f2ad803ident#34: notification switches: push/email by name=..., locked by aria-disabled, the switch look is the role=switch button (no switch/push/email/locked classes)mre
  • e0f0ddaaident#34: inbox: the Mark read/unread button is styled as the button of its note-foot, the icon is found as the row's img (no toggle/icon classes)mre
  • 16b49756ident#34: unused row classes (choice, usedrow, kind, shortid) droppedmre
  • f9d6fb38ident#34: apps and identity rows: the Edit/New secret/Delete buttons carry name=..., the API key is found by its element; unused row classes (app, identity, shortid) droppedmre
  • b323265aMerge branch 'f5-styles' into mainIdent
  • 9ced53c3|||PR ident#33 ident#35 every component's styles live in its own Style block; styles.hl keeps the page-wide rest; the account bar is phone first (min-width: 60rem block); the avatar preview is hidden with the hidden attribute (ident#34 in part)mre
  • f28333e4ident#33 ident#35: styles.hl keeps only the accent, the page column and the shared patterns; the account bar is written phone first (base rule + one min-width: 60rem block) instead of a max-width overridemre
  • 5b4541fcident#33: the selector sign-in frame's rules move into embed.hl's Stylemre
  • 00235f21ident#33: the per-app notification switches move into appsettings.hl's Stylemre
  • 2249945cident#33: the inbox and connection list rules move into inbox.hl's Stylemre
  • f2d9f79fident#33: the apps list and the secret box move into apps.hl's Stylemre