Set title and convert all class component to functional #4
| @@ -61,9 +61,9 @@ export class MinistreamApiClient { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async siteInfo(): Promise<SiteInfo> { |     async siteInfo(): Promise<SiteInfo> { | ||||||
|         var url = "/api/info" |         var url = "/api/siteinfo" | ||||||
|         if (this.ENV !== "production") { |         if (this.ENV !== "production") { | ||||||
|             url = "http://localhost:8080/api/info" |             url = "http://localhost:8080/api/siteinfo" | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         const resp = await fetch(url, |         const resp = await fetch(url, | ||||||
|   | |||||||
| @@ -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(() => { |     setInterval(() => { | ||||||
|         updateStreamList() |         updateStreamList() | ||||||
|     }, 10000) |     }, 10000) | ||||||
|  |  | ||||||
|     useEffect(() => { |     useEffect(() => { | ||||||
|         updateStreamList() |         updateStreamList() | ||||||
|     },[]) |     }, []) | ||||||
|  |     useEffect(() => { | ||||||
|  |         updateTitle() | ||||||
|  |     }, []) | ||||||
|  |  | ||||||
|  |  | ||||||
|     return ( |     return ( | ||||||
| @@ -57,5 +81,5 @@ const rootElement = document.getElementById("app"); | |||||||
| if (rootElement) { | if (rootElement) { | ||||||
|     const root = createRoot(rootElement); |     const root = createRoot(rootElement); | ||||||
|     const api = new MinistreamApiClient() |     const api = new MinistreamApiClient() | ||||||
|     root.render(<App api={api}/>) |     root.render(<App api={api} />) | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user