This commit is contained in:
piradata 2024-05-16 02:52:10 -03:00
parent 72aa822655
commit 653afa7210

View File

@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import ISO6391 from 'iso-639-1'
import ISO6391 from "iso-639-1";
import { TextField, Button, CheckboxField, Select } from "@renderer/components";
import { useTranslation } from "react-i18next";
@ -18,29 +18,29 @@ export function SettingsGeneral({
userPreferences,
updateUserPreferences,
}: SettingsGeneralProps) {
const { t } = useTranslation("settings");
const [form, setForm] = useState(
{
downloadsPath: '',
const [form, setForm] = useState({
downloadsPath: "",
downloadNotificationsEnabled: false,
repackUpdatesNotificationsEnabled: false,
language: '',
}
);
language: "",
});
const [defaultDownloadsPath, setdefaultDownloadsPath] = useState('');
const [defaultDownloadsPath, setdefaultDownloadsPath] = useState("");
useEffect(() => {
async function fetchdefaultDownloadsPath() {
setdefaultDownloadsPath(await window.electron.getDefaultDownloadsPath())
setdefaultDownloadsPath(await window.electron.getDefaultDownloadsPath());
}
fetchdefaultDownloadsPath();
}, []);
useEffect(updateFormWithUserPreferences, [userPreferences, defaultDownloadsPath]);
useEffect(updateFormWithUserPreferences, [
userPreferences,
defaultDownloadsPath,
]);
const handleLanguageChange = (event) => {
const value = event.target.value;
@ -74,9 +74,11 @@ export function SettingsGeneral({
setForm((prev) => ({
...prev,
downloadsPath: userPreferences.downloadsPath ?? defaultDownloadsPath,
downloadNotificationsEnabled: userPreferences.downloadNotificationsEnabled,
repackUpdatesNotificationsEnabled: userPreferences.repackUpdatesNotificationsEnabled,
language: userPreferences.language
downloadNotificationsEnabled:
userPreferences.downloadNotificationsEnabled,
repackUpdatesNotificationsEnabled:
userPreferences.repackUpdatesNotificationsEnabled,
language: userPreferences.language,
}));
}
}
@ -103,8 +105,10 @@ export function SettingsGeneral({
<h3>{t("language")}</h3>
<>
<Select value={form.language} onChange={handleLanguageChange}>
{Object.keys(languageResources).map(language => (
<option key={language} value={language}>{ISO6391.getName(language)}</option>
{Object.keys(languageResources).map((language) => (
<option key={language} value={language}>
{ISO6391.getName(language)}
</option>
))}
</Select>
</>