fix(LocEditorView): shallow copy and add in-place saving

This commit is contained in:
neoapps-dev
2026-05-27 22:07:40 +03:00
parent d70ab4a128
commit 4356db0996
+22 -10
View File
@@ -63,15 +63,24 @@ export default function LocEditorView() {
const handleLocStringEdit = (langIdx: number, strIdx: number, isNew: boolean, key: string, value: string) => { const handleLocStringEdit = (langIdx: number, strIdx: number, isNew: boolean, key: string, value: string) => {
if (!loc) return; if (!loc) return;
playPressSound(); playPressSound();
const newLoc = { ...loc }; setLoc({
const lang = newLoc.languages[langIdx]; ...loc,
languages: loc.languages.map((lang, lIdx) => {
if (lIdx !== langIdx) return lang;
if (isNew) { if (isNew) {
lang.strings.push(lang.isStatic ? { value } : { key, value }); return {
} else { ...lang,
if (!lang.isStatic) lang.strings[strIdx].key = key; strings: [...lang.strings, lang.isStatic ? { value } : { key, value }]
lang.strings[strIdx].value = value; };
} }
setLoc(newLoc); return {
...lang,
strings: lang.strings.map((str, sIdx) =>
sIdx !== strIdx ? str : { ...str, ...(!lang.isStatic ? { key } : {}), value }
)
};
})
});
setIsLocEditModalOpen(null); setIsLocEditModalOpen(null);
showNotification(isNew ? "String Added" : "String Updated"); showNotification(isNew ? "String Added" : "String Updated");
}; };
@@ -79,9 +88,12 @@ export default function LocEditorView() {
const handleLocStringDelete = (langIdx: number, strIdx: number) => { const handleLocStringDelete = (langIdx: number, strIdx: number) => {
if (!loc) return; if (!loc) return;
playBackSound(); playBackSound();
const newLoc = { ...loc }; setLoc({
newLoc.languages[langIdx].strings.splice(strIdx, 1); ...loc,
setLoc(newLoc); languages: loc.languages.map((lang, lIdx) =>
lIdx !== langIdx ? lang : { ...lang, strings: lang.strings.filter((_, sIdx) => sIdx !== strIdx) }
)
});
showNotification("String Deleted"); showNotification("String Deleted");
}; };