2024-01-29 16:10:44 +01:00
|
|
|
import { localeType } from '@/provider/i18n'
|
2024-01-09 13:30:05 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}, [])
|
|
|
|
|
2024-01-09 13:30:05 +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') {
|
2024-01-09 13:30:05 +01:00
|
|
|
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 (
|
2024-01-09 13:30:05 +01:00
|
|
|
<Dialog open={props.opened} handler={props.close} size="sm">
|
|
|
|
<DialogHeader>
|
2023-12-04 17:08:12 +01:00
|
|
|
<FormattedMessage id="settings.title" />
|
2024-01-09 13:30:05 +01:00
|
|
|
</DialogHeader>
|
|
|
|
<DialogBody>
|
2023-12-06 16:10:16 +01:00
|
|
|
<div className="flex flex-col gap-4">
|
|
|
|
<div>
|
|
|
|
<div className="mb-2">
|
2024-01-09 13:30:05 +01:00
|
|
|
<Typography>
|
2023-12-06 16:10:16 +01:00
|
|
|
<FormattedMessage id="settings.font_size" />
|
2024-01-09 13:30:05 +01:00
|
|
|
</Typography>
|
2023-12-06 16:10:16 +01:00
|
|
|
</div>
|
|
|
|
<div>
|
2024-01-09 13:30:05 +01:00
|
|
|
<Input type="number" value={fontSize} onChange={fontSizeChanged} />
|
2023-12-06 16:10:16 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div className="mb-2">
|
2024-01-09 13:30:05 +01:00
|
|
|
<Typography>
|
2023-12-06 16:10:16 +01:00
|
|
|
<FormattedMessage id="settings.language" />
|
2024-01-09 13:30:05 +01:00
|
|
|
</Typography>
|
2023-12-06 16:10:16 +01:00
|
|
|
</div>
|
|
|
|
<div>
|
2024-01-09 13:30:05 +01:00
|
|
|
<Select id="language" onChange={languageChanged} value={language}>
|
2023-12-06 16:10:16 +01:00
|
|
|
{languages.map(lang => (
|
2024-01-09 13:30:05 +01:00
|
|
|
<Option key={lang.value} value={lang.value}>
|
2023-12-06 16:10:16 +01:00
|
|
|
{lang.label}
|
2024-01-09 13:30:05 +01:00
|
|
|
</Option>
|
2023-12-06 16:10:16 +01:00
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-04 17:08:12 +01:00
|
|
|
</div>
|
2024-01-09 13:30:05 +01:00
|
|
|
</DialogBody>
|
|
|
|
</Dialog>
|
2023-12-04 17:08:12 +01:00
|
|
|
)
|
|
|
|
}
|