From bfa3fa293ffe6027d0cafcecbd6ff3a8ae8988a4 Mon Sep 17 00:00:00 2001 From: dongchengjie <37543964+dongchengjie@users.noreply.github.com> Date: Sun, 23 Jun 2024 06:47:51 +0800 Subject: [PATCH] fix: `update_interval` won't save when creating local profile while updating does & number input locales --- src-tauri/src/config/prfitem.rs | 14 ++++++++--- src/components/profile/profile-viewer.tsx | 15 +++-------- src/components/setting/mods/misc-viewer.tsx | 28 +++++++++++++-------- src/locales/en.json | 6 ++++- src/locales/fa.json | 6 ++++- src/locales/ru.json | 6 ++++- src/locales/zh.json | 8 ++++-- 7 files changed, 53 insertions(+), 30 deletions(-) diff --git a/src-tauri/src/config/prfitem.rs b/src-tauri/src/config/prfitem.rs index 2846a38..d2a7955 100644 --- a/src-tauri/src/config/prfitem.rs +++ b/src-tauri/src/config/prfitem.rs @@ -135,7 +135,7 @@ impl PrfItem { "local" => { let name = item.name.unwrap_or("Local File".into()); let desc = item.desc.unwrap_or("".into()); - PrfItem::from_local(name, desc, file_data) + PrfItem::from_local(name, desc, file_data, item.option) } "merge" => { let name = item.name.unwrap_or("Merge".into()); @@ -153,7 +153,12 @@ impl PrfItem { /// ## Local type /// create a new item from name/desc - pub fn from_local(name: String, desc: String, file_data: Option) -> Result { + pub fn from_local( + name: String, + desc: String, + file_data: Option, + option: Option, + ) -> Result { let uid = help::get_uid("l"); let file = format!("{uid}.yaml"); @@ -166,7 +171,10 @@ impl PrfItem { url: None, selected: None, extra: None, - option: None, + option: Some(PrfOption { + update_interval: option.unwrap_or_default().update_interval, + ..PrfOption::default() + }), home: None, updated: Some(chrono::Local::now().timestamp() as usize), file_data: Some(file_data.unwrap_or(tmpl::ITEM_LOCAL.into())), diff --git a/src/components/profile/profile-viewer.tsx b/src/components/profile/profile-viewer.tsx index 14839dd..0a67523 100644 --- a/src/components/profile/profile-viewer.tsx +++ b/src/components/profile/profile-viewer.tsx @@ -95,6 +95,7 @@ export const ProfileViewer = forwardRef( if (form.type !== "remote" && form.type !== "local") { delete form.option; } + if (form.option?.update_interval) { form.option.update_interval = +form.option.update_interval; } else { @@ -228,16 +229,11 @@ export const ProfileViewer = forwardRef( { - e.target.value = e.target.value - ?.replace(/\D/, "") - .slice(0, 10); - field.onChange(e); - }} + type="number" label={t("Update Interval")} InputProps={{ endAdornment: ( - mins + {t("mins")} ), }} /> @@ -248,10 +244,7 @@ export const ProfileViewer = forwardRef( {isLocal && openType === "new" && ( { - if (!formIns.getValues("name")) { - const name = file.name.substring(0, file.name.lastIndexOf(".")); - formIns.setValue("name", name); - } + formIns.setValue("name", formIns.getValues("name") || file.name); fileDataRef.current = val; }} /> diff --git a/src/components/setting/mods/misc-viewer.tsx b/src/components/setting/mods/misc-viewer.tsx index 6e2de5e..ca94aa0 100644 --- a/src/components/setting/mods/misc-viewer.tsx +++ b/src/components/setting/mods/misc-viewer.tsx @@ -8,6 +8,7 @@ import { MenuItem, Select, TextField, + InputAdornment, } from "@mui/material"; import { useVerge } from "@/hooks/use-verge"; import { BaseDialog, DialogRef, Notice, Switch } from "@/components/base"; @@ -81,12 +82,12 @@ export const MiscViewer = forwardRef((props, ref) => { size="small" sx={{ width: 100, "> div": { py: "7.5px" } }} value={values.appLogLevel} - onChange={(e) => { + onChange={(e) => setValues((v) => ({ ...v, appLogLevel: e.target.value as string, - })); - }} + })) + } > {["trace", "debug", "info", "warn", "error", "silent"].map((i) => ( @@ -130,20 +131,20 @@ export const MiscViewer = forwardRef((props, ref) => { - +