Skip to content

Commit

Permalink
all: smoother snackbar truncation (fixes #8081) (#8088)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
jessewashburn and dogi authored Jan 17, 2025
1 parent 3ee10a5 commit 83b0779
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/app/community/community-link-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
2 changes: 1 addition & 1 deletion src/app/community/community.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
2 changes: 1 addition & 1 deletion src/app/courses/add-courses/courses-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/app/courses/courses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}));
Expand All @@ -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;
}));
Expand Down
3 changes: 1 addition & 2 deletions src/app/resources/resources-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/app/resources/resources.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/app/shared/planet-message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand All @@ -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 + '...';
}
}

0 comments on commit 83b0779

Please sign in to comment.