Update hub-button-app to use a local script
Co-authored-by: Firespray-31 <147506444+Firespray-31@users.noreply.github.com>
This commit is contained in:
parent
5df4c270a7
commit
2580d0f95c
7 changed files with 124 additions and 37 deletions
40
webui/src/contexts/version.tsx
Normal file
40
webui/src/contexts/version.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { createContext, ReactNode, useEffect, useState } from 'react'
|
||||
|
||||
type VersionContextProps = {
|
||||
showHubButton: boolean
|
||||
version: string
|
||||
}
|
||||
|
||||
export const VersionContext = createContext<VersionContextProps>({
|
||||
showHubButton: false,
|
||||
version: '',
|
||||
})
|
||||
|
||||
type VersionProviderProps = {
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
export const VersionProvider = ({ children }: VersionProviderProps) => {
|
||||
const [showHubButton, setShowHubButton] = useState(false)
|
||||
const [version, setVersion] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
const fetchVersion = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/version')
|
||||
if (!response.ok) {
|
||||
throw new Error(`Network error: ${response.status}`)
|
||||
}
|
||||
const data: API.Version = await response.json()
|
||||
setShowHubButton(!data.disableDashboardAd)
|
||||
setVersion(data.Version)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
fetchVersion()
|
||||
}, [])
|
||||
|
||||
return <VersionContext.Provider value={{ showHubButton, version }}>{children}</VersionContext.Provider>
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue