gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf20313aaf20313aa|||PR bound calendar context and recover state across account changes and resyncsAtlasf20313aa/components/reminder-settings.hl

7.6 KB

  1. import { userIdOfSession } from '../lib/users.hl'
  2. import { settingsView } from '../lib/events.hl'
  3. import { saveDefaults } from '../lib/settings.hl'
  4. import { editRow, addRow, removeRow } from '../lib/reminder-rows.hl'
  5. // Reminder settings: calendar defaults and the device's notification controls.
  6. import { withIndex } from '../lib/reminders.hl'
  7. ownerId = null
  8. settingsOwner = null
  9. settingsEpoch = 0
  10. get ownerId() { return settingsOwner }
  11. set ownerId(String value) {
  12. if (value != settingsOwner) {
  13. settingsOwner = value
  14. settingsEpoch = settingsEpoch + 1
  15. settingsOpen = false
  16. setRows = []
  17. setError = ''
  18. }
  19. }
  20. Hybrid setRows = []
  21. String setError = ''
  22. Boolean settingsOpen = false
  23. String askClass = 'hidden'
  24. String blockedClass = 'hidden'
  25. String plannedText = ''
  26. String pushText = ''
  27. String pushOffClass = 'hidden'
  28. Style {
  29. reminderBox {
  30. display = 'grid'
  31. gap = '.4rem'
  32. h3 {
  33. margin = '0'
  34. fontSize = '.85rem'
  35. fontWeight = '600'
  36. color = 'var(--color-text-muted, rgb(145, 150, 155))'
  37. }
  38. p {
  39. margin = '0'
  40. fontSize = '.85rem'
  41. color = 'var(--color-text-muted, rgb(145, 150, 155))'
  42. }
  43. }
  44. '#set-rows' {
  45. display = 'grid'
  46. gridTemplateColumns = 'minmax(0, 1fr)'
  47. gap = '.5rem'
  48. margin = '0'
  49. padding = '0'
  50. listStyle = 'none'
  51. }
  52. reminderRow {
  53. display = 'grid'
  54. gridTemplateColumns = '5rem minmax(0, 1fr) 2.75rem'
  55. alignItems = 'center'
  56. gap = '.4rem'
  57. input {
  58. minWidth = '0'
  59. width = '100%'
  60. }
  61. select {
  62. minWidth = '0'
  63. width = '100%'
  64. gridColumn = '2'
  65. }
  66. 'input[type=time]' {
  67. gridColumn = '1 / 3'
  68. }
  69. button {
  70. gridColumn = '3'
  71. gridRow = '1'
  72. minWidth = '2.75rem'
  73. minHeight = '2.75rem'
  74. padding = '0'
  75. }
  76. }
  77. 'reminder-row.other' {
  78. 'input[type=time]' {
  79. display = 'none'
  80. }
  81. }
  82. formButtons {
  83. display = 'flex'
  84. flexWrap = 'wrap'
  85. gap = '.5rem'
  86. 'button.danger' {
  87. marginLeft = 'auto'
  88. }
  89. }
  90. eventEditor {
  91. position = 'fixed'
  92. inset = '0'
  93. zIndex = '40'
  94. display = 'grid'
  95. placeItems = 'center'
  96. padding = '1rem'
  97. background = 'color-mix(in srgb, var(--color-background-sunken) 82%, transparent)'
  98. form {
  99. display = 'grid'
  100. gap = '.7rem'
  101. width = '100%'
  102. maxWidth = '28rem'
  103. maxHeight = '100%'
  104. overflowY = 'auto'
  105. padding = '1rem'
  106. background = 'var(--color-surface)'
  107. borderRadius = 'var(--radius-large)'
  108. }
  109. h2 {
  110. margin = '0'
  111. }
  112. input {
  113. width = '100%'
  114. color = 'var(--color-text-strong)'
  115. }
  116. }
  117. 'event-editor.closed' {
  118. display = 'none'
  119. }
  120. 'event-editor[popover]' {
  121. width = '100%'
  122. height = '100%'
  123. maxWidth = 'none'
  124. maxHeight = 'none'
  125. margin = '0'
  126. border = '0'
  127. overflow = 'hidden'
  128. color = 'var(--color-text)'
  129. }
  130. 'event-editor[popover]:not(:popover-open)' {
  131. display = 'none'
  132. }
  133. @media {
  134. minWidth = '60rem'
  135. reminderRow {
  136. gridTemplateColumns = '5rem minmax(0, 1fr) 7.5rem 2.75rem'
  137. 'input[type=time]' {
  138. gridColumn = '3'
  139. }
  140. button {
  141. gridColumn = '4'
  142. }
  143. }
  144. 'reminder-row.other' {
  145. select {
  146. gridColumn = '2 / 4'
  147. }
  148. }
  149. }
  150. notifyBox {
  151. display = 'grid'
  152. gap = '.5rem'
  153. h3 {
  154. margin = '0'
  155. fontSize = '.85rem'
  156. fontWeight = '600'
  157. color = 'var(--color-text-muted, rgb(145, 150, 155))'
  158. }
  159. p {
  160. margin = '0'
  161. fontSize = '.85rem'
  162. color = 'var(--color-text-muted, rgb(145, 150, 155))'
  163. empty {
  164. display = 'none'
  165. }
  166. }
  167. button {
  168. width = '100%'
  169. }
  170. }
  171. '#notify-ask' {
  172. color = 'var(--color-accent-text)'
  173. background = 'var(--color-accent)'
  174. }
  175. '.hidden' {
  176. display = 'none'
  177. }
  178. }
  179. View {
  180. eventEditor { id = "settingseditor" popover = "manual" popoverOpen = settingsOpen on toggle(Hybrid e) { emit settingsToggled(e) } on keydown(Hybrid e) { emit settingsKey(e) }
  181. form { id = "settingsform" class = "timed"
  182. on submit(Hybrid e) {
  183. e.preventDefault()
  184. emit saveSettings(e)
  185. }
  186. h2 { "Reminder settings" }
  187. notifyBox {
  188. h3 { "Notifications on this device" }
  189. p { id = "notify-blocked" class = blockedClass "Notifications are blocked for this site in the browser settings." }
  190. p { id = "notify-planned" plannedText }
  191. p { id = "push-state" pushText }
  192. button { id = "notify-ask" type = "button" class = askClass "Turn on notifications" on click(Hybrid e) { $parent.askNotify(e) } }
  193. button { id = "push-test" type = "button" class = pushOffClass "Send a test notification" on click(Hybrid e) { $parent.pushTest(e) } }
  194. button { id = "push-off" type = "button" class = pushOffClass "Turn off on this device" on click(Hybrid e) { $parent.pushOff(e) } }
  195. }
  196. reminderBox {
  197. h3 { "Default reminders" }
  198. p { class = "muted" "Every event without reminders of its own is reminded like this:" }
  199. ol { id = "set-rows"
  200. for (r of setRows) {
  201. reminderRow { class = r.cls
  202. input { type = "number" min = "0" value = r.n on change(Hybrid e) { emit setDefaultRow('set', r.i, 'n', e.target.value) } }
  203. select { value = r.unit on change(Hybrid e) { emit setDefaultRow('set', r.i, 'unit', e.target.value) }
  204. option { value = "minutes" "minutes before" }
  205. option { value = "hours" "hours before" }
  206. option { value = "days" "days before, at" }
  207. }
  208. input { type = "time" value = r.time on change(Hybrid e) { emit setDefaultRow('set', r.i, 'time', e.target.value) } }
  209. button { type = "button" class = "quiet" "×" on click(Hybrid e) { emit delDefaultRow('set', r.i) } }
  210. }
  211. }
  212. }
  213. button { id = "set-add" type = "button" class = "quiet" "Add reminder" on click(Hybrid e) { emit addDefaultRow('set') } }
  214. }
  215. p { id = "settingserror" class = "message" setError }
  216. formButtons {
  217. button { id = "set-save" type = "submit" "Save" }
  218. button { id = "set-cancel" type = "button" class = "quiet" popovertarget = "settingseditor" popovertargetaction = "hide" autofocus = "autofocus" "Cancel" }
  219. }
  220. }
  221. }
  222. }
  223. on setDefaultRow(String which, Number i, String field, String value) {
  224. setRows = editRow(setRows, i, field, value)
  225. }
  226. on addDefaultRow(String which) {
  227. setRows = addRow(setRows)
  228. }
  229. on delDefaultRow(String which, Number i) {
  230. setRows = removeRow(setRows, i)
  231. }
  232. on settingsToggled(Hybrid e) {
  233. settingsOpen = e.newState == 'open'
  234. if (e.newState != 'open') { return null }
  235. // no pointer event of the month view may have come yet, so the page's browser state is read now —
  236. // the notification section is right on the first look (and a device that allowed notifications is subscribed)
  237. $parent.refreshDevice()
  238. owner = ownerId
  239. epoch = settingsEpoch
  240. r = emit server calSettingsLoad()
  241. if (owner != ownerId || epoch != settingsEpoch) { return null }
  242. if (r == null || r.error != null) {
  243. setError = r == null ? 'the settings need the server: you are offline' : r.error
  244. return null
  245. }
  246. setRows = withIndex(r.rows)
  247. setError = ''
  248. }
  249. on settingsKey(Hybrid e) {
  250. if (e.key == 'Escape') { settingsOpen = false }
  251. }
  252. on saveSettings(Hybrid e) {
  253. owner = ownerId
  254. epoch = settingsEpoch
  255. r = emit server calSettingsSave(setRows, owner)
  256. if (owner != ownerId || epoch != settingsEpoch) { return null }
  257. if (r == null || r.error != null) {
  258. setError = r == null ? 'the settings could not be saved (offline?)' : r.error
  259. return null
  260. }
  261. settingsOpen = false
  262. $parent.takeSoon(r)
  263. }
  264. on server calSettingsLoad(session) {
  265. u = userIdOfSession(session)
  266. if (u == null) { return { error = 'log in with ident first' } }
  267. return settingsView(u)
  268. }
  269. on server calSettingsSave(rows, expectedOwner, session) {
  270. u = userIdOfSession(session)
  271. if (u == null) { return { error = 'log in with ident first' } }
  272. if (expectedOwner != null && expectedOwner != u) { return { error = 'the account changed' } }
  273. r = saveDefaults(u, rows)
  274. if (r.error != null) { return { error = r.error } }
  275. emit client calendarChanged(u, [], settingsView(u))
  276. return settingsView(u)
  277. }

Branches

Latest commits

  • f20313aa|||PR bound calendar context and recover state across account changes and resyncsAtlas
  • 651752c0|||PR run the browser gate once per deployAtlas
  • e24e28a1|||PR preserve calendar state across month addresses and split dialogsAtlas
  • 384d3d23|||PR give calendar months their own addressAtlas
  • fff2f537Merge branch 'calendar31-lib' into mainAtlas
  • 07cde3dc|||PR keep worker records out of the repo; README vendor is day72Atlas
  • a753b0ab|||PR move shared calendar logic to libAtlas
  • b32a921dMerge branch 'vendor-day72' into mainAtlas
  • 60a0dd19|||PR Hybriel day72 (00c9dbb8) instead of the withdrawn day73Atlas
  • 53f5464dMerge branch 'calendar26-day73' into mainAtlas
  • 338499ec|||PR Keep reminder settings open during editing and rejected savesAtlas
  • ad9e8d59|||PR Use framework page and popover state, Hybriel day73Atlas
  • cab224a1Re-vendor calendar to verified Hybriel day73Atlas
  • f9b8f918Merge branch 'calendar-vendor-day61' into mainAtlas
  • 66341793|||PR Vendor Hybriel day61Atlas
  • 36fc596bMerge branch 'vendor-day59' into mainAtlas
  • b37cc1da|||PR Vendor Hybriel day59Atlas
  • 05665102Merge branch 'vendor-day56' into mainAtlas
  • 687296fb|||PR Vendor Hybriel day56Atlas
  • a6166d4eMerge branch 'hl-standard-3' into mainAtlas