Notification düzenlemesi

This commit is contained in:
Sedat ÖZTÜRK 2026-05-15 15:04:47 +03:00
parent f62d4b1a74
commit 48acf4211d
2 changed files with 69 additions and 86 deletions

5
api/.gitignore vendored
View file

@ -268,3 +268,8 @@ src/Sozsoft.Platform.Blazor.Server.Tiered/Logs/*
# DevExpress License - DO NOT commit to repository
**/DevExpress_License.txt
DevExpress_License.txt
# Local cache files
*.lscache
lscache/
**/lscache/

View file

@ -76,9 +76,8 @@ const _Notification = ({ className }: { className?: string }) => {
const [loading, setLoading] = useState(false)
const toastNotificationList = useRef<string[]>([])
const toastNotificationInterval = useRef<ReturnType<typeof setInterval>>()
const desktopNotificationList = useRef<string[]>([])
const desktopNotificationInterval = useRef<ReturnType<typeof setInterval>>()
const pushNotificationInterval = useRef<ReturnType<typeof setInterval>>()
const { bgTheme } = useThemeClass()
const { larger } = useResponsive()
@ -103,7 +102,9 @@ const _Notification = ({ className }: { className?: string }) => {
useEffect(() => {
getReactNotificationCount()
var intervalId = setInterval(() => {
if (tabHasFocusRef.current) {
getReactNotificationCount()
}
}, notificationInterval)
return () => {
@ -174,75 +175,56 @@ const _Notification = ({ className }: { className?: string }) => {
[notificationList],
)
// Toast
const getToastNotifications = async () => {
const getPushNotifications = async () => {
const desktopGranted =
'Notification' in window && window.Notification.permission === 'granted'
const channels = [NotificationChannels.UiToast]
if (desktopGranted) channels.push(NotificationChannels.Desktop)
const resp = await getList({
channels: [NotificationChannels.UiToast],
channels,
isListRequest: false,
isSent: false,
maxResultCount: 1000,
})
const items = resp.data.items ?? []
const newNotificationList = items.filter(
(a) => !toastNotificationList.current.includes(a.id) && !a.isSent,
// Toast
const newToastList = items.filter(
(a) =>
a.notificationChannel === NotificationChannels.UiToast &&
!toastNotificationList.current.includes(a.id) &&
!a.isSent,
)
toastNotificationList.current = [
...toastNotificationList.current,
...newNotificationList.map((a) => a.id),
...newToastList.map((a) => a.id),
]
for (const notification of newNotificationList) {
for (const notification of newToastList) {
toast.push(
<Notify
type="success"
duration={0}
closable={true}
>
<Notify type="success" duration={0} closable={true}>
{notification.message}
</Notify>,
{
placement: 'bottom-end',
},
{ placement: 'bottom-end' },
)
await updateSent(notification.id, true)
await updateRead(notification.id, true)
}
}
useEffect(() => {
if (tabHasFocusRef.current) {
getToastNotifications()
}
toastNotificationInterval.current = setInterval(async () => {
if (tabHasFocusRef.current) {
await getToastNotifications()
}
}, notificationInterval)
return () => {
clearInterval(toastNotificationInterval.current)
}
}, [])
//Desktop
const getDesktopNotifications = async () => {
if (!('Notification' in window) || window.Notification.permission !== 'granted') return
const resp = await getList({
channels: [NotificationChannels.Desktop],
isListRequest: false,
isSent: false,
maxResultCount: 1000,
})
const items = resp.data.items ?? []
const newNotificationList = items.filter(
(a) => !desktopNotificationList.current.includes(a.id) && !a.isSent,
// Desktop
if (desktopGranted) {
const newDesktopList = items.filter(
(a) =>
a.notificationChannel === NotificationChannels.Desktop &&
!desktopNotificationList.current.includes(a.id) &&
!a.isSent,
)
desktopNotificationList.current = [
...desktopNotificationList.current,
...newNotificationList.map((a) => a.id),
...newDesktopList.map((a) => a.id),
]
for (const notification of newNotificationList) {
for (const notification of newDesktopList) {
const title = notification.notificationType || 'Bildirim'
const options = {
body: notification.message,
@ -261,27 +243,23 @@ const _Notification = ({ className }: { className?: string }) => {
await updateRead(notification.id, true)
}
}
}
useEffect(() => {
const startDesktopNotifications = async () => {
if (!('Notification' in window)) return
if (window.Notification.permission === 'default') {
await window.Notification.requestPermission()
if ('Notification' in window && window.Notification.permission === 'default') {
window.Notification.requestPermission()
}
if (window.Notification.permission === 'granted') {
await getDesktopNotifications()
desktopNotificationInterval.current = setInterval(async () => {
await getDesktopNotifications()
getPushNotifications()
pushNotificationInterval.current = setInterval(() => {
if (tabHasFocusRef.current) {
getPushNotifications()
}
}, notificationInterval)
}
}
startDesktopNotifications()
return () => {
clearInterval(desktopNotificationInterval.current)
clearInterval(pushNotificationInterval.current)
}
}, [])