Skip to content

Commit d035d9d

Browse files
OXeuBad3r
authored andcommitted
fix: hide uv pv stats when disabled (openRin#461)
(cherry picked from commit c3289c3)
1 parent d1f5f7f commit d035d9d

5 files changed

Lines changed: 26 additions & 6 deletions

File tree

client/src/components/footer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function Footer() {
1414
const [modeState, setModeState] = useState<ThemeMode>('system')
1515
const config = useContext(ClientConfigContext)
1616
const footerHtml = config.get<string>('footer')
17-
const loginEnabled = config.get<boolean>('login.enabled')
17+
const loginEnabled = config.getBoolean('login.enabled')
1818
const [doubleClickTimes, setDoubleClickTimes] = useState(0)
1919

2020
const setMode = useCallback((mode: ThemeMode) => {
@@ -74,7 +74,7 @@ function Footer() {
7474
<a className='hover:underline' href='https://github.com/Bad3r/Rin' target='_blank' rel='noopener'>
7575
Rin
7676
</a>
77-
{config.get<boolean>('rss') && (
77+
{config.getBoolean('rss') && (
7878
<>
7979
<Spliter />
8080
<Popup

client/src/components/header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ function UserAvatar({ className, profile }: { className?: string; profile?: Prof
323323
return (
324324
<>
325325
{' '}
326-
{config.get<boolean>('login.enabled') && (
326+
{config.getBoolean('login.enabled') && (
327327
<div className={`${className} flex flex-row items-center`}>
328328
{profile ? (
329329
<div className='w-8 relative group'>

client/src/page/feed.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function FeedPage({ id, TOC, clean }: { id: string; TOC: () => JSX.Elemen
3232
const { showConfirm, ConfirmUI } = useConfirm()
3333
const [top, setTop] = useState<number>(0)
3434
const config = useContext(ClientConfigContext)
35-
const counterEnabled = config.get<boolean>('counter.enabled')
35+
const counterEnabled = config.getBoolean('counter.enabled')
3636
const [aiSummaryEnabled, setAiSummaryEnabled] = useState(config.get<boolean>('ai_summary.enabled') ?? false)
3737

3838
// Listen for config changes
@@ -421,7 +421,7 @@ function Comments({ id }: { id: string }) {
421421
}, [id, loadComments])
422422
return (
423423
<>
424-
{config.get<boolean>('comment.enabled') && (
424+
{config.getBoolean('comment.enabled') && (
425425
<div className='m-2 flex flex-col justify-center items-center'>
426426
<CommentInput id={id} onRefresh={loadComments} />
427427
{error && (

client/src/page/settings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ function ItemSwitch({
331331
const { showAlert, AlertUI } = useAlert()
332332
const { t } = useTranslation()
333333
useEffect(() => {
334-
const value = config?.get<boolean>(configKey)
334+
const value = config?.getBoolean(configKey)
335335
if (value !== undefined) {
336336
setChecked(value)
337337
}

client/src/state/config.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ export class ConfigWrapper {
4444
default<T>(key: string) {
4545
return this.defaultConfig.get(key) as T
4646
}
47+
48+
getBoolean(key: string): boolean {
49+
const value = this.get<unknown>(key)
50+
51+
if (typeof value === 'boolean') {
52+
return value
53+
}
54+
55+
if (typeof value === 'string') {
56+
const normalizedValue = value.trim().toLowerCase()
57+
if (normalizedValue === 'true') return true
58+
if (normalizedValue === 'false') return false
59+
}
60+
61+
if (typeof value === 'number') {
62+
return value !== 0
63+
}
64+
65+
return Boolean(value)
66+
}
4767
}
4868

4969
export const defaultClientConfigWrapper = new ConfigWrapper({}, defaultClientConfig)

0 commit comments

Comments
 (0)