From 4356db0996d9a4667f5a0bb1fc7b4b7404887f77 Mon Sep 17 00:00:00 2001 From: neoapps-dev Date: Wed, 27 May 2026 22:07:40 +0300 Subject: [PATCH] fix(LocEditorView): shallow copy and add in-place saving --- src/components/views/LocEditorView.tsx | 36 +++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/components/views/LocEditorView.tsx b/src/components/views/LocEditorView.tsx index 68be3b8..d597ceb 100644 --- a/src/components/views/LocEditorView.tsx +++ b/src/components/views/LocEditorView.tsx @@ -63,15 +63,24 @@ export default function LocEditorView() { const handleLocStringEdit = (langIdx: number, strIdx: number, isNew: boolean, key: string, value: string) => { if (!loc) return; playPressSound(); - const newLoc = { ...loc }; - const lang = newLoc.languages[langIdx]; - if (isNew) { - lang.strings.push(lang.isStatic ? { value } : { key, value }); - } else { - if (!lang.isStatic) lang.strings[strIdx].key = key; - lang.strings[strIdx].value = value; - } - setLoc(newLoc); + setLoc({ + ...loc, + languages: loc.languages.map((lang, lIdx) => { + if (lIdx !== langIdx) return lang; + if (isNew) { + return { + ...lang, + strings: [...lang.strings, lang.isStatic ? { value } : { key, value }] + }; + } + return { + ...lang, + strings: lang.strings.map((str, sIdx) => + sIdx !== strIdx ? str : { ...str, ...(!lang.isStatic ? { key } : {}), value } + ) + }; + }) + }); setIsLocEditModalOpen(null); showNotification(isNew ? "String Added" : "String Updated"); }; @@ -79,9 +88,12 @@ export default function LocEditorView() { const handleLocStringDelete = (langIdx: number, strIdx: number) => { if (!loc) return; playBackSound(); - const newLoc = { ...loc }; - newLoc.languages[langIdx].strings.splice(strIdx, 1); - setLoc(newLoc); + setLoc({ + ...loc, + languages: loc.languages.map((lang, lIdx) => + lIdx !== langIdx ? lang : { ...lang, strings: lang.strings.filter((_, sIdx) => sIdx !== strIdx) } + ) + }); showNotification("String Deleted"); };