From 2a5f0ea6010f3324092ad4cb9c98cc17cc46abdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Tue, 5 Dec 2023 02:41:03 +0100 Subject: [PATCH] Set page title --- src/js/api.ts | 4 ++-- src/js/app.tsx | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/js/api.ts b/src/js/api.ts index 137675c..3021467 100644 --- a/src/js/api.ts +++ b/src/js/api.ts @@ -61,9 +61,9 @@ export class MinistreamApiClient { } async siteInfo(): Promise { - 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, diff --git a/src/js/app.tsx b/src/js/app.tsx index 54806f0..dbb607f 100644 --- a/src/js/app.tsx +++ b/src/js/app.tsx @@ -32,13 +32,37 @@ 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) useEffect(() => { updateStreamList() - },[]) + }, []) + useEffect(() => { + updateTitle() + }, []) return ( @@ -57,5 +81,5 @@ const rootElement = document.getElementById("app"); if (rootElement) { const root = createRoot(rootElement); const api = new MinistreamApiClient() - root.render() + root.render() } \ No newline at end of file