Skip to content

Conversation

@ThembaMahlangu
Copy link

Itembox notifications can show in a row of up to 5 notifications at once

Normally if it receives 2 or more removal or add events of different items it will only show 1 item box notification instead of all

Checklist

  • I have personally loaded this code into an updated qbcore project and checked all of its functionality.
  • My code fits the style guidelines.
  • My PR fits the contribution guidelines.

Itembox notifications can show in a row of up to 5 notifications at once
html/app.js Outdated

if (existingIndex > -1) {
// Update existing notification amount
this.notifications[existingIndex].amount += notification.amount;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a thing called "DRY" in Programming (Don't repeat yourself).
I would recomment using it like this:

const notification = this.notifications[existingIndex];
notification.amount += .....
/*ALL THE STUFF */
this.notifications[existingIndex] = notification

html/app.js Outdated
const index = this.notifications.findIndex(n => n.id === notificationId);
if (index > -1) {
// Clear timeout if it exists
if (this.notifications[index].timeoutId) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You get the object 2 times, but you could just get it one time by assigning it to an object:

const timeOutId = this.notifications[index].timeoutId;
if (timeOutId) {
   clearTimeout(timeOutId)
}

Copy link
Author

@ThembaMahlangu ThembaMahlangu Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review and recommendation, I'll look out for that more often

I also updated per recommendation

Recommendation from a reviewer
// Update existing notification amount
this.notifications[existingIndex].amount += notification.amount;
this.notifications[existingIndex].timestamp = Date.now();
const existingNotification = this.notifications[existingIndex];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgit to update the object in notifications-array. JavaScript does not provide pointer's, so you have to update the object in the array again.
like this.notifications[existingIndex] = existingNotification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants