]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/menu/menu.service.ts
Don't display account setup modal on signup
[github/Chocobozzz/PeerTube.git] / client / src / app / core / menu / menu.service.ts
CommitLineData
3b20bdd6
RK
1import { fromEvent } from 'rxjs'
2import { debounceTime } from 'rxjs/operators'
67ed6552 3import { Injectable } from '@angular/core'
2539932e 4import { GlobalIconName } from '@app/shared/shared-icons'
2989628b 5import { HTMLServerConfig } from '@shared/models/server'
67ed6552 6import { ScreenService } from '../wrappers'
3b20bdd6 7
2539932e
C
8export type MenuLink = {
9 icon: GlobalIconName
8beea2d3 10
2539932e 11 label: string
8beea2d3
C
12 // Used by the left menu for example
13 shortLabel: string
14
2539932e 15 path: string
8beea2d3
C
16}
17
18export type MenuSection = {
19 key: string
20 title: string
21 links: MenuLink[]
2539932e
C
22}
23
3b20bdd6
RK
24@Injectable()
25export class MenuService {
26 isMenuDisplayed = true
27 isMenuChangedByUser = false
9df52d66 28 menuWidth = 240 // should be kept equal to $menu-width
3b20bdd6 29
ac940348 30 constructor (
3b20bdd6
RK
31 private screenService: ScreenService
32 ) {
245b9d27
K
33 // Do not display menu on small or touch screens
34 if (this.screenService.isInSmallView() || this.screenService.isInTouchScreen()) {
35 this.setMenuDisplay(false)
3b20bdd6
RK
36 }
37
245b9d27 38 this.handleWindowResize()
3b20bdd6
RK
39 }
40
41 toggleMenu () {
245b9d27 42 this.setMenuDisplay(!this.isMenuDisplayed)
3b20bdd6
RK
43 this.isMenuChangedByUser = true
44 }
45
d95bc702
C
46 isDisplayed () {
47 return this.isMenuDisplayed
48 }
49
245b9d27
K
50 setMenuDisplay (display: boolean) {
51 this.isMenuDisplayed = display
52
1bfc7b73
C
53 if (!this.screenService.isInTouchScreen()) return
54
245b9d27 55 // On touch screens, lock body scroll and display content overlay when memu is opened
1bfc7b73
C
56 if (this.isMenuDisplayed) {
57 document.body.classList.add('menu-open')
9df52d66 58 this.screenService.onFingerSwipe('left', () => this.setMenuDisplay(false))
1bfc7b73 59 return
245b9d27 60 }
1bfc7b73
C
61
62 document.body.classList.remove('menu-open')
245b9d27
K
63 }
64
3b20bdd6
RK
65 onResize () {
66 this.isMenuDisplayed = window.innerWidth >= 800 && !this.isMenuChangedByUser
67 }
245b9d27 68
8beea2d3
C
69 buildLibraryLinks (userCanSeeVideosLink: boolean): MenuSection {
70 let links: MenuLink[] = []
71
72 if (userCanSeeVideosLink) {
73 links.push({
74 path: '/my-library/videos',
75 icon: 'videos' as GlobalIconName,
76 shortLabel: $localize`Videos`,
77 label: $localize`My videos`
78 })
79 }
80
81 links = links.concat([
82 {
83 path: '/my-library/video-playlists',
84 icon: 'playlists' as GlobalIconName,
85 shortLabel: $localize`Playlists`,
86 label: $localize`My playlists`
87 },
88 {
89 path: '/videos/subscriptions',
90 icon: 'subscriptions' as GlobalIconName,
91 shortLabel: $localize`Subscriptions`,
92 label: $localize`My subscriptions`
93 },
94 {
95 path: '/my-library/history/videos',
96 icon: 'history' as GlobalIconName,
97 shortLabel: $localize`History`,
98 label: $localize`My history`
99 }
100 ])
101
102 return {
103 key: 'in-my-library',
c3185413 104 title: $localize`In my library`,
8beea2d3
C
105 links
106 }
107 }
108
109 buildCommonLinks (config: HTMLServerConfig): MenuSection {
110 let links: MenuLink[] = []
111
112 if (config.homepage.enabled) {
113 links.push({
114 icon: 'home' as 'home',
115 label: $localize`Home`,
116 shortLabel: $localize`Home`,
117 path: '/home'
118 })
119 }
120
121 links = links.concat([
2539932e
C
122 {
123 icon: 'globe' as 'globe',
124 label: $localize`Discover videos`,
8beea2d3
C
125 shortLabel: $localize`Discover`,
126 path: '/videos/overview'
2539932e
C
127 },
128 {
129 icon: 'trending' as 'trending',
130 label: $localize`Trending videos`,
8beea2d3
C
131 shortLabel: $localize`Trending`,
132 path: '/videos/trending'
2539932e
C
133 },
134 {
135 icon: 'recently-added' as 'recently-added',
136 label: $localize`Recently added videos`,
8beea2d3
C
137 shortLabel: $localize`Recently added`,
138 path: '/videos/recently-added'
2539932e
C
139 },
140 {
5351a058 141 icon: 'local' as 'local',
2539932e 142 label: $localize`Local videos`,
8beea2d3
C
143 shortLabel: $localize`Local videos`,
144 path: '/videos/local'
2539932e 145 }
8beea2d3 146 ])
2539932e 147
8beea2d3
C
148 return {
149 key: 'on-instance',
150 title: $localize`ON ${config.instance.name}`,
151 links
2539932e 152 }
2539932e
C
153 }
154
245b9d27
K
155 private handleWindowResize () {
156 // On touch screens, do not handle window resize event since opened menu is handled with a content overlay
1bfc7b73 157 if (this.screenService.isInTouchScreen()) return
245b9d27
K
158
159 fromEvent(window, 'resize')
160 .pipe(debounceTime(200))
161 .subscribe(() => this.onResize())
162 }
3b20bdd6 163}