From 83b077918f77fa8a138e20a74e96e26a5ac31d88 Mon Sep 17 00:00:00 2001 From: Jesse Washburn <142361664+jessewashburn@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:35:22 -0500 Subject: [PATCH] all: smoother snackbar truncation (fixes #8081) (#8088) Co-authored-by: dogi --- package.json | 2 +- src/app/community/community-link-dialog.component.ts | 2 +- src/app/community/community.component.ts | 2 +- src/app/courses/add-courses/courses-add.component.ts | 2 +- src/app/courses/courses.service.ts | 9 ++++----- src/app/resources/resources-add.component.ts | 3 +-- src/app/resources/resources.service.ts | 6 +++--- src/app/shared/planet-message.service.ts | 11 ++++++++++- 8 files changed, 22 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 4e75e763c1..209e02f65d 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "planet", "license": "AGPL-3.0", - "version": "0.16.66", + "version": "0.16.67", "myplanet": { "latest": "v0.22.20", "min": "v0.21.20" diff --git a/src/app/community/community-link-dialog.component.ts b/src/app/community/community-link-dialog.component.ts index 5483e4986f..7cbac9d750 100644 --- a/src/app/community/community-link-dialog.component.ts +++ b/src/app/community/community-link-dialog.component.ts @@ -58,7 +58,7 @@ export class CommunityLinkDialogComponent { ).subscribe({ next: () => { this.dialogRef.close(); - this.planetMessageService.showMessage(`${linkTitle} added successfully`); + this.planetMessageService.showMessage(`Added link: ${linkTitle}`); }, error: () => { this.planetMessageService.showAlert(`Error adding link`); diff --git a/src/app/community/community.component.ts b/src/app/community/community.component.ts index 82d186ac52..695d278021 100644 --- a/src/app/community/community.component.ts +++ b/src/app/community/community.component.ts @@ -299,7 +299,7 @@ export class CommunityComponent implements OnInit, OnDestroy { request: this.couchService.updateDocument('teams', { ...link, _deleted: true }).pipe(switchMap(() => this.getLinks())), onNext: (res) => { this.setLinksAndFinances(res); - this.planetMessageService.showMessage($localize`${link.title} deleted`); + this.planetMessageService.showMessage($localize` Deleted link: ${link.title}`); deleteDialog.close(); }, onError: () => this.planetMessageService.showAlert($localize`There was an error deleting ${link.title}`) diff --git a/src/app/courses/add-courses/courses-add.component.ts b/src/app/courses/add-courses/courses-add.component.ts index 36b3fce0ab..8e1884c8ee 100644 --- a/src/app/courses/add-courses/courses-add.component.ts +++ b/src/app/courses/add-courses/courses-add.component.ts @@ -199,7 +199,7 @@ export class CoursesAddComponent implements OnInit, OnDestroy { ) ]) )).subscribe(([ courseRes, tagsRes ]) => { - const message = courseInfo.courseTitle + (this.pageType === 'Edit' ? $localize` Updated Successfully` : $localize` Added`); + const message = (this.pageType === 'Edit' ? $localize`Edited course: ` : $localize`Added course: `) + courseInfo.courseTitle; this.courseChangeComplete(message, courseRes, shouldNavigate); }, (err) => { // Connect to an error display component to show user that an error has occurred diff --git a/src/app/courses/courses.service.ts b/src/app/courses/courses.service.ts index 2c69e183be..dee41effc5 100644 --- a/src/app/courses/courses.service.ts +++ b/src/app/courses/courses.service.ts @@ -203,7 +203,6 @@ export class CoursesService { courseResignAdmission(courseId, type, courseTitle?) { const title = courseTitle ? courseTitle : this.getCourseNameFromId(courseId); - const truncatedTitle = title.length > 180 ? `${title.slice(0, 180)}...` : title; const courseIds: any = [ ...this.userService.shelf.courseIds ]; if (type === 'resign') { const myCourseIndex = courseIds.indexOf(courseId); @@ -213,8 +212,8 @@ export class CoursesService { } return this.userService.updateShelf(courseIds, 'courseIds').pipe(map((res) => { const admissionMessage = type === 'resign' - ? $localize`${truncatedTitle} successfully removed from myCourses` - : $localize`${truncatedTitle} added to your dashboard`; + ? $localize`Removed from myCourses: ${title}` + : $localize`Course added to your dashboard: ${title}`; this.planetMessageService.showMessage(admissionMessage); return res; })); @@ -227,8 +226,8 @@ export class CoursesService { courseAdmissionMany(courseIds, type) { return this.userService.changeShelf(courseIds, 'courseIds', type).pipe(map(({ shelf, countChanged }) => { const prefix = countChanged > 1 ? $localize`${countChanged} courses` : this.getCourseNameFromId(courseIds[courseIds.length - 1]); - const message = type === 'remove' ? $localize`${prefix} successfully removed from myCourses` : - $localize`${prefix} added to myCourses`; + const message = type === 'remove' ? $localize`Removed from myCourses: ${prefix}` : + $localize`Added to myCourses: ${prefix} `; this.planetMessageService.showMessage(message); return shelf; })); diff --git a/src/app/resources/resources-add.component.ts b/src/app/resources/resources-add.component.ts index df12cbc83e..7923ad0641 100644 --- a/src/app/resources/resources-add.component.ts +++ b/src/app/resources/resources-add.component.ts @@ -183,8 +183,7 @@ export class ResourcesAddComponent implements OnInit { const existingData = this.deleteAttachment ? { _id, _rev } : this.existingResource.doc; // Start with empty object so this.resourceForm.value does not change const newResource = Object.assign({}, existingData, this.resourceForm.value, resource); - const message = newResource.title + - (this.pageType === 'Edit' || this.existingResource.doc ? $localize` Updated Successfully` : $localize` Added`); + const message = (this.pageType === 'Edit' ? $localize`Edited resource: ` : $localize`Added resource: `) + newResource.title; const currentTags = (this.existingResource.tags || []).map(tag => tag._id); if (JSON.stringify(existingData) !== JSON.stringify(newResource) || !deepEqual(currentTags, this.tags.value)) { this.updateResource(newResource, file).subscribe( diff --git a/src/app/resources/resources.service.ts b/src/app/resources/resources.service.ts index aac7f085eb..33c35b4ed2 100644 --- a/src/app/resources/resources.service.ts +++ b/src/app/resources/resources.service.ts @@ -93,9 +93,9 @@ export class ResourcesService { const resource = this.resources.local.find(r => r._id === resourceIds[0]); const resourceTitle = resource ? resource.doc.title : ''; const message = type === 'remove' ? - (countChanged === 1 ? $localize`${resourceTitle} successfully removed from myLibrary` : - `${countChanged} ${$localize`Resources`} successfully removed from myLibrary`) : - (countChanged === 1 ? $localize`${resourceTitle} added to myLibrary` : + (countChanged === 1 ? $localize`Removed from myLibrary: ${resourceTitle}` : + `${countChanged} ${$localize`Resources`} removed from myLibrary`) : + (countChanged === 1 ? $localize`Added to myLibrary: ${resourceTitle}` : `${countChanged} ${$localize`Resources`} added to myLibrary`); this.planetMessageService.showMessage(message); return shelf; diff --git a/src/app/shared/planet-message.service.ts b/src/app/shared/planet-message.service.ts index 3fb902c1ad..da440f18d3 100644 --- a/src/app/shared/planet-message.service.ts +++ b/src/app/shared/planet-message.service.ts @@ -10,7 +10,8 @@ export class PlanetMessageService { ) { } showMessage(message: string) { - this.snackBar.open(message, undefined, { + const truncatedMessage = this.truncateMessage(message); + this.snackBar.open(truncatedMessage, undefined, { duration: 3000, }); } @@ -20,4 +21,12 @@ export class PlanetMessageService { duration: 10000 }); } + + truncateMessage(message: string, maxLength: number = 50): string { + if (message.length <= maxLength) { + return message; + } + const truncatedMessage = message.slice(0, maxLength - 3); + return truncatedMessage + '...'; + } }