Client: better confirm box for a beautiful world
[oweals/peertube.git] / client / src / app / app.module.ts
1 import { ApplicationRef, NgModule } from '@angular/core';
2 import { BrowserModule } from '@angular/platform-browser';
3 import { removeNgStyles, createNewHosts } from '@angularclass/hmr';
4
5 import { MetaModule, MetaConfig } from 'ng2-meta';
6 import 'bootstrap-loader';
7
8 import { ENV_PROVIDERS } from './environment';
9 import { AppRoutingModule } from './app-routing.module';
10 import { AppComponent } from './app.component';
11 import { AppState } from './app.service';
12
13 import { AccountModule } from './account';
14 import { CoreModule } from './core';
15 import { LoginModule } from './login';
16 import { SharedModule } from './shared';
17 import { VideosModule } from './videos';
18
19 const metaConfig: MetaConfig = {
20   //Append a title suffix such as a site name to all titles
21   //Defaults to false
22   useTitleSuffix: true,
23   defaults: {
24     title: 'PeerTube'
25   }
26 };
27
28 // Application wide providers
29 const APP_PROVIDERS = [
30   AppState
31 ];
32
33 @NgModule({
34   bootstrap: [ AppComponent ],
35   declarations: [
36     AppComponent
37   ],
38   imports: [
39     BrowserModule,
40
41     CoreModule,
42     SharedModule,
43
44     AppRoutingModule,
45
46     MetaModule.forRoot(metaConfig),
47
48     AccountModule,
49     CoreModule,
50     LoginModule,
51     SharedModule,
52     VideosModule
53   ],
54   providers: [ // expose our Services and Providers into Angular's dependency injection
55     ENV_PROVIDERS,
56     APP_PROVIDERS
57   ]
58 })
59 export class AppModule {
60   constructor(public appRef: ApplicationRef, public appState: AppState) {}
61   hmrOnInit(store) {
62     if (!store || !store.state) return;
63     console.log('HMR store', store);
64     this.appState._state = store.state;
65     this.appRef.tick();
66     delete store.state;
67   }
68   hmrOnDestroy(store) {
69     const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
70     // recreate elements
71     const state = this.appState._state;
72     store.state = state;
73     store.disposeOldHosts = createNewHosts(cmpLocation);
74     // remove styles
75     removeNgStyles();
76   }
77   hmrAfterDestroy(store) {
78     // display new elements
79     store.disposeOldHosts();
80     delete store.disposeOldHosts;
81   }
82 }