Skip to content

Commit

Permalink
add back icon
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmojicatech committed Dec 19, 2022
1 parent f0089ab commit 651bea9
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IonicModule } from '@ionic/angular';
import { Store } from '@ngrx/store';
import { BehaviorSubject, combineLatest, filter, map, Observable, Subject, take, takeUntil } from 'rxjs';
import { PositionTypes } from '../../../../../libs/fantalytic-shared/src';
import { setHasBackButton } from '../ngrx/actions/shared.actions';
import { loadDefenses, loadQbs, loadRbs, loadReceivers, setPositionType, updateYearFilter } from './ngrx/actions/fantasy-football.actions';
import { getDefenses, getPosition, getQbs, getRbs, getReceivers, getSelectedYear } from './ngrx/selectors/fantasy-football.selectors';

Expand Down Expand Up @@ -193,6 +194,7 @@ export class FantasyFootballComponent implements OnInit, OnDestroy {
}

handlePlayerSelected(playerId: string): void {
this._store.dispatch(setHasBackButton(true));
this._router.navigate(['tabs', 'fantasy-football', `player-details`, playerId]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content *ngIf="player$ | async as player">

<ion-card>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable arrow-body-style */
import { Component, inject } from '@angular/core';
import { Component, inject, OnDestroy } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ActivatedRoute } from '@angular/router';
import { combineLatest, EMPTY, map, shareReplay, switchMap } from 'rxjs';
Expand All @@ -8,6 +8,7 @@ import { getDefenses, getPosition, getQbs, getRbs, getReceivers } from '../ngrx/
import { PositionTypes } from '../../../../../../libs/fantalytic-shared/src';
import { IonicModule } from '@ionic/angular';
import { FANTASY_FOOTBALL_STAT_HEADER_MAP } from '../const/fantasy-football.const';
import { setHasBackButton } from 'src/app/ngrx/actions/shared.actions';

@Component({
selector: 'pmt-player-detail',
Expand All @@ -16,7 +17,7 @@ import { FANTASY_FOOTBALL_STAT_HEADER_MAP } from '../const/fantasy-football.cons
templateUrl: './player-detail.component.html',
styleUrls: ['./player-detail.component.scss'],
})
export class PlayerDetailComponent {
export class PlayerDetailComponent implements OnDestroy {

private _route = inject(ActivatedRoute);
private _store = inject(Store);
Expand Down Expand Up @@ -62,4 +63,8 @@ export class PlayerDetailComponent {
})
);

ngOnDestroy(): void {
this._store.dispatch(setHasBackButton(false));
}

}
7 changes: 6 additions & 1 deletion apps/fantalytic-mobile/src/app/header/header.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<ion-header>
<ion-toolbar>
<ion-title>Fantalytic.io</ion-title>
<ion-buttons *ngIf="hasBackButton$ | async" slot="start">
<ion-button (click)="goBack()">
<ion-icon slot="start" name="chevron-back-outline"></ion-icon>
</ion-button>
</ion-buttons>
<ion-title>Fantalytic.io</ion-title>
<ion-buttons slot="end">
<ion-button id="click-trigger">
<ion-icon slot="icon-only" name="american-football-outline"></ion-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

.active {
color: rgb(66,140,255);
}
}
18 changes: 16 additions & 2 deletions apps/fantalytic-mobile/src/app/header/header.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { Component, inject } from '@angular/core';
import { Router } from '@angular/router';
import { IonicModule, NavController } from '@ionic/angular';
import { Store } from '@ngrx/store';
import { BehaviorSubject } from 'rxjs';
import { setHasBackButton } from '../ngrx/actions/shared.actions';
import { selectHasBackButton } from '../ngrx/selectors/shared.selectors';

@Component({
selector: 'pmt-header',
Expand All @@ -12,9 +16,19 @@ import { BehaviorSubject } from 'rxjs';
exportAs: 'pmt-header'
})
export class HeaderComponent {

_store = inject(Store);
_controller = inject(NavController);

activeModule$ = new BehaviorSubject<string>('Football');
hasBackButton$ = this._store.select(selectHasBackButton);

switchActiveModule(module: string): void {
this.activeModule$.next(module);
}

goBack(): void {
this._controller.back();
this._store.dispatch(setHasBackButton(false));
}
}
6 changes: 6 additions & 0 deletions apps/fantalytic-mobile/src/app/ngrx/actions/shared.actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createAction } from '@ngrx/store';

export const setHasBackButton = createAction(
'[Shared] Set Has Back Button',
(hasBackButton: boolean) => ({hasBackButton})
);
18 changes: 18 additions & 0 deletions apps/fantalytic-mobile/src/app/ngrx/reducers/shared.reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createReducer, on } from '@ngrx/store';
import { setHasBackButton } from '../actions/shared.actions';

export interface SharedState {
hasBackButton: boolean;
}

export const initialState: SharedState = {
hasBackButton: false
};

export const sharedReducer = createReducer(
initialState,
on(
setHasBackButton,
(state, {hasBackButton}) => ({...state, hasBackButton})
)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createFeatureSelector, createSelector } from '@ngrx/store';
import { SharedState } from '../reducers/shared.reducer';

const selectSharedState = createFeatureSelector<SharedState>('shared');

export const selectHasBackButton = createSelector(
selectSharedState,
state => state.hasBackButton
);
2 changes: 2 additions & 0 deletions apps/fantalytic-mobile/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TopicEffects } from './app/topics/ngrx/effects/topics.effects';
import { topicsReducer } from './app/topics/ngrx/reducer/topics.reducer';
import { environment } from './environments/environment';
import { IonicModule } from '@ionic/angular';
import { sharedReducer } from './app/ngrx/reducers/shared.reducer';

if (environment.production) {
enableProdMode();
Expand Down Expand Up @@ -53,6 +54,7 @@ bootstrapApplication(
RouterModule.forRoot(routes),
IonicModule.forRoot(),
StoreModule.forRoot({}),
StoreModule.forFeature('shared', sharedReducer),
EffectsModule.forRoot([]),
StoreDevtoolsModule.instrument({}),
HttpClientModule,
Expand Down

0 comments on commit 651bea9

Please sign in to comment.