mirror of
https://github.com/LCE-Hub/LCE-Emerald-Launcher.git
synced 2026-09-23 08:32:51 +00:00
fix(LocEditorView): shallow copy and add in-place saving
This commit is contained in:
@@ -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");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user