Set page title

This commit is contained in:
Torjus Håkestad 2023-12-05 02:41:03 +01:00
parent f0dd632922
commit 2a5f0ea601
2 changed files with 28 additions and 4 deletions

View File

@ -61,9 +61,9 @@ export class MinistreamApiClient {
}
async siteInfo(): Promise<SiteInfo> {
var url = "/api/info"
var url = "/api/siteinfo"
if (this.ENV !== "production") {
url = "http://localhost:8080/api/info"
url = "http://localhost:8080/api/siteinfo"
}
const resp = await fetch(url,

View File

@ -32,6 +32,27 @@ export function App({ api }: AppProps) {
})
}
const updateTitle = () => {
const titleKey = "ministream.title"
var title = localStorage.getItem(titleKey)
const setTitle = (title: string) => {
const el = document.querySelector('title')
if (el) {
el.textContent = title
}
}
if (title) {
setTitle(title)
}
api.siteInfo().then((info) => {
if (info.siteName != title) {
setTitle(info.siteName)
localStorage.setItem(titleKey, info.siteName)
}
})
return
}
setInterval(() => {
updateStreamList()
}, 10000)
@ -39,6 +60,9 @@ export function App({ api }: AppProps) {
useEffect(() => {
updateStreamList()
}, [])
useEffect(() => {
updateTitle()
}, [])
return (