Skip to content
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

Notifications: Add sound option to generic useNotification hook and code cleanup #1023

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const useMarketplaceService = () => {
notisId: 'npwd:marketplace:newListingBroadcast',
content: resp.listing.description,
secondaryTitle: t('MARKETPLACE.NEW_LISTING'),
playSound: true,
});
},
[addListing, enqueueNotification],
Expand Down
48 changes: 0 additions & 48 deletions apps/phone/src/apps/match/hooks/useMatchNotifications.ts

This file was deleted.

1 change: 1 addition & 0 deletions apps/phone/src/apps/match/hooks/useMatchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const useMatchService = () => {
path: '/match',
keepOpen: false,
duration: 3000,
playSound: true,
});
addMatchedAccount();
};
Expand Down
70 changes: 0 additions & 70 deletions apps/phone/src/apps/messages/hooks/useMessageNotifications.ts

This file was deleted.

1 change: 1 addition & 0 deletions apps/phone/src/apps/messages/hooks/useMessageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const useMessagesService = () => {
onClick: () => goToConversation(group),
secondaryTitle: getDisplayByNumber(convoName) ?? convoName,
path: `/messages/conversations/${activeMessageConversation.id}`,
playSound: true,
});
},
[enqueueNotification],
Expand Down
81 changes: 0 additions & 81 deletions apps/phone/src/apps/twitter/hooks/useTwitterNotifications.ts

This file was deleted.

1 change: 1 addition & 0 deletions apps/phone/src/apps/twitter/hooks/useTwitterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const useTwitterService = () => {
notisId: 'npwd:tweetBroadcast',
secondaryTitle: data.profile_name,
path: '/twitter',
playSound: true,
});
},
[enqueueNotification],
Expand Down
68 changes: 0 additions & 68 deletions apps/phone/src/os/call/hooks/useCallNotifications.tsx

This file was deleted.

25 changes: 22 additions & 3 deletions apps/phone/src/os/new-notifications/useNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useSnackbar } from 'notistack';
import uuid from 'react-uuid';
import { useRecoilCallback } from 'recoil';
import { AlertEvents } from '@typings/alerts';
import fetchNui from '@utils/fetchNui';
import { useApps } from '../apps/hooks/useApps';
import uuid from 'react-uuid';

import {
notifications,
Expand All @@ -11,6 +13,18 @@ import {
unreadNotifications,
} from './state';

interface INotificationOptions {
appId: string,
content: string,
secondaryTitle: string,
notisId: string,
path: string,
keepOpen?: boolean,
onClick?: () => any,
duration?: number,
playSound?: boolean,
}

interface NotificationProps {
enqueueNotification: (options: any) => void;
removeAllActive: () => void;
Expand All @@ -35,7 +49,8 @@ export const useNotification = (): NotificationProps => {
keepOpen = false,
onClick,
duration,
}: any) => {
playSound,
}: INotificationOptions) => {
const app = getApp(appId);

const curNotis = await snapshot.getPromise(allNotificationIds);
Expand Down Expand Up @@ -86,9 +101,13 @@ export const useNotification = (): NotificationProps => {
secondaryTitle,
path,
app,
autoHideDuration: 3000 || duration,
autoHideDuration: duration || 3000,
disableWindowBlurListener: true,
});

if (playSound) {
fetchNui(AlertEvents.PLAY_ALERT);
}
},
);

Expand Down