-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from builtbysuraj/dev
fix: Commented ServerStatus
- Loading branch information
Showing
4 changed files
with
76 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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,47 +1,47 @@ | ||
import axios from 'axios' | ||
import { PropsWithChildren, createContext, useEffect, useState } from 'react' | ||
|
||
import { ENV } from '@/conf' | ||
|
||
type ServerStateType = { | ||
status: boolean | ||
message: string | ||
} | ||
|
||
export const ServerStatusContext = createContext<ServerStateType | null>(null) | ||
|
||
export default function ServerStatusProvider({ children }: PropsWithChildren) { | ||
const [serverStatus, setServerStatus] = useState<ServerStateType>({ | ||
status: false, | ||
message: '', | ||
}) | ||
|
||
useEffect(() => { | ||
const checkServerStatus = async () => { | ||
try { | ||
const { data } = await axios.get(`${ENV.SERVER_URL}/status`) | ||
|
||
if (data.status) { | ||
setServerStatus(data) | ||
} else { | ||
setServerStatus({ status: false, message: 'Server is not running' }) | ||
} | ||
} catch (error) { | ||
setServerStatus({ status: false, message: 'Wait for server to start' }) | ||
} | ||
} | ||
|
||
checkServerStatus() | ||
|
||
const intervalId = setInterval(checkServerStatus, 10000) | ||
|
||
// Clear interval on component unmount | ||
return () => clearInterval(intervalId) | ||
}, []) | ||
|
||
return ( | ||
<ServerStatusContext.Provider value={serverStatus}> | ||
{children} | ||
</ServerStatusContext.Provider> | ||
) | ||
} | ||
// import axios from 'axios' | ||
// import { PropsWithChildren, createContext, useEffect, useState } from 'react' | ||
|
||
// import { ENV } from '@/conf' | ||
|
||
// type ServerStateType = { | ||
// status: boolean | ||
// message: string | ||
// } | ||
|
||
// export const ServerStatusContext = createContext<ServerStateType | null>(null) | ||
|
||
// export default function ServerStatusProvider({ children }: PropsWithChildren) { | ||
// const [serverStatus, setServerStatus] = useState<ServerStateType>({ | ||
// status: false, | ||
// message: '', | ||
// }) | ||
|
||
// useEffect(() => { | ||
// const checkServerStatus = async () => { | ||
// try { | ||
// const { data } = await axios.get(`${ENV.SERVER_URL}/status`) | ||
|
||
// if (data.status) { | ||
// setServerStatus(data) | ||
// } else { | ||
// setServerStatus({ status: false, message: 'Server is not running' }) | ||
// } | ||
// } catch (error) { | ||
// setServerStatus({ status: false, message: 'Wait for server to start' }) | ||
// } | ||
// } | ||
|
||
// checkServerStatus() | ||
|
||
// const intervalId = setInterval(checkServerStatus, 10000) | ||
|
||
// // Clear interval on component unmount | ||
// return () => clearInterval(intervalId) | ||
// }, []) | ||
|
||
// return ( | ||
// <ServerStatusContext.Provider value={serverStatus}> | ||
// {children} | ||
// </ServerStatusContext.Provider> | ||
// ) | ||
// } |
This file contains 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,12 +1,12 @@ | ||
import { ServerStatusContext } from '@/context/ServerStatusProvider' | ||
import { useContext } from 'react' | ||
// import { ServerStatusContext } from '@/context/ServerStatusProvider' | ||
// import { useContext } from 'react' | ||
|
||
export default function useServerStatus() { | ||
const context = useContext(ServerStatusContext) | ||
if (context === undefined) { | ||
throw new Error( | ||
'useServerStatus must be used within an ServerStatusProvider' | ||
) | ||
} | ||
return context | ||
} | ||
// export default function useServerStatus() { | ||
// const context = useContext(ServerStatusContext) | ||
// if (context === undefined) { | ||
// throw new Error( | ||
// 'useServerStatus must be used within an ServerStatusProvider' | ||
// ) | ||
// } | ||
// return context | ||
// } |
This file contains 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 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