From 9a3cff864e50ed07760c21f33d347cc7278d4346 Mon Sep 17 00:00:00 2001 From: Luke Date: Wed, 11 Jan 2023 20:38:58 +0100 Subject: [PATCH] refactor(client/interface): default notify backwards compat --- resource/interface/client/notify.lua | 12 ++++++------ web/src/features/dev/debug/notification.ts | 8 ++++---- .../features/notifications/NotificationWrapper.tsx | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/resource/interface/client/notify.lua b/resource/interface/client/notify.lua index deb298e..2b240ea 100644 --- a/resource/interface/client/notify.lua +++ b/resource/interface/client/notify.lua @@ -1,4 +1,4 @@ ----@alias NotificationPosition 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left' +---@alias NotificationPosition 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left' | 'center-right' | 'center-left' ---@alias NotificationType 'inform' | 'error' | 'success' ---@class NotifyProps @@ -15,7 +15,7 @@ ---@param data NotifyProps function lib.notify(data) SendNUIMessage({ - action = 'customNotify', + action = 'notify', data = data }) end @@ -30,10 +30,10 @@ end ---@param data DefaultNotifyProps function lib.defaultNotify(data) - SendNUIMessage({ - action = 'notify', - data = data - }) + -- Backwards compat for v3 + data.type = data.status + if data.type == 'info' or data.type == 'warning' then data.type = 'inform' end + return lib.notify(data) end RegisterNetEvent('ox_lib:notify', lib.notify) diff --git a/web/src/features/dev/debug/notification.ts b/web/src/features/dev/debug/notification.ts index 211e47f..f8fa0ee 100644 --- a/web/src/features/dev/debug/notification.ts +++ b/web/src/features/dev/debug/notification.ts @@ -4,7 +4,7 @@ import { debugData } from '../../../utils/debugData'; export const debugCustomNotification = () => { debugData([ { - action: 'customNotify', + action: 'notify', data: { title: 'Success', description: 'Notification description', @@ -14,7 +14,7 @@ export const debugCustomNotification = () => { ]); debugData([ { - action: 'customNotify', + action: 'notify', data: { title: 'Info', description: 'Notification description', @@ -24,7 +24,7 @@ export const debugCustomNotification = () => { ]); debugData([ { - action: 'customNotify', + action: 'notify', data: { title: 'Error', description: 'Notification description', @@ -34,7 +34,7 @@ export const debugCustomNotification = () => { ]); debugData([ { - action: 'customNotify', + action: 'notify', data: { title: 'Custom icon success', description: 'Notification description', diff --git a/web/src/features/notifications/NotificationWrapper.tsx b/web/src/features/notifications/NotificationWrapper.tsx index 40e539e..6c74e2a 100644 --- a/web/src/features/notifications/NotificationWrapper.tsx +++ b/web/src/features/notifications/NotificationWrapper.tsx @@ -119,7 +119,7 @@ const exitAnimationBottom = keyframes({ const Notifications: React.FC = () => { const { classes } = useStyles(); - useNuiEvent('customNotify', (data) => { + useNuiEvent('notify', (data) => { if (!data.title && !data.description) return; // Backwards compat with old notifications let position = data.position;