Skip to content

Commit

Permalink
fix: do not prerequest default favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
OXeu committed Jul 8, 2024
2 parents b6d1072 + ee88254 commit 6a0f036
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react'
import { useEffect, useMemo, useRef, useState } from 'react'
import { Helmet } from 'react-helmet'
import { getCookie } from 'typescript-cookie'
import { DefaultParams, PathPattern, Route, Switch } from 'wouter'
Expand All @@ -16,15 +16,15 @@ import { HashtagsPage } from './page/hashtags.tsx'
import { Settings } from "./page/settings.tsx"
import { TimelinePage } from './page/timeline'
import { WritingPage } from './page/writing'
import { ClientConfigContext, ConfigWrapper, defaultClientConfig, defaultClientConfigWrapper } from './state/config.tsx'
import { ClientConfigContext, ConfigWrapper, defaultClientConfig } from './state/config.tsx'
import { Profile, ProfileContext } from './state/profile'
import { headersWithAuth } from './utils/auth'
import { tryInt } from './utils/int'

function App() {
const ref = useRef(false)
const [profile, setProfile] = useState<Profile | undefined>()
const [config, setConfig] = useState<ConfigWrapper>(defaultClientConfigWrapper)
const [config, setConfig] = useState<ConfigWrapper>(new ConfigWrapper({}, new Map()))
useEffect(() => {
if (ref.current) return
if (getCookie('token')?.length ?? 0 > 0) {
Expand Down Expand Up @@ -57,12 +57,14 @@ function App() {
}
ref.current = true
}, [])
const favicon = useMemo(() => config.get<string>("favicon"), [config])
return (
<>
<ClientConfigContext.Provider value={config}>
<ProfileContext.Provider value={profile}>
<Helmet>
<link rel="icon" href={config.get("favicon")} />
{favicon &&
<link rel="icon" href={favicon} />}
</Helmet>
<Switch>
<RouteMe path="/">
Expand Down
5 changes: 3 additions & 2 deletions client/src/state/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export class ConfigWrapper {
this.defaultConfig = defaultConfig;
}
get<T>(key: string) {
if (this.config[key] != undefined) {
return this.config[key] as T;
const value = this.config[key];
if (value != undefined && value != "") {
return value as T;
}
if (this.defaultConfig.has(key)) {
return this.defaultConfig.get(key) as T;
Expand Down

0 comments on commit 6a0f036

Please sign in to comment.