1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-23 15:37:59 +01:00
Whalebird-desktop-client-ma.../renderer/components/Settings.tsx

96 lines
2.5 KiB
TypeScript
Raw Normal View History

import { localeType } from '@/provider/i18n'
import { Dialog, DialogBody, DialogHeader, Input, Option, Select, Typography } from '@material-tailwind/react'
2023-12-04 17:17:52 +01:00
import { ChangeEvent, useEffect, useState } from 'react'
2023-12-04 17:08:12 +01:00
import { FormattedMessage } from 'react-intl'
type Props = {
opened: boolean
close: () => void
2023-12-04 17:17:52 +01:00
reloadSettings: () => void
2023-12-04 17:08:12 +01:00
}
const languages = [
{
label: 'English',
value: 'en'
},
{
label: '日本語',
value: 'ja'
2024-02-05 13:52:13 +01:00
},
{
label: 'Português',
value: 'pt-PT'
2023-12-04 17:08:12 +01:00
}
]
export default function Settings(props: Props) {
const [language, setLanguage] = useState<localeType>('en')
2023-12-06 16:10:16 +01:00
const [fontSize, setFontSize] = useState<number>(16)
2023-12-04 17:08:12 +01:00
useEffect(() => {
if (typeof localStorage !== 'undefined') {
const lang = localStorage.getItem('language')
2024-02-05 13:52:13 +01:00
if (lang) {
setLanguage(lang as localeType)
} else {
setLanguage('en')
}
2023-12-04 17:08:12 +01:00
}
}, [])
const languageChanged = (e: string) => {
2024-02-05 13:52:13 +01:00
setLanguage(e as localeType)
2023-12-04 17:08:12 +01:00
if (typeof localStorage !== 'undefined') {
localStorage.setItem('language', e)
2023-12-04 17:08:12 +01:00
}
2023-12-04 17:17:52 +01:00
props.reloadSettings()
2023-12-04 17:08:12 +01:00
}
2023-12-06 16:10:16 +01:00
const fontSizeChanged = (e: ChangeEvent<HTMLInputElement>) => {
setFontSize(parseInt(e.target.value))
if (typeof localStorage !== 'undefined') {
localStorage.setItem('fontSize', e.target.value)
}
props.reloadSettings()
}
2023-12-04 17:08:12 +01:00
return (
<Dialog open={props.opened} handler={props.close} size="sm">
<DialogHeader>
2023-12-04 17:08:12 +01:00
<FormattedMessage id="settings.title" />
</DialogHeader>
<DialogBody>
2023-12-06 16:10:16 +01:00
<div className="flex flex-col gap-4">
<div>
<div className="mb-2">
<Typography>
2023-12-06 16:10:16 +01:00
<FormattedMessage id="settings.font_size" />
</Typography>
2023-12-06 16:10:16 +01:00
</div>
<div>
<Input type="number" value={fontSize} onChange={fontSizeChanged} />
2023-12-06 16:10:16 +01:00
</div>
</div>
<div>
<div className="mb-2">
<Typography>
2023-12-06 16:10:16 +01:00
<FormattedMessage id="settings.language" />
</Typography>
2023-12-06 16:10:16 +01:00
</div>
<div>
<Select id="language" onChange={languageChanged} value={language}>
2023-12-06 16:10:16 +01:00
{languages.map(lang => (
<Option key={lang.value} value={lang.value}>
2023-12-06 16:10:16 +01:00
{lang.label}
</Option>
2023-12-06 16:10:16 +01:00
))}
</Select>
</div>
</div>
2023-12-04 17:08:12 +01:00
</div>
</DialogBody>
</Dialog>
2023-12-04 17:08:12 +01:00
)
}