Skip to content

Commit 12bda02

Browse files
feat(dashboard): Recent People drawer is now in local storage (#521)
* Recent people können mit Button getoggelt werden. * feat(app.dashboard): toggles recent people list ISSUES CLOSED: #277 * scroller fixed, openbydefault fixed haven't fixed colour yet * background-colour-fixed * style: background-colour-recent-people-fixed ISSUES CLOSED: #277 * hidden in smaller window * Update Phonebook.Frontend/src/app/pages/dashboard/dashboard.component.html Co-Authored-By: DanielHabenicht <daniel-habenicht@outlook.de> * button needs to be relocated * feat(dashboard): make recent people collapsible * add formatting rule * fix two little issue - default open - oveflow scroll bar * Update dashboard.component.ts first change * recent people in local storage * small change * feat(App.Types): drawer in store * closed drawer when window smaller than 768px * auto toggle when resizing window * preference saved when bigger screen * better code * fix(recentPeople): save state only in big screen * auto resize drawer while repecting state Co-authored-by: DanielHabenicht <daniel-habenicht@outlook.de>
1 parent cd0a06a commit 12bda02

File tree

3 files changed

+61
-13
lines changed

3 files changed

+61
-13
lines changed

Phonebook.Frontend/src/app/pages/dashboard/dashboard.component.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<mat-drawer-container hasBackdrop="false" class="container" position="end">
2-
<mat-drawer #drawer [mode]="drawerMode" [opened]="drawerOpen" position="end" class="pb-recent-people-drawer">
2+
<mat-drawer
3+
#drawer
4+
[mode]="smallScreen ? 'push' : 'side'"
5+
[opened]="drawerOpen"
6+
position="end"
7+
class="pb-recent-people-drawer"
8+
>
39
<div class="pb-recent-people">
410
<h1>
511
<ng-container i18n="DashboardComponent|Title of the recent people section@@DashboardComponentTitleRecent">
@@ -111,7 +117,7 @@ <h1 i18n="DashboardComponent|Title of the Bookmarked people section@@DashboardCo
111117
<div class="toggle-drawer">
112118
<button
113119
mat-icon-button
114-
(click)="drawer.toggle()"
120+
(click)="toggleDrawer()"
115121
i18n-matTooltip="
116122
DashboardComponent|Tooltip for expanding recently viewed people@@DashboardComponentButtonExpandTooltip
117123
"

Phonebook.Frontend/src/app/pages/dashboard/dashboard.component.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
21
import { CdkDragEnd, CdkDragEnter, moveItemInArray } from '@angular/cdk/drag-drop';
3-
import { ChangeDetectorRef, Component, OnInit, OnDestroy } from '@angular/core';
2+
import { BreakpointObserver } from '@angular/cdk/layout';
3+
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
44
import { Select, Store } from '@ngxs/store';
5+
import { untilComponentDestroyed } from 'ng2-rx-componentdestroyed';
56
import { Observable, Subscription } from 'rxjs';
67
import { map } from 'rxjs/operators';
78
import { Person, PhonebookSortDirection } from 'src/app/shared/models';
8-
import { BookmarksState, ToggleBookmark, UpdateBookmarkOrder } from 'src/app/shared/states';
9+
import {
10+
AppState,
11+
BookmarksState,
12+
SetRecentPeopleDrawer,
13+
ToggleBookmark,
14+
UpdateBookmarkOrder
15+
} from 'src/app/shared/states';
916
import {
1017
LastPersonsState,
1118
RemoveFromLastPersons,
1219
ResetLastPersons,
1320
SetLastPersons
1421
} from 'src/app/shared/states/LastPersons.state';
15-
import { untilComponentDestroyed } from 'ng2-rx-componentdestroyed';
16-
import { MatDrawerMode } from '@angular/material/sidenav';
1722
@Component({
1823
selector: 'app-dashboard',
1924
templateUrl: './dashboard.component.html',
@@ -31,18 +36,28 @@ export class DashboardComponent implements OnInit, OnDestroy {
3136
@Select(BookmarksState)
3237
public bookmarkedPersons$: Observable<Person[]>;
3338
public removedLastPersons: Person[] | null = null;
34-
public drawerOpen: boolean = !this.breakpointObserver.isMatched('(max-width: 768px)');
35-
public drawerMode: MatDrawerMode = 'side';
36-
public smallerScreen: boolean = false;
39+
public drawerOpen: boolean = false;
40+
public smallScreen: boolean = false;
3741
constructor(private store: Store, private cd: ChangeDetectorRef, private breakpointObserver: BreakpointObserver) {}
3842

3943
public ngOnInit() {
4044
this.changeOrder();
45+
this.store
46+
.select(AppState.recentPeopleDrawer)
47+
.pipe(untilComponentDestroyed(this))
48+
.subscribe(open => {
49+
this.drawerOpen = open;
50+
});
4151
this.breakpointObserver
4252
.observe('(max-width: 768px)')
4353
.pipe(untilComponentDestroyed(this))
4454
.subscribe(result => {
45-
this.drawerMode = !result.matches ? 'side' : 'push';
55+
this.smallScreen = result.matches;
56+
if (this.smallScreen) {
57+
this.drawerOpen = false;
58+
} else {
59+
this.drawerOpen = this.store.selectSnapshot(AppState.recentPeopleDrawer);
60+
}
4661
});
4762
}
4863

@@ -98,5 +113,12 @@ export class DashboardComponent implements OnInit, OnDestroy {
98113
public removeFromBookmarkedPersons(person: Person) {
99114
this.store.dispatch(new ToggleBookmark(person));
100115
}
116+
117+
public toggleDrawer() {
118+
this.drawerOpen = !this.drawerOpen;
119+
if (!this.smallScreen) {
120+
this.store.dispatch(new SetRecentPeopleDrawer(this.drawerOpen));
121+
}
122+
}
101123
ngOnDestroy(): void {}
102124
}

Phonebook.Frontend/src/app/shared/states/App.state.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { Injectable } from '@angular/core';
12
import { Action, Selector, State, StateContext } from '@ngxs/store';
23
import { ThemeService } from 'src/app/services/theme.service';
34
import { Theme } from 'src/app/shared/models/enumerables/Theme';
4-
import { Injectable } from '@angular/core';
55

66
export class ServiceWorkerNotificationDisplayed {
77
public static readonly type: string = '[App State] Service Worker Notification displayed';
@@ -30,6 +30,11 @@ export class InitTheme {
3030
public static readonly type: string = '[App State] Init activeTheme';
3131
}
3232

33+
export class SetRecentPeopleDrawer {
34+
public static readonly type: string = '[App State] Set recentPeopleDrawer';
35+
constructor(public active: boolean) {}
36+
}
37+
3338
export interface AppStateModel {
3439
serviceWorkerNotificationDisplayed: boolean;
3540
version: string;
@@ -40,6 +45,7 @@ export interface AppStateModel {
4045
*/
4146
sendFeedback: boolean | null;
4247
activeTheme: Theme;
48+
recentPeopleDrawer: boolean;
4349
}
4450

4551
@State<AppStateModel>({
@@ -49,7 +55,8 @@ export interface AppStateModel {
4955
version: '0.0.0',
5056
displayedNotificationVersion: 0,
5157
sendFeedback: null,
52-
activeTheme: Theme.magenta_light_theme
58+
activeTheme: Theme.magenta_light_theme,
59+
recentPeopleDrawer: true
5360
}
5461
})
5562
@Injectable()
@@ -77,6 +84,10 @@ export class AppState {
7784
public static sendFeedback(state: AppStateModel): boolean | null {
7885
return state.sendFeedback;
7986
}
87+
@Selector()
88+
public static recentPeopleDrawer(state: AppStateModel): boolean {
89+
return state.recentPeopleDrawer;
90+
}
8091

8192
@Action(ServiceWorkerNotificationDisplayed)
8293
public serviceWorkerNotificationDisplayed(ctx: StateContext<AppStateModel>) {
@@ -128,4 +139,13 @@ export class AppState {
128139
const state = ctx.getState();
129140
this.themeService.setTheme(state.activeTheme);
130141
}
142+
143+
@Action(SetRecentPeopleDrawer)
144+
public setDrawer(ctx: StateContext<AppStateModel>, action: SetRecentPeopleDrawer) {
145+
const state = ctx.getState();
146+
ctx.setState({
147+
...state,
148+
recentPeopleDrawer: action.active
149+
});
150+
}
131151
}

0 commit comments

Comments
 (0)