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