gitoria

ident

All repositories: gitoria

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

Branches

Latest commits

  • 8bb333ba|||PR ident#38 online state without probe timermre
  • 8d86b1f7|||PR ident#38 online state without probe timermre
  • fa4ed25bMerge branch 'f11-upsert' into mainIdent
  • 8f3d9bc9|||PR ident#42 keyed upsert and removemre
  • 675493b1ident#42: editing an identity upserts the one edited row (face editIdentity answers { identity, row }); a create or delete keeps the whole list because the rows' position-dependent parts (default, Delete, Identity n) changemre
  • 45e55303ident#42: an app write patches one row: upsert on create, edit and new secret, one-argument remove on delete; the faces answer the changed app (or the deleted id), not the whole listmre
  • 991641d4Merge branch 'f10-access' into mainIdent
  • e56d8273|||PR ident#34 part 4: access and inbox fixed classesmre
  • df7696dbident#34: tests: access ticks selector quoting fixmre
  • 7215903eident#34: access: the unstyled classes all, app, tick, apptick, plus are dropped; the gate finds the app ticks by input[name=app]mre
  • 69b0a0ceident#34: access: the pick buttons use Style.pickCard instead of class pickmre
  • dc702419Merge branch 'f9-choose' into mainIdent
  • 8caec771|||PR ident#34 restore .choose hookmre
  • 0dbff960Merge branch 'f8-shared' into mainIdent
  • d69665f6|||PR ident#34 part 3: shared look classes (wide, avatar, chip/used, conn, choose, who, inboxlink) moved to statics or droppedmre
  • 3a64dc48ident#34: chipLook: radius as the same var() string (a bare token name in a static does not compile); selector gate selectormre
  • eb039073ident#34: tests: signin and migration find the choice without the classmre
  • 4b94a594ident#34: tests: fix selector of the identity choicemre
  • bebc88e4ident#34: main.hl drops the unstyled classes inboxlink and whomre
  • b4e7ad04ident#34: the identity choice link/button has no class (rule on #chooselist a)mre