Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lakhoune committed Aug 10, 2022
1 parent bf5b198 commit fa0e4f5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
32 changes: 20 additions & 12 deletions angular-cards/src/app/cards/cards.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Component, OnInit, HostListener, ViewChild, ElementRef, OnDestroy } fro
import { Vorlesung } from 'src/app/models/Vorlesung';
import { Title } from '@angular/platform-browser';
import { Store } from '@ngrx/store';
import { Observable, Subscription } from 'rxjs';
import { map, take } from 'rxjs/operators';
import { Observable, Subscription, firstValueFrom } from 'rxjs';
import { map, take, timeout } from 'rxjs/operators';
import { fetchCards } from '../store/actions/CardActions';
import { fadeInOnEnterAnimation } from 'angular-animations';
import { changeTab, setSuggestionsMode, showNewCard } from '../store/actions/StateActions';
Expand Down Expand Up @@ -45,7 +45,12 @@ export class CardsComponent implements OnInit, OnDestroy {

public lecture$: Observable<Vorlesung> = this.data$.pipe(map((data) => data.currLecture));

constructor(private store: Store<AppState>, private title: Title, private _snackBar: MatSnackBar) {}
constructor(
private store: Store<AppState>,
private title: Title,
private _snackBar: MatSnackBar,
private translate: TranslateService
) {}

ngOnInit(): void {
this.title.setTitle('Cards');
Expand Down Expand Up @@ -87,15 +92,18 @@ export class CardsComponent implements OnInit, OnDestroy {
this.store.dispatch(changeTab({ tab: index }));
}

openSnackBar(card: Card) {
this._snackBar
.open('Do you want to pick up where you left off?', 'Yes', { duration: 5000, politeness: 'assertive' })
.onAction()
.subscribe(async () => {
this.store.dispatch(showNewCard({ card: card }));
const currentLecture = await this.store.select(SELECTED_LECTURE).pipe(take(1)).toPromise();
localStorage.remove(currentLecture._id);
});
async openSnackBar(card: Card) {
const message = this.translate.instant('notifications.pick-up');
await firstValueFrom(
this._snackBar
.open(message, 'Yes', { duration: 5000, politeness: 'assertive' })
.onAction()
.pipe(take(1), timeout(6000))
);

this.store.dispatch(showNewCard({ card: card }));
const currentLecture = await this.store.select(SELECTED_LECTURE).pipe(take(1)).toPromise();
localStorage.remove(currentLecture._id);
}

async ngOnDestroy() {
Expand Down
3 changes: 2 additions & 1 deletion angular-cards/src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@
"flash-cards": "Karteikarten",
"notifications": {
"notifications": "Benachrichtigungen",
"add-card-success": "Deine Karte wurde erfolgreich hinzugefügt."
"add-card-success": "Deine Karte wurde erfolgreich hinzugefügt.",
"pick-up": "Möchtest du zu deiner zuletzt besuchten Karte zurückkehren?"
},
"report-type": "Report Typ",
"users": "Nutzer",
Expand Down
6 changes: 5 additions & 1 deletion angular-cards/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@
"RANGE_PAGE_LABEL_1": "0 of {{length}}",
"RANGE_PAGE_LABEL_2": "{{startIndex}} - {{endIndex}} of {{length}}",
"flash-cards": "Flash cards",
"notifications": { "notifications": "Notifications", "add-card-success": "Your card has been added successfully" },
"notifications": {
"notifications": "Notifications",
"add-card-success": "Your card has been added successfully",
"pick-up": "Do you want to pick up where you left off?"
},
"users": "Users",
"number-of-cards": "Number of cards",
"report-type": "Report Type",
Expand Down

0 comments on commit fa0e4f5

Please sign in to comment.