aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-03-07 13:50:26 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-03-10 16:22:52 +0100
commit3b20bdd6dc7402b0723e038c57f0606131e20e54 (patch)
tree68b203892c15c524f57651bfda7e6d5c0e920443 /client/src/app/core
parent7b81edc854902a536083298472bf92bb6726edcf (diff)
downloadPeerTube-3b20bdd6dc7402b0723e038c57f0606131e20e54.tar.gz
PeerTube-3b20bdd6dc7402b0723e038c57f0606131e20e54.tar.zst
PeerTube-3b20bdd6dc7402b0723e038c57f0606131e20e54.zip
Servicify menu, close menu on admin for small and medium screens
Diffstat (limited to 'client/src/app/core')
-rw-r--r--client/src/app/core/core.module.ts2
-rw-r--r--client/src/app/core/menu/index.ts1
-rw-r--r--client/src/app/core/menu/menu.service.ts32
-rw-r--r--client/src/app/core/routing/index.ts1
-rw-r--r--client/src/app/core/routing/menu-guard.service.ts48
-rw-r--r--client/src/app/core/theme/theme.service.ts1
6 files changed, 84 insertions, 1 deletions
diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts
index 5943af4da..a1734ad80 100644
--- a/client/src/app/core/core.module.ts
+++ b/client/src/app/core/core.module.ts
@@ -13,6 +13,7 @@ import { throwIfAlreadyLoaded } from './module-import-guard'
13import { LoginGuard, RedirectService, UserRightGuard } from './routing' 13import { LoginGuard, RedirectService, UserRightGuard } from './routing'
14import { ServerService } from './server' 14import { ServerService } from './server'
15import { ThemeService } from './theme' 15import { ThemeService } from './theme'
16import { MenuService } from './menu'
16import { HotkeyModule } from 'angular2-hotkeys' 17import { HotkeyModule } from 'angular2-hotkeys'
17import { CheatSheetComponent } from './hotkeys' 18import { CheatSheetComponent } from './hotkeys'
18import { ToastModule } from 'primeng/toast' 19import { ToastModule } from 'primeng/toast'
@@ -59,6 +60,7 @@ import { HooksService } from '@app/core/plugins/hooks.service'
59 ConfirmService, 60 ConfirmService,
60 ServerService, 61 ServerService,
61 ThemeService, 62 ThemeService,
63 MenuService,
62 LoginGuard, 64 LoginGuard,
63 UserRightGuard, 65 UserRightGuard,
64 UnloggedGuard, 66 UnloggedGuard,
diff --git a/client/src/app/core/menu/index.ts b/client/src/app/core/menu/index.ts
new file mode 100644
index 000000000..516a49aca
--- /dev/null
+++ b/client/src/app/core/menu/index.ts
@@ -0,0 +1 @@
export * from './menu.service'
diff --git a/client/src/app/core/menu/menu.service.ts b/client/src/app/core/menu/menu.service.ts
new file mode 100644
index 000000000..46ef72e17
--- /dev/null
+++ b/client/src/app/core/menu/menu.service.ts
@@ -0,0 +1,32 @@
1import { Injectable } from '@angular/core'
2import { ScreenService } from '@app/shared/misc/screen.service'
3import { fromEvent } from 'rxjs'
4import { debounceTime } from 'rxjs/operators'
5
6@Injectable()
7export class MenuService {
8 isMenuDisplayed = true
9 isMenuChangedByUser = false
10
11 constructor(
12 private screenService: ScreenService
13 ) {
14 // Do not display menu on small screens
15 if (this.screenService.isInSmallView()) {
16 this.isMenuDisplayed = false
17 }
18
19 fromEvent(window, 'resize')
20 .pipe(debounceTime(200))
21 .subscribe(() => this.onResize())
22 }
23
24 toggleMenu () {
25 this.isMenuDisplayed = !this.isMenuDisplayed
26 this.isMenuChangedByUser = true
27 }
28
29 onResize () {
30 this.isMenuDisplayed = window.innerWidth >= 800 && !this.isMenuChangedByUser
31 }
32}
diff --git a/client/src/app/core/routing/index.ts b/client/src/app/core/routing/index.ts
index 9f0b4eac5..58b83bb2a 100644
--- a/client/src/app/core/routing/index.ts
+++ b/client/src/app/core/routing/index.ts
@@ -2,3 +2,4 @@ export * from './login-guard.service'
2export * from './user-right-guard.service' 2export * from './user-right-guard.service'
3export * from './preload-selected-modules-list' 3export * from './preload-selected-modules-list'
4export * from './redirect.service' 4export * from './redirect.service'
5export * from './menu-guard.service'
diff --git a/client/src/app/core/routing/menu-guard.service.ts b/client/src/app/core/routing/menu-guard.service.ts
new file mode 100644
index 000000000..907d145fd
--- /dev/null
+++ b/client/src/app/core/routing/menu-guard.service.ts
@@ -0,0 +1,48 @@
1import { Injectable } from '@angular/core'
2import { CanActivate, CanDeactivate } from '@angular/router'
3import { MenuService } from '@app/core/menu'
4import { ScreenService } from '@app/shared/misc/screen.service'
5
6abstract class MenuGuard implements CanActivate, CanDeactivate<any> {
7 display = true
8 canDeactivate = this.canActivate
9
10 constructor (protected menu: MenuService, protected screen: ScreenService, display: boolean) {
11 this.display = display
12 }
13
14 canActivate (): boolean {
15 // small screens already have the site-wide onResize from screenService
16 // > medium screens have enough space to fit the administrative menus
17 if (!this.screen.isInMobileView() && this.screen.isInMediumView()) {
18 this.menu.isMenuDisplayed = this.display
19 }
20 return true
21 }
22}
23
24@Injectable()
25export class OpenMenuGuard extends MenuGuard {
26 constructor (menu: MenuService, screen: ScreenService) { super(menu, screen, true) }
27}
28
29@Injectable()
30export class CloseMenuGuard extends MenuGuard {
31 constructor (menu: MenuService, screen: ScreenService) { super(menu, screen, false) }
32}
33
34@Injectable()
35export class MenuGuards {
36 public static guards = [
37 OpenMenuGuard,
38 CloseMenuGuard
39 ]
40
41 static open () {
42 return OpenMenuGuard
43 }
44
45 static close () {
46 return CloseMenuGuard
47 }
48}
diff --git a/client/src/app/core/theme/theme.service.ts b/client/src/app/core/theme/theme.service.ts
index 3c066ca74..c0189ad32 100644
--- a/client/src/app/core/theme/theme.service.ts
+++ b/client/src/app/core/theme/theme.service.ts
@@ -8,7 +8,6 @@ import { first } from 'rxjs/operators'
8import { User } from '@app/shared/users/user.model' 8import { User } from '@app/shared/users/user.model'
9import { UserService } from '@app/shared/users/user.service' 9import { UserService } from '@app/shared/users/user.service'
10import { LocalStorageService } from '@app/shared/misc/storage.service' 10import { LocalStorageService } from '@app/shared/misc/storage.service'
11import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage'
12 11
13@Injectable() 12@Injectable()
14export class ThemeService { 13export class ThemeService {