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

courses: smoother deletion snackbar (fixes #7941) #7953

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion src/app/courses/courses.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ export class CoursesComponent implements OnInit, OnChanges, AfterViewInit, OnDes
});
}

truncateMessage(message: string, maxLength: number=50): string {
if (message.length <= maxLength) {
return message;
}
const truncatedMessage = message.slice(0, maxLength - 3);
return truncatedMessage + '...';
}

deleteCourse(course) {
const { _id: courseId, _rev: courseRev } = course;
return {
Expand All @@ -260,7 +268,7 @@ export class CoursesComponent implements OnInit, OnChanges, AfterViewInit, OnDes
// It's safer to remove the item from the array based on its id than to splice based on the index
this.courses.data = this.courses.data.filter((c: any) => data.id !== c._id);
this.deleteDialog.close();
this.planetMessageService.showMessage($localize`Course deleted: ${course.courseTitle}`);
this.planetMessageService.showMessage($localize`Course deleted: ${this.truncateMessage(course.courseTitle, 30)}`);
},
onError: (error) => this.planetMessageService.showAlert($localize`There was a problem deleting this course.`)
};
Expand Down
8 changes: 4 additions & 4 deletions src/app/shared/planet-message.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Injectable } from '@angular/core';
import { Injectable} from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';

@Injectable({
providedIn: 'root'
})
export class PlanetMessageService {
constructor(
private snackBar: MatSnackBar
) { }

private snackBar: MatSnackBar,
) {}
showMessage(message: string) {
this.snackBar.open(message, undefined, {
duration: 3000,
Expand Down
Loading