diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-03-07 13:50:26 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-03-10 16:22:52 +0100 |
commit | 3b20bdd6dc7402b0723e038c57f0606131e20e54 (patch) | |
tree | 68b203892c15c524f57651bfda7e6d5c0e920443 /client/src/app/core | |
parent | 7b81edc854902a536083298472bf92bb6726edcf (diff) | |
download | PeerTube-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.ts | 2 | ||||
-rw-r--r-- | client/src/app/core/menu/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/menu/menu.service.ts | 32 | ||||
-rw-r--r-- | client/src/app/core/routing/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/routing/menu-guard.service.ts | 48 | ||||
-rw-r--r-- | client/src/app/core/theme/theme.service.ts | 1 |
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' | |||
13 | import { LoginGuard, RedirectService, UserRightGuard } from './routing' | 13 | import { LoginGuard, RedirectService, UserRightGuard } from './routing' |
14 | import { ServerService } from './server' | 14 | import { ServerService } from './server' |
15 | import { ThemeService } from './theme' | 15 | import { ThemeService } from './theme' |
16 | import { MenuService } from './menu' | ||
16 | import { HotkeyModule } from 'angular2-hotkeys' | 17 | import { HotkeyModule } from 'angular2-hotkeys' |
17 | import { CheatSheetComponent } from './hotkeys' | 18 | import { CheatSheetComponent } from './hotkeys' |
18 | import { ToastModule } from 'primeng/toast' | 19 | import { 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 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
3 | import { fromEvent } from 'rxjs' | ||
4 | import { debounceTime } from 'rxjs/operators' | ||
5 | |||
6 | @Injectable() | ||
7 | export 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' | |||
2 | export * from './user-right-guard.service' | 2 | export * from './user-right-guard.service' |
3 | export * from './preload-selected-modules-list' | 3 | export * from './preload-selected-modules-list' |
4 | export * from './redirect.service' | 4 | export * from './redirect.service' |
5 | export * 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 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { CanActivate, CanDeactivate } from '@angular/router' | ||
3 | import { MenuService } from '@app/core/menu' | ||
4 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
5 | |||
6 | abstract 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() | ||
25 | export class OpenMenuGuard extends MenuGuard { | ||
26 | constructor (menu: MenuService, screen: ScreenService) { super(menu, screen, true) } | ||
27 | } | ||
28 | |||
29 | @Injectable() | ||
30 | export class CloseMenuGuard extends MenuGuard { | ||
31 | constructor (menu: MenuService, screen: ScreenService) { super(menu, screen, false) } | ||
32 | } | ||
33 | |||
34 | @Injectable() | ||
35 | export 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' | |||
8 | import { User } from '@app/shared/users/user.model' | 8 | import { User } from '@app/shared/users/user.model' |
9 | import { UserService } from '@app/shared/users/user.service' | 9 | import { UserService } from '@app/shared/users/user.service' |
10 | import { LocalStorageService } from '@app/shared/misc/storage.service' | 10 | import { LocalStorageService } from '@app/shared/misc/storage.service' |
11 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage' | ||
12 | 11 | ||
13 | @Injectable() | 12 | @Injectable() |
14 | export class ThemeService { | 13 | export class ThemeService { |