add resize listener (#1182)
* add resize listener * respect user decision * change listener to rxjs * review changes
This commit is contained in:
parent
4232d092bb
commit
a585824160
|
@ -4,9 +4,10 @@ import { GuardsCheckStart, NavigationEnd, Router } from '@angular/router'
|
||||||
import { AuthService, RedirectService, ServerService, ThemeService } from '@app/core'
|
import { AuthService, RedirectService, ServerService, ThemeService } from '@app/core'
|
||||||
import { is18nPath } from '../../../shared/models/i18n'
|
import { is18nPath } from '../../../shared/models/i18n'
|
||||||
import { ScreenService } from '@app/shared/misc/screen.service'
|
import { ScreenService } from '@app/shared/misc/screen.service'
|
||||||
import { skip } from 'rxjs/operators'
|
import { skip, debounceTime } from 'rxjs/operators'
|
||||||
import { HotkeysService, Hotkey } from 'angular2-hotkeys'
|
import { HotkeysService, Hotkey } from 'angular2-hotkeys'
|
||||||
import { I18n } from '@ngx-translate/i18n-polyfill'
|
import { I18n } from '@ngx-translate/i18n-polyfill'
|
||||||
|
import { fromEvent } from 'rxjs'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
|
@ -28,6 +29,7 @@ export class AppComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
isMenuDisplayed = true
|
isMenuDisplayed = true
|
||||||
|
isMenuChangedByUser = false
|
||||||
|
|
||||||
customCSS: SafeHtml
|
customCSS: SafeHtml
|
||||||
|
|
||||||
|
@ -165,6 +167,10 @@ export class AppComponent implements OnInit {
|
||||||
return false
|
return false
|
||||||
}, undefined, this.i18n('Toggle Dark theme'))
|
}, undefined, this.i18n('Toggle Dark theme'))
|
||||||
])
|
])
|
||||||
|
|
||||||
|
fromEvent(window, 'resize')
|
||||||
|
.pipe(debounceTime(200))
|
||||||
|
.subscribe(() => this.onResize())
|
||||||
}
|
}
|
||||||
|
|
||||||
isUserLoggedIn () {
|
isUserLoggedIn () {
|
||||||
|
@ -173,5 +179,10 @@ export class AppComponent implements OnInit {
|
||||||
|
|
||||||
toggleMenu () {
|
toggleMenu () {
|
||||||
this.isMenuDisplayed = !this.isMenuDisplayed
|
this.isMenuDisplayed = !this.isMenuDisplayed
|
||||||
|
this.isMenuChangedByUser = true
|
||||||
|
}
|
||||||
|
|
||||||
|
onResize () {
|
||||||
|
this.isMenuDisplayed = window.innerWidth >= 800 && !this.isMenuChangedByUser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue