Skip to content

Commit

Permalink
Explicit imports from notifications.js
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzen committed Jan 5, 2024
1 parent e5ccb14 commit bcd0441
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions client/webserver/site/src/js/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import State from './state'
import { postJSON } from './http'
import * as forms from './forms'
import * as intl from './locales'
import * as ntfn from './notifications'
import {
updateNtfnSetting,
DesktopNtfnSetting,
fetchDesktopNtfnSettings,
desktopNtfnLabels,
Notifier
} from './notifications'
import {
app,
Exchange,
Expand Down Expand Up @@ -180,18 +186,18 @@ export default class SettingsPage extends BasePage {
const noteType = checkbox.getAttribute('name')
if (noteType === null) return
const enabled = checkbox.checked
ntfn.updateNtfnSetting(noteType, enabled)
updateNtfnSetting(noteType, enabled)
}

getBrowserNtfnSettings (): ntfn.DesktopNtfnSetting {
const permissions = ntfn.fetchDesktopNtfnSettings()
getBrowserNtfnSettings (): DesktopNtfnSetting {
const permissions = fetchDesktopNtfnSettings()
return permissions
}

async renderDesktopNtfnSettings () {
const page = this.page
const ntfnSettings = this.getBrowserNtfnSettings()
const labels = ntfn.desktopNtfnLabels
const labels = desktopNtfnLabels
const tmpl = page.browserNtfnCheckboxTemplate
tmpl.removeAttribute('id')
const container = page.browserNtfnCheckboxContainer
Expand All @@ -211,25 +217,25 @@ export default class SettingsPage extends BasePage {
const enabledCheckbox = page.browserNtfnEnabled

Doc.bind(enabledCheckbox, 'click', async (e: Event) => {
if (ntfn.Notifier.ntfnPermissionDenied()) return
if (Notifier.ntfnPermissionDenied()) return
const checkbox = e.target as HTMLInputElement
if (checkbox.checked) {
await ntfn.Notifier.requestNtfnPermission()
checkbox.checked = !ntfn.Notifier.ntfnPermissionDenied()
await Notifier.requestNtfnPermission()
checkbox.checked = !Notifier.ntfnPermissionDenied()
}
this.updateNtfnSetting(e)
checkbox.dispatchEvent(new Event('change'))
})

Doc.bind(enabledCheckbox, 'change', (e: Event) => {
const checkbox = e.target as HTMLInputElement
const permDenied = ntfn.Notifier.ntfnPermissionDenied()
const permDenied = Notifier.ntfnPermissionDenied()
Doc.setVis(checkbox.checked, page.browserNtfnCheckboxContainer)
Doc.setVis(permDenied, page.browserNtfnBlockedMsg)
checkbox.disabled = permDenied
})

enabledCheckbox.checked = (ntfn.Notifier.ntfnPermissionGranted() && ntfnSettings.browserNtfnEnabled)
enabledCheckbox.checked = (Notifier.ntfnPermissionGranted() && ntfnSettings.browserNtfnEnabled)
enabledCheckbox.dispatchEvent(new Event('change'))
}

Expand Down

0 comments on commit bcd0441

Please sign in to comment.