gitoria

ident

All repositories: gitoria

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

Branches

Latest commits

  • 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
  • 8370b748ident#33: the app request box moves into home.hl's Stylemre
  • 40bf3b97ident#33: the 404 page's home link rule moves into notfound.hlmre
  • 40627a89ident#33: the time zone section's spacing moves into timezone.hlmre
  • d389db08ident#33: the identity page's rules and the Notif. chip move into identity.hl's Stylemre
  • ddda0b5bident#33: the identity row's parts move into identitylist.hl's Stylemre
  • 47e516afident#33 ident#34: the identity form's avatar rules move into identityform.hl; the preview and Remove button are hidden with the hidden attribute instead of built class strings (avatarPreviewClass, avatarRemoveClass gone)mre
  • 5cb5cf0eident#33: the code field's look moves into codestep.hl's Stylemre
  • f421cd60ident#33: the shell's own rules (user menu address, offline note, network probe) move into main.hl's Stylemre
  • c512fb96Merge branch 'f4-homesplit' into mainIdent
  • 07d1717c|||PR ident#40 home.hl is split into components, one per area: email step, identity form, identity list, app identity choice, time zone; each moves its faces with it, the email step is shared with embed.hl (#40.3, rest of #40.2)mre
  • 59e8fcc1ident#40.3: the app's identity choice is one component (components/chooseidentity.hl); its face chooseIdentity moves with itmre
  • e23efdfcident#40.3: the identity list is one component (components/identitylist.hl); its delete and face dropIdentity move with itmre
  • e24b59a6ident#40.3: the time zone is one component (components/timezone.hl); its face changeTimeZone moves with itmre
  • 8cbc5717ident#40.3: the email step is one component (components/emailstep.hl) placed by home.hl and embed.hlmre
  • 6fad3bd2Merge branch 'f3-codestep' into mainIdent
  • 51e387f2|||PR ident#40 the code step is one component (components/codestep.hl) placed by home.hl and embed.hl; its verify face, setCode, browserZone and verify call exist once (#40.2)mre