Skip to content

Commit

Permalink
feat(ui): expose manual toggle red dot function (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: kirillgroshkov <kirill.groshkov@naturalcycles.com>
  • Loading branch information
anthonwellsjo and kirillgroshkov authored Oct 16, 2023
1 parent dd856d4 commit 125ccda
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/admin/adminService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class AdminService {

this.adminMode = !!localStorage.getItem(this.cfg.localStorageKey)

if (this.adminMode) this.toggleRedDot()
if (this.adminMode) this.toggleRedDotVisibility()

document.addEventListener('keydown', this.keydownListener.bind(this), { passive: true })

Expand All @@ -107,7 +107,10 @@ export class AdminService {
private async keydownListener(e: KeyboardEvent): Promise<void> {
// console.log(e)
if (!this.cfg.predicate(e)) return
await this.toggleRedDot()
}

async toggleRedDot(): Promise<void> {
try {
const allow = await this.cfg[this.adminMode ? 'beforeExit' : 'beforeEnter']()
if (!allow) return // no change
Expand All @@ -120,7 +123,7 @@ export class AdminService {

this.adminMode = !this.adminMode

this.toggleRedDot()
this.toggleRedDotVisibility()

if (this.cfg.persistToLocalStorage) {
const { localStorageKey } = this.cfg
Expand All @@ -134,7 +137,7 @@ export class AdminService {
this.cfg.onChange(this.adminMode)
}

private toggleRedDot(): void {
private toggleRedDotVisibility(): void {
this.getRedDotElement().style.display = this.adminMode ? 'block' : 'none'
}

Expand Down

0 comments on commit 125ccda

Please sign in to comment.