Skip to content

Commit 4e5a8a9

Browse files
committed
Load supporters settings notif instantly
1 parent cc291fa commit 4e5a8a9

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

src/scripts/features/supporters.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,43 +75,45 @@ export function supportersNotifications(init?: SupportersInit, update?: Supporte
7575
return
7676
}
7777

78-
// extracts notification template from index.html
79-
const template = document.getElementById('supporters-notif-template') as HTMLTemplateElement
80-
const doc = document.importNode(template.content, true)
81-
supportersNotif = doc.getElementById('supporters-notif-container') as HTMLElement
82-
8378
// resets closing and stores new month
8479
updateSupportersOption({
8580
closed: false,
8681
month: currentMonth,
8782
})
8883

84+
const settingsNotifs = document.getElementById('settings-notifications')
85+
const template = document.getElementById('supporters-notif-template') as HTMLTemplateElement
86+
const doc = document.importNode(template.content, true)
87+
88+
supportersNotif = doc.getElementById('supporters-notif-container') as HTMLElement
89+
settingsNotifs?.insertAdjacentElement('beforebegin', supportersNotif)
8990
supportersNotif.classList.add('shown')
9091
document.documentElement.dataset.supporters = ''
92+
}
9193

92-
onSettingsLoad(() => {
93-
const notifClose = doc.getElementById('supporters-notif-close')
94-
const settingsNotifs = document.getElementById('settings-notifications')
95-
const image = monthBackgrounds[currentMonth - 1]
94+
export function initSupportersSettingsNotif(supporters: Sync['supporters']) {
95+
// extracts notification template from index.html
96+
const template = document.getElementById('supporters-notif-template') as HTMLTemplateElement
97+
const doc = document.importNode(template.content, true)
98+
const notifClose = doc.getElementById('supporters-notif-close')
99+
const image = monthBackgrounds[supporters.month - 1]
96100

97-
supportersNotif.style.setProperty('--background', `url(${image})`)
98-
settingsNotifs?.insertAdjacentElement('beforebegin', supportersNotif)
101+
supportersNotif.style.setProperty('--background', `url(${image})`)
99102

100-
initSupportersModal()
101-
translateNotif()
103+
initSupportersModal()
104+
translateNotif()
102105

103-
onclickdown(supportersNotif, (e) => {
104-
if (e.target instanceof Element && !e.target.closest('#supporters-notif-close')) {
105-
toggleSupportersModal(true)
106-
loadModalData()
107-
}
108-
})
106+
onclickdown(supportersNotif, (e) => {
107+
if (e.target instanceof Element && !e.target.closest('#supporters-notif-close')) {
108+
toggleSupportersModal(true)
109+
loadModalData()
110+
}
111+
})
109112

110-
onclickdown(notifClose, () => {
111-
delete document.documentElement.dataset.supporters
112-
supportersNotif.classList.remove('shown')
113-
updateSupportersOption({ closed: true })
114-
})
113+
onclickdown(notifClose, () => {
114+
delete document.documentElement.dataset.supporters
115+
supportersNotif.classList.remove('shown')
116+
updateSupportersOption({ closed: true })
115117
})
116118
}
117119

src/scripts/settings.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { colorButtonStyling, darkmode, favicon, pageControl, tabTitle, textShadow } from './features/others.ts'
2+
import { initSupportersSettingsNotif, supportersNotifications } from './features/supporters.ts'
23
import { customFont, fontIsAvailableInSubset, systemfont } from './features/fonts.ts'
34
import { backgroundUpdate, initBackgroundOptions } from './features/backgrounds/index.ts'
45
import { changeGroupTitle, initGroups } from './features/links/groups.ts'
5-
import { supportersNotifications } from './features/supporters.ts'
66
import { synchronization } from './features/synchronization/index.ts'
77
import { interfacePopup } from './features/popup.ts'
88
import { moveElements } from './features/move/index.ts'
@@ -80,6 +80,7 @@ function settingsInitEvent(event: Event) {
8080
traduction(settings, sync.lang)
8181
translatePlaceholders()
8282
initBackgroundOptions(sync, local)
83+
initSupportersSettingsNotif(sync.supporters)
8384
initOptionsValues(sync, local)
8485
initOptionsEvents()
8586
settingsFooter()

0 commit comments

Comments
 (0)