From b910b65f7f7f255c30f694d2b12dca5020c68a64 Mon Sep 17 00:00:00 2001 From: Gavin Porter Date: Tue, 17 Dec 2024 13:16:38 -0500 Subject: [PATCH 1/3] courses: smoother snackbar (fixes #7941) --- src/app/shared/planet-message.service.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/app/shared/planet-message.service.ts b/src/app/shared/planet-message.service.ts index 3fb902c1ad..e111bdabd7 100644 --- a/src/app/shared/planet-message.service.ts +++ b/src/app/shared/planet-message.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable, HostListener } from '@angular/core'; import { MatSnackBar } from '@angular/material/snack-bar'; @Injectable({ @@ -6,11 +6,21 @@ import { MatSnackBar } from '@angular/material/snack-bar'; }) export class PlanetMessageService { constructor( - private snackBar: MatSnackBar - ) { } + private snackBar: MatSnackBar, + ) { + } + truncateMessage(message: string) { + const maxLength = 45; + if (message.length <= maxLength) { + return message; + } else { + return message.slice(0, maxLength) + '...'; + } + } + showMessage(message: string) { - this.snackBar.open(message, undefined, { + this.snackBar.open(this.truncateMessage(message), undefined, { duration: 3000, }); } From c390d6e26da2d4e861a1789745e94459e5069985 Mon Sep 17 00:00:00 2001 From: Gavin Porter Date: Tue, 17 Dec 2024 13:22:34 -0500 Subject: [PATCH 2/3] removed unneeded variables and spacing --- src/app/shared/planet-message.service.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/app/shared/planet-message.service.ts b/src/app/shared/planet-message.service.ts index e111bdabd7..56e505b90f 100644 --- a/src/app/shared/planet-message.service.ts +++ b/src/app/shared/planet-message.service.ts @@ -1,4 +1,4 @@ -import { Injectable, HostListener } from '@angular/core'; +import { Injectable} from '@angular/core'; import { MatSnackBar } from '@angular/material/snack-bar'; @Injectable({ @@ -7,8 +7,7 @@ import { MatSnackBar } from '@angular/material/snack-bar'; export class PlanetMessageService { constructor( private snackBar: MatSnackBar, - ) { - } + ) {} truncateMessage(message: string) { const maxLength = 45; From dac2d29cb02176a8c9057751443ad57aaf34fdb2 Mon Sep 17 00:00:00 2001 From: Gavin Porter Date: Tue, 17 Dec 2024 14:09:25 -0500 Subject: [PATCH 3/3] removed universal snackbar truncation --- src/app/courses/courses.component.ts | 10 +++++++++- src/app/shared/planet-message.service.ts | 11 +---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/app/courses/courses.component.ts b/src/app/courses/courses.component.ts index f036d867cb..cb9b001cfe 100644 --- a/src/app/courses/courses.component.ts +++ b/src/app/courses/courses.component.ts @@ -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 { @@ -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.`) }; diff --git a/src/app/shared/planet-message.service.ts b/src/app/shared/planet-message.service.ts index 56e505b90f..3c4bd64638 100644 --- a/src/app/shared/planet-message.service.ts +++ b/src/app/shared/planet-message.service.ts @@ -8,18 +8,9 @@ export class PlanetMessageService { constructor( private snackBar: MatSnackBar, ) {} - - truncateMessage(message: string) { - const maxLength = 45; - if (message.length <= maxLength) { - return message; - } else { - return message.slice(0, maxLength) + '...'; - } - } showMessage(message: string) { - this.snackBar.open(this.truncateMessage(message), undefined, { + this.snackBar.open(message, undefined, { duration: 3000, }); }