Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move lang out of ngRedux store, add GoogleMaterialModule #398

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const CLOSE_SIDEBARS = 'CLOSE_SIDEBARS';
export const NAVIGATE_TO_FOUNTAIN = 'NAVIGATE_TO_FOUNTAIN';
export const UPDATE_FILTER_CATEGORIES = 'UPDATE_FILTER_CATEGORIES';
export const CLOSE_NAVIGATION = 'CLOSE_NAVIGATION';
export const CHANGE_LANG = 'CHANGE_LANG';
export const CHANGE_CITY = 'CHANGE_CITY';
export const CHANGE_MODE = 'CHANGE_MODE';
export const CHANGE_TRAVEL_MODE = 'CHANGE_TRAVEL_MODE';
Expand Down
11 changes: 3 additions & 8 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { DialogConfig, hideIntroVar } from './constants';
import { IssueListComponent } from './issue-list/issue-list.component';
import { finalize } from 'rxjs/operators';
import { IntroWindowComponent } from './intro-window/intro-window.component';
import { TranslateService } from '@ngx-translate/core';
import { LanguageService } from './core/language.service';

@Component({
selector: 'app-root',
Expand All @@ -29,7 +29,6 @@ import { TranslateService } from '@ngx-translate/core';
export class AppComponent implements OnInit {
title = 'app';
@select() mode;
@select() lang;
@select() showList;
@select() showMenu;
@select() previewState;
Expand All @@ -51,7 +50,7 @@ export class AppComponent implements OnInit {
public media: MediaMatcher,
private dialog: MatDialog,
private ngRedux: NgRedux<IAppState>,
private translate: TranslateService,
private languageService: LanguageService,
private iconRegistry: MatIconRegistry,
private sanitizer: DomSanitizer
) {
Expand Down Expand Up @@ -89,11 +88,7 @@ export class AppComponent implements OnInit {

ngOnInit(): void {
this.broadcastMediaChange();
// MultiLanguages functionality default is en (English)
this.translate.use(this.ngRedux.getState().lang);
this.lang.subscribe(s => {
this.translate.use(s);
});
this.languageService.init();

this.showList.subscribe(show => {
if (this.listDrawer) {
Expand Down
117 changes: 27 additions & 90 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,18 @@

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgRedux, NgReduxModule, DevToolsExtension } from '@angular-redux/store';
import { NgRedux, DevToolsExtension, NgReduxModule } from '@angular-redux/store';

import { AppComponent } from './app.component';
import { NavbarComponent } from './navbar/navbar.component';
import { MapComponent } from './map/map.component';
import { ListComponent } from './list/list.component';
import { IAppState, INITIAL_STATE, rootReducer } from './store';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { DataService } from './data.service';
import { MapConfig } from './map/map.config';
import { FormsModule } from '@angular/forms';
import { DetailComponent } from './detail/detail.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgProgressModule } from '@ngx-progressbar/core';
import { NgProgressHttpModule } from '@ngx-progressbar/http';
import { MatBadgeModule } from '@angular/material/badge';
import { MatBottomSheetModule } from '@angular/material/bottom-sheet';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { MatDialogModule } from '@angular/material/dialog';
import { MatDividerModule } from '@angular/material/divider';
import { MatExpansionModule } from '@angular/material/expansion';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatListModule } from '@angular/material/list';
import { MatMenuModule } from '@angular/material/menu';
import { MatRadioModule } from '@angular/material/radio';
import { MatSelectModule } from '@angular/material/select';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatSliderModule } from '@angular/material/slider';
import { MatTableModule } from '@angular/material/table';
import { MatTabsModule } from '@angular/material/tabs';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatTooltipModule } from '@angular/material/tooltip';
import { MediaMatcher } from '@angular/cdk/layout';
import { MobileMenuComponent } from './mobile-menu/mobile-menu.component';
import { FilterComponent } from './filter/filter.component';
Expand All @@ -60,9 +35,6 @@ import { FountainPropertyBadgeComponent } from './fountain-property-badge/founta
import { FountainPropertyDialogComponent } from './fountain-property-dialog/fountain-property-dialog.component';
import { TruncatePipe } from './pipes/truncate';
import { MinuteSecondsPipe } from './pipes/minute.seconds';
// Imports for Multilingual Integration
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { StateSelectorComponent } from './state-selector/state-selector.component';
import { RouterModule } from '@angular/router';
import { RouterComponent } from './router/router.component';
Expand All @@ -71,15 +43,17 @@ import { NgxGalleryModule } from '@kolkov/ngx-gallery';
import { IssueIndicatorComponent } from './issue-indicator/issue-indicator.component';
import { IssueListComponent } from './issue-list/issue-list.component';

// Locales
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
import localeDe from '@angular/common/locales/de';
import localeIt from '@angular/common/locales/it';
import localeTr from '@angular/common/locales/tr';
import { IntroWindowComponent } from './intro-window/intro-window.component';
import { LegendComponent } from './legend/legend.component';
import { EscapeHtmlPipe } from './pipes/keep-html.pipe';
import { GoogleMaterialModule } from './core/google-material.module';
import { NgProgressHttpModule } from '@ngx-progressbar/http';
import { NgProgressModule } from '@ngx-progressbar/core';
import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
import { NavbarComponent } from './navbar/navbar.component';
import { LanguageSelectorComponent } from './core/language-selector.component';
import { LanguageService } from './core/language.service';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';

@NgModule({
declarations: [
Expand Down Expand Up @@ -109,6 +83,7 @@ import { EscapeHtmlPipe } from './pipes/keep-html.pipe';
CallToActionComponent,
IntroWindowComponent,
LegendComponent,
LanguageSelectorComponent,
],
entryComponents: [
GuideSelectorComponent,
Expand All @@ -121,50 +96,26 @@ import { EscapeHtmlPipe } from './pipes/keep-html.pipe';
IntroWindowComponent,
],
imports: [
GoogleMaterialModule,
BrowserAnimationsModule,
BrowserModule,
FormsModule,
NgxGalleryModule,
HttpClientModule,
MatBadgeModule,
MatBottomSheetModule,
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatDialogModule,
MatSnackBarModule,
MatDividerModule,
MatExpansionModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatListModule,
MatMenuModule,
MatRadioModule,
MatSelectModule,
MatSidenavModule,
MatSliderModule,
MatTableModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule,
NgProgressModule.forRoot(),
NgProgressHttpModule.forRoot(),
NgReduxModule,
RouterModule.forRoot(
[
{
path: ':city',
component: RouterComponent,
},
{
path: '',
redirectTo: '/ch-zh',
pathMatch: 'full',
},
],
{ useHash: false, relativeLinkResolution: 'legacy' }
),
HttpClientModule,
RouterModule.forRoot([
{
path: ':city',
component: RouterComponent,
},
{
path: '',
redirectTo: '/ch-zh',
pathMatch: 'full',
},
]),
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
Expand All @@ -173,8 +124,8 @@ import { EscapeHtmlPipe } from './pipes/keep-html.pipe';
},
}),
],
exports: [TranslateModule, RouterModule],
providers: [DataService, ListComponent, MapConfig, MediaMatcher],
exports: [RouterModule, TranslateModule, NavbarComponent, LanguageSelectorComponent],
providers: [TranslateService, LanguageService, DataService, ListComponent, MapConfig, MediaMatcher],
bootstrap: [AppComponent],
})
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
Expand All @@ -183,25 +134,11 @@ export class AppModule {
// When DevTools is active, the page shows up blank on browsers other than chrome
const enhancers = devTools.isEnabled() ? [devTools.enhancer()] : [];
ngRedux.configureStore(rootReducer, INITIAL_STATE, [], enhancers);

// hide address bar after load
// window.addEventListener("load",function() {
// setTimeout(function(){
// // This hides the address bar:
// window.scrollTo(0, 1);
// }, 0);
// });
}
}

// Multilingual HttpLoader
// AoT requires an exported function for factories
export function HttpLoaderFactory(http: HttpClient) {
function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
}

// Register locales
registerLocaleData(localeFr, 'fr');
registerLocaleData(localeDe, 'de');
registerLocaleData(localeIt, 'it');
registerLocaleData(localeTr, 'tr');
77 changes: 77 additions & 0 deletions src/app/core/google-material.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { NgModule } from '@angular/core';
import { MatBadgeModule } from '@angular/material/badge';
import { MatBottomSheetModule } from '@angular/material/bottom-sheet';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatDialogModule } from '@angular/material/dialog';
import { MatDividerModule } from '@angular/material/divider';
import { MatExpansionModule } from '@angular/material/expansion';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatListModule } from '@angular/material/list';
import { MatMenuModule } from '@angular/material/menu';
import { MatRadioModule } from '@angular/material/radio';
import { MatSelectModule } from '@angular/material/select';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatSliderModule } from '@angular/material/slider';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { MatTableModule } from '@angular/material/table';
import { MatTabsModule } from '@angular/material/tabs';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatTooltipModule } from '@angular/material/tooltip';
import { MatFormFieldModule, MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field';

@NgModule({
imports: [
MatBadgeModule,
MatBottomSheetModule,
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatDialogModule,
MatSnackBarModule,
MatDividerModule,
MatExpansionModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatListModule,
MatMenuModule,
MatRadioModule,
MatSelectModule,
MatSidenavModule,
MatSliderModule,
MatTableModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule,
],
exports: [
MatBadgeModule,
MatBottomSheetModule,
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatDialogModule,
MatSnackBarModule,
MatDividerModule,
MatExpansionModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatListModule,
MatMenuModule,
MatRadioModule,
MatSelectModule,
MatSidenavModule,
MatSliderModule,
MatTableModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule,
],
providers: [{ provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { appearance: 'outline' } }],
})
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class GoogleMaterialModule {}
Empty file.
5 changes: 5 additions & 0 deletions src/app/core/language-selector.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<mat-form-field>
<mat-select class="responsive" (selectionChange)="changeLocale($event)" [value]="langObservable | async">
<mat-option *ngFor="let l of languages" [value]="l">{{ 'lang.' + l | translate }}</mat-option>
</mat-select>
</mat-form-field>
23 changes: 23 additions & 0 deletions src/app/core/language-selector.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NgRedux } from '@angular-redux/store';
import { Component } from '@angular/core';
import { TOGGLE_MENU } from '../actions';
import { IAppState } from '../store';
import { LanguageService } from './language.service';

@Component({
selector: 'app-lang-select',
templateUrl: './language-selector.component.html',
styleUrls: ['./language-selector.component.css'],
})
export class LanguageSelectorComponent {
constructor(private languageService: LanguageService, private ngRedux: NgRedux<IAppState>) {}

public languages = this.languageService.languages;
public langObservable = this.languageService.langObservable;

changeLocale(event: { value: string }) {
this.languageService.changeLang(event.value);
// TODO replace by a service call
this.ngRedux.dispatch({ type: TOGGLE_MENU, payload: false });
}
}
Loading