-
Notifications
You must be signed in to change notification settings - Fork 0
feat(100): added buttons actions on toast #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ASTRAone
wants to merge
2
commits into
main
Choose a base branch
from
100
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| export { useGetNotificationsStatus } from './useGetNotificationsStatus'; | ||
| export { NotificationsProvider, useNotificationsContext } from './NotificationsProvider'; | ||
| export * from './notificationUtils'; | ||
| export { useChangeContactsVisibility } from './useChangeContactsVisibility'; | ||
| export { useCreateTgConnection } from './useCreateTgConnection'; | ||
| export { useDeleteTgConnection } from './useDeleteTgConnection'; | ||
| export { useChangeContactsVisibility } from './useChangeContactsVisibility'; | ||
| export { useSearchNotifications } from './useSearchNotifications'; | ||
| export { useGetNotificationsStatus } from './useGetNotificationsStatus'; | ||
| export { useGetUnreadCount } from './useGetUnreadCount'; | ||
| export { useMarkNotificationAsRead } from './useMarkNotificationAsRead'; | ||
| export { useNotifications } from './useNotifications'; | ||
| export { NotificationsProvider, useNotificationsContext } from './NotificationsProvider'; | ||
| export * from './notificationUtils'; | ||
| export { useSearchNotifications } from './useSearchNotifications'; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,25 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| import { useState, useCallback, useEffect, useMemo } from 'react'; | ||
| import { useQueryClient } from '@tanstack/react-query'; | ||
| import { toast } from 'sonner'; | ||
| import { Button } from '@xipkg/button'; | ||
| import { useSocketEvent } from 'common.sockets'; | ||
| import { NotificationT, NotificationsStateT, RecipientNotificationResponse } from 'common.types'; | ||
| import { useCallback, useEffect, useMemo, useState } from 'react'; | ||
| import { toast } from 'sonner'; | ||
| import { useCurrentUser } from '../user'; | ||
| import { notificationConfigs } from './notificationConfig'; | ||
| import { | ||
| generateNotificationTitle, | ||
| generateNotificationAction, | ||
| generateNotificationDescription, | ||
| generateNotificationTitle, | ||
| getNotificationInvalidationKeys, | ||
| } from './notificationUtils'; | ||
| import { useSearchNotifications } from './useSearchNotifications'; | ||
| import { useGetUnreadCount } from './useGetUnreadCount'; | ||
| import { useMarkNotificationAsRead } from './useMarkNotificationAsRead'; | ||
| import { useCurrentUser } from '../user'; | ||
| import { useSearchNotifications } from './useSearchNotifications'; | ||
|
|
||
| export const useNotifications = () => { | ||
| // const navigate = useNavigate(); | ||
|
|
||
| const [socketNotifications, setSocketNotifications] = useState<NotificationT[]>([]); | ||
| const [shouldLoadNotifications, setShouldLoadNotifications] = useState(false); | ||
| const queryClient = useQueryClient(); | ||
|
|
@@ -79,6 +84,22 @@ export const useNotifications = () => { | |
| [], | ||
| ); | ||
|
|
||
| // Обработчик навигации по URL из уведомления | ||
| const onNavigate = useCallback((url: string) => { | ||
| try { | ||
| // Проверяем, является ли URL относительным путем или полным URL | ||
| if (url.startsWith('http://') || url.startsWith('https://')) { | ||
| // Внешняя ссылка - открываем в новой вкладке | ||
| window.open(url, '_blank', 'noopener,noreferrer'); | ||
| } else { | ||
| // Внутренняя навигация - используем window.location.href | ||
| window.location.href = url; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Мне немного не нравится эта история, так как мы используем Tanstack Router и с обычным window location могут быть конфликты в поведении роутинга, переходов назад и вперёд |
||
| } | ||
| } catch (error) { | ||
| console.error('Ошибка при навигации:', error); | ||
| } | ||
| }, []); | ||
|
|
||
| // Обработчик нового уведомления от SocketIO | ||
| const handleNewNotification = useCallback( | ||
| (data: NotificationT | RecipientNotificationResponse) => { | ||
|
|
@@ -107,9 +128,28 @@ export const useNotifications = () => { | |
| const title = generateNotificationTitle(notification); | ||
| const description = generateNotificationDescription(notification); | ||
|
|
||
| const { kind } = notification.payload; | ||
| const config = notificationConfigs[kind]; | ||
|
|
||
| toast(title, { | ||
| description, | ||
| duration: 5000, | ||
| action: config && ( | ||
| <Button | ||
| size="s" | ||
| className="ml-[20px]" | ||
| onClick={(e) => { | ||
| e.stopPropagation(); | ||
| // Получаем URL из конфига уведомления | ||
| const url = generateNotificationAction(notification); | ||
| if (url) { | ||
| onNavigate(url); | ||
| } | ||
| }} | ||
| > | ||
| Перейти | ||
| </Button> | ||
| ), | ||
| }); | ||
| }, | ||
| [refetchCount, transformNotification, queryClient], | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это кажется забыто