Skip to content

Commit

Permalink
USEOFFLINE CHECK FORMATE AND LINTING
Browse files Browse the repository at this point in the history
  • Loading branch information
Blazing-Mike committed Mar 15, 2024
1 parent dba4935 commit 8fc4b62
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
49 changes: 25 additions & 24 deletions packages/webapp/src/hooks/useOfflineCheck.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import { useState, useEffect } from "react";
import { toast } from "sonner";
import { useEffect, useState } from "react"

import { toast } from "sonner"

function useOfflineCheck() {
const [isOnline, setIsOnline] = useState(true);
const [isOnline, setIsOnline] = useState(true)

useEffect(() => {
const handleOnline = () => setIsOnline(true);
const handleOffline = () => setIsOnline(false);
useEffect(() => {
const handleOnline = () => setIsOnline(true)
const handleOffline = () => setIsOnline(false)

window.addEventListener("online", handleOnline);
window.addEventListener("offline", handleOffline);
window.addEventListener("online", handleOnline)
window.addEventListener("offline", handleOffline)

return () => {
window.removeEventListener("online", handleOnline);
window.removeEventListener("offline", handleOffline);
};
}, []);
return () => {
window.removeEventListener("online", handleOnline)
window.removeEventListener("offline", handleOffline)
}
}, [])

useEffect(() => {
if (!isOnline) {
toast.error("App is offline. Please check your internet connection.", {
dismissible: false,
duration: Infinity,
});
} else {
toast.dismiss();
}
}, [isOnline]);
useEffect(() => {
if (!isOnline) {
toast.error("App is offline. Please check your internet connection.", {
dismissible: false,
duration: Infinity,
})
} else {
toast.dismiss()
}
}, [isOnline])
}

export default useOfflineCheck;
export default useOfflineCheck
5 changes: 3 additions & 2 deletions packages/webapp/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import jotaiDebug from "src/components/lib/jotaiDebug"
import { GlobalErrorModal } from "src/components/modals/globalErrorModal"
import { Toaster } from "src/components/ui/sonner"
import { useIsHydrated } from "src/hooks/useIsHydrated"
import useOfflineCheck from "src/hooks/useOfflineCheck"
import { useErrorConfig } from "src/store/hooks"

import "src/styles/globals.css"
Expand All @@ -33,7 +34,7 @@ export type FablePage = NextPage<{ isHydrated: boolean }>
// =================================================================================================

const MyApp: AppType = ({ Component, pageProps }) => {
useOfflineCheck()
useOfflineCheck()
return (
<>
<Head>
Expand Down Expand Up @@ -96,4 +97,4 @@ const ComponentWrapper = ({ Component, pageProps }: { Component: ComponentType;
)
}

// =================================================================================================
// =================================================================================================
2 changes: 1 addition & 1 deletion packages/webapp/src/pages/play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,4 @@ const Play: FablePage = ({ isHydrated }) => {
)
}

export default Play
export default Play

0 comments on commit 8fc4b62

Please sign in to comment.