Add custom modal to plugin helpers (#2631)
[oweals/peertube.git] / client / src / app / app.module.ts
1 import { LOCALE_ID, NgModule, TRANSLATIONS, TRANSLATIONS_FORMAT } from '@angular/core'
2 import { BrowserModule } from '@angular/platform-browser'
3 import { ServerService } from '@app/core'
4 import { ResetPasswordModule } from '@app/reset-password'
5
6 import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
7 import 'focus-visible'
8
9 import { AppRoutingModule } from './app-routing.module'
10 import { AppComponent } from './app.component'
11 import { CoreModule } from './core'
12 import { HeaderComponent, SearchTypeaheadComponent, SuggestionsComponent, SuggestionComponent } from './header'
13 import { LoginModule } from './login'
14 import { AvatarNotificationComponent, LanguageChooserComponent, MenuComponent } from './menu'
15 import { SharedModule } from './shared'
16 import { VideosModule } from './videos'
17 import { SearchModule } from '@app/search'
18 import { WelcomeModalComponent } from '@app/modal/welcome-modal.component'
19 import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component'
20 import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '@shared/models'
21 import { APP_BASE_HREF } from '@angular/common'
22 import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component'
23 import { CustomModalComponent } from '@app/modal/custom-modal.component'
24
25 export function metaFactory (serverService: ServerService): MetaLoader {
26   return new MetaStaticLoader({
27     pageTitlePositioning: PageTitlePositioning.PrependPageTitle,
28     pageTitleSeparator: ' - ',
29     get applicationName () { return serverService.getTmpConfig().instance.name },
30     defaults: {
31       get title () { return serverService.getTmpConfig().instance.name },
32       get description () { return serverService.getTmpConfig().instance.shortDescription }
33     }
34   })
35 }
36
37 @NgModule({
38   bootstrap: [ AppComponent ],
39   declarations: [
40     AppComponent,
41
42     MenuComponent,
43     LanguageChooserComponent,
44     QuickSettingsModalComponent,
45     AvatarNotificationComponent,
46     HeaderComponent,
47     SearchTypeaheadComponent,
48     SuggestionsComponent,
49     SuggestionComponent,
50
51     CustomModalComponent,
52     WelcomeModalComponent,
53     InstanceConfigWarningModalComponent
54   ],
55   imports: [
56     BrowserModule,
57
58     CoreModule,
59     SharedModule,
60
61     CoreModule,
62     LoginModule,
63     ResetPasswordModule,
64     SearchModule,
65     SharedModule,
66     VideosModule,
67
68     MetaModule.forRoot({
69       provide: MetaLoader,
70       useFactory: (metaFactory),
71       deps: [ ServerService ]
72     }),
73
74     AppRoutingModule // Put it after all the module because it has the 404 route
75   ],
76
77   providers: [
78     {
79       provide: APP_BASE_HREF,
80       useValue: '/'
81     },
82
83     {
84       provide: TRANSLATIONS,
85       useFactory: (locale: string) => {
86         // Default locale, nothing to translate
87         const completeLocale = getCompleteLocale(locale)
88         if (isDefaultLocale(completeLocale)) return ''
89
90         const fileLocale = buildFileLocale(locale)
91         return require(`raw-loader!../locale/angular.${fileLocale}.xlf`).default
92       },
93       deps: [ LOCALE_ID ]
94     },
95     { provide: TRANSLATIONS_FORMAT, useValue: 'xlf' }
96   ]
97 })
98 export class AppModule {}