]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/app.module.ts
Update client modules
[github/Chocobozzz/PeerTube.git] / client / src / app / app.module.ts
CommitLineData
23bcf666 1import { ApplicationRef, NgModule } from '@angular/core';
ab32b0fc 2import { BrowserModule } from '@angular/platform-browser';
8635a2c7
C
3import {
4 removeNgStyles,
5 createNewHosts,
6 createInputTransfer
7} from '@angularclass/hmr';
ab32b0fc 8
758b996d 9import { MetaModule, MetaLoader, MetaStaticLoader, PageTitlePositioning } from '@nglibs/meta';
ad42bea3
C
10// TODO: remove, we need this to avoid error in ng2-smart-table
11import 'rxjs/add/operator/toPromise';
c16ce1de 12import 'bootstrap-loader';
b58c69a1 13
ab32b0fc 14import { ENV_PROVIDERS } from './environment';
693b1aba 15import { AppRoutingModule } from './app-routing.module';
ab32b0fc 16import { AppComponent } from './app.component';
8635a2c7 17import { AppState, InternalStateType } from './app.service';
23bcf666 18
693b1aba 19import { AccountModule } from './account';
693b1aba
C
20import { CoreModule } from './core';
21import { LoginModule } from './login';
a184c71b 22import { SignupModule } from './signup';
693b1aba
C
23import { SharedModule } from './shared';
24import { VideosModule } from './videos';
25
758b996d
C
26export function metaFactory(): MetaLoader {
27 return new MetaStaticLoader({
28 pageTitlePositioning: PageTitlePositioning.PrependPageTitle,
29 pageTitleSeparator: ' - ',
30 applicationName: 'PeerTube',
31 defaults: {
32 title: 'PeerTube',
33 description: 'PeerTube, a decentralized video streaming platform using P2P (BitTorrent) directly in the web browser'
34 }
35 });
36}
b58c69a1 37
8635a2c7
C
38type StoreType = {
39 state: InternalStateType,
40 restoreInputValues: () => void,
41 disposeOldHosts: () => void
42};
43
ab32b0fc
C
44// Application wide providers
45const APP_PROVIDERS = [
693b1aba 46 AppState
ab32b0fc 47];
693b1aba 48
ab32b0fc
C
49@NgModule({
50 bootstrap: [ AppComponent ],
51 declarations: [
50b0c262 52 AppComponent
ab32b0fc 53 ],
693b1aba 54 imports: [
ab32b0fc 55 BrowserModule,
23bcf666 56
693b1aba
C
57 CoreModule,
58 SharedModule,
59
60 AppRoutingModule,
b58c69a1 61
693b1aba 62 AccountModule,
693b1aba
C
63 CoreModule,
64 LoginModule,
a184c71b 65 SignupModule,
693b1aba 66 SharedModule,
55b33946
C
67 VideosModule,
68
69 MetaModule.forRoot({
70 provide: MetaLoader,
71 useFactory: (metaFactory)
72 })
ab32b0fc
C
73 ],
74 providers: [ // expose our Services and Providers into Angular's dependency injection
75 ENV_PROVIDERS,
76 APP_PROVIDERS
77 ]
78})
79export class AppModule {
8635a2c7
C
80 constructor(
81 public appRef: ApplicationRef,
82 public appState: AppState
83 ) {}
84
85 public hmrOnInit(store: StoreType) {
86 if (!store || !store.state) {
87 return;
88 }
89 console.log('HMR store', JSON.stringify(store, null, 2));
90 /**
91 * Set state
92 */
ab32b0fc 93 this.appState._state = store.state;
8635a2c7
C
94 /**
95 * Set input values
96 */
97 if ('restoreInputValues' in store) {
98 let restoreInputValues = store.restoreInputValues;
99 setTimeout(restoreInputValues);
100 }
101
ab32b0fc
C
102 this.appRef.tick();
103 delete store.state;
8635a2c7 104 delete store.restoreInputValues;
ab32b0fc 105 }
8635a2c7
C
106
107 public hmrOnDestroy(store: StoreType) {
108 const cmpLocation = this.appRef.components.map((cmp) => cmp.location.nativeElement);
109 /**
110 * Save state
111 */
ab32b0fc
C
112 const state = this.appState._state;
113 store.state = state;
8635a2c7
C
114 /**
115 * Recreate root elements
116 */
ab32b0fc 117 store.disposeOldHosts = createNewHosts(cmpLocation);
8635a2c7
C
118 /**
119 * Save input values
120 */
121 store.restoreInputValues = createInputTransfer();
122 /**
123 * Remove styles
124 */
ab32b0fc
C
125 removeNgStyles();
126 }
8635a2c7
C
127
128 public hmrAfterDestroy(store: StoreType) {
129 /**
130 * Display new elements
131 */
ab32b0fc
C
132 store.disposeOldHosts();
133 delete store.disposeOldHosts;
134 }
135}