fix adding of language

This commit is contained in:
Chris Kruining 2025-01-03 04:56:21 +01:00
parent aadc27262a
commit 4fba9cc23c
No known key found for this signature in database
GPG key ID: EB894A3560CCCAD2
2 changed files with 24 additions and 7 deletions

View file

@ -11,7 +11,7 @@ export interface GridApi {
readonly selection: Accessor<SelectionItem<number, Entry>[]>;
remove(indices: number[]): void;
addKey(key: string): void;
addLocale(locale: string): void;
// addLocale(locale: string): void;
};
const groupBy = (rows: DataSetRowNode<number, Entry>[]) => {
@ -49,6 +49,15 @@ export function Grid(props: { class?: string, rows: Entry[], locales: string[],
const [api, setApi] = createSignal<GridCompApi<Entry>>();
createEffect(() => {
const r = rows();
const l = locales();
r.mutateEach(({ key, ...rest }) => {
return ({ key, ...Object.fromEntries(l.map(locale => [locale, rest[locale] ?? ''])) });
});
});
createEffect(() => {
const r = rows();
@ -59,9 +68,6 @@ export function Grid(props: { class?: string, rows: Entry[], locales: string[],
addKey(key) {
r.insert({ key, ...Object.fromEntries(locales().map(l => [l, ''])) });
},
addLocale(locale) {
r.mutateEach(entry => ({ ...entry, [locale]: '' }));
},
});
});