Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit025eae7

Browse files
committed
conditionally hide push notification button
1 parent801f22d commit025eae7

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

‎site/src/contexts/usePushNotifications.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useQuery } from "react-query";
77
interfacePushNotifications{
88
readonlysubscribed:boolean;
99
readonlyloading:boolean;
10+
readonlyenabled:boolean;
1011

1112
subscribe():Promise<void>;
1213
unsubscribe():Promise<void>;
@@ -19,6 +20,17 @@ export const usePushNotifications = (): PushNotifications => {
1920
const[subscribed,setSubscribed]=useState<boolean>(false);
2021
const[loading,setLoading]=useState<boolean>(true);
2122

23+
// Disable push notifications if the server is not configured to send them.
24+
constenabled=!!buildInfoQuery.data?.push_notifications_public_key;
25+
if(!enabled){
26+
return{
27+
enabled:false,
28+
subscribed:false,
29+
loading:false,
30+
subscribe:async()=>{},
31+
unsubscribe:async()=>{},
32+
};
33+
}
2234
useEffect(()=>{
2335
// Check if browser supports push notifications
2436
if(!("Notification"inwindow)||!("serviceWorker"innavigator)){
@@ -95,6 +107,7 @@ export const usePushNotifications = (): PushNotifications => {
95107
};
96108

97109
return{
110+
enabled,
98111
subscribed,
99112
loading:loading||buildInfoQuery.isLoading,
100113
subscribe,

‎site/src/modules/dashboard/Navbar/NavbarView.tsx‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const NavbarView: FC<NavbarViewProps> = ({
4444
canViewAuditLog,
4545
proxyContextValue,
4646
})=>{
47-
const{ subscribed, loading, subscribe, unsubscribe}=
47+
const{enabled,subscribed, loading, subscribe, unsubscribe}=
4848
usePushNotifications();
4949

5050
return(
@@ -59,13 +59,13 @@ export const NavbarView: FC<NavbarViewProps> = ({
5959

6060
<NavItemsclassName="ml-4"/>
6161

62-
{/* // TODO: styling required here.
63-
{subscribed ? (
64-
<button onClick={unsubscribe}>Unsubscribe</button>
65-
) : (
66-
<button onClick={subscribe}>Subscribe</button>
62+
{enabled&&(
63+
subscribed ?(
64+
<buttononClick={unsubscribe}>Unsubscribe</button>
65+
) :(
66+
<buttononClick={subscribe}>Subscribe</button>
67+
)
6768
)}
68-
*/}
6969

7070
<divclassName=" hidden md:flex items-center gap-3 ml-auto">
7171
{proxyContextValue&&(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp