Draft
Conversation
dvladir
requested changes
Aug 9, 2024
projects/step-core/src/lib/components/toast-container/toast-container.component.html
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,5 @@ | |||
| <div class="toast-container"> | |||
| @for (toast of toasts; track toast) { | |||
| <step-toast [message]="toast.message" [actions]="toast.actions" [duration]="toast.duration"> </step-toast> | |||
Contributor
There was a problem hiding this comment.
Suggested change
| <step-toast [message]="toast.message" [actions]="toast.actions" [duration]="toast.duration"> </step-toast> | |
| <step-toast [message]="toast.message" [actions]="toast.actions" [duration]="toast.duration"/> |
Comment on lines
9
to
21
| private toastSubject = new Subject<{ message: string; actions?: NotificationAction[]; duration?: number }[]>(); | ||
| toastMessages = this.toastSubject.asObservable(); | ||
| private toasts: { message: string; actions: NotificationAction[]; duration: number }[] = []; | ||
|
|
||
| showToast(message: string, actions?: NotificationAction[], duration?: number): void { | ||
| this.toasts.push({ message, actions: actions || [], duration: duration || 3000 }); | ||
| this.toastSubject.next(this.toasts); | ||
| } | ||
|
|
||
| removeToast(message: string): void { | ||
| this.toasts = this.toasts.filter((toast) => toast.message !== message); | ||
| this.toastSubject.next(this.toasts); | ||
| } |
Contributor
There was a problem hiding this comment.
I think the usage of signals could simplify this code
Suggested change
| private toastSubject = new Subject<{ message: string; actions?: NotificationAction[]; duration?: number }[]>(); | |
| toastMessages = this.toastSubject.asObservable(); | |
| private toasts: { message: string; actions: NotificationAction[]; duration: number }[] = []; | |
| showToast(message: string, actions?: NotificationAction[], duration?: number): void { | |
| this.toasts.push({ message, actions: actions || [], duration: duration || 3000 }); | |
| this.toastSubject.next(this.toasts); | |
| } | |
| removeToast(message: string): void { | |
| this.toasts = this.toasts.filter((toast) => toast.message !== message); | |
| this.toastSubject.next(this.toasts); | |
| } | |
| private toastsInternal = signal<{ message: string; actions?: NotificationAction[]; duration?: number }[]>([]); | |
| readonly toastMessages = this.toastsInternal.asReadonly(); | |
| showToast(message: string, actions: NotificationAction[] = [], duration: number = 3000): void { | |
| this.toastsInternal.update((toasts) => toasts.concat({message, actions, duration})) ; | |
| } | |
| removeToast(message: string): void { | |
| this.toastsInternal.update((toasts) => toasts.filter((toast) => toast.message !== message)); | |
| } |
Comment on lines
11
to
19
| toasts: { message: string; actions?: NotificationAction[]; duration?: number }[] = []; | ||
|
|
||
| constructor(private toastService: ToastService) {} | ||
|
|
||
| ngOnInit(): void { | ||
| this.toastService.toastMessages.subscribe((toasts) => { | ||
| this.toasts = toasts; | ||
| }); | ||
| } |
Contributor
There was a problem hiding this comment.
Please, check the comment below in ToastService. With signal usage the code of current component could look like this
Suggested change
| toasts: { message: string; actions?: NotificationAction[]; duration?: number }[] = []; | |
| constructor(private toastService: ToastService) {} | |
| ngOnInit(): void { | |
| this.toastService.toastMessages.subscribe((toasts) => { | |
| this.toasts = toasts; | |
| }); | |
| } | |
| protected readonly _toasts = inject(ToastService).toastMessages; |
| @@ -0,0 +1,14 @@ | |||
| @if (message) { | |||
| <div class="toast"> | |||
| <span class="success-icon">✓</span> | |||
Contributor
There was a problem hiding this comment.
@neogucky @lukasz-lepa
Shouldn't we use feather-icons here instead of unicode symbols?
projects/step-core/src/lib/components/toast/toast.component.html
Outdated
Show resolved
Hide resolved
…ntainer.component.html Co-authored-by: Vladimir <dragonvladir@gmail.com>
Co-authored-by: Vladimir <dragonvladir@gmail.com>
…tend into SED-3222-duplicate-edit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://exense.atlassian.net/browse/SED-3304