fix adding of language
This commit is contained in:
parent
aadc27262a
commit
4fba9cc23c
2 changed files with 24 additions and 7 deletions
|
@ -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]: '' }));
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ const Editor: Component<{ root: FileSystemDirectoryHandle }> = (props) => {
|
|||
const filesContext = useFiles();
|
||||
|
||||
const tabs = createMemo(() => filesContext.files().map(({ key, handle }) => {
|
||||
const [api, setApi] = createSignal<GridApi>();
|
||||
const [api, setApi] = createSignal<(GridApi & { addLocale(locale: string): void })>();
|
||||
const [entries, setEntries] = createSignal<Entries>(new Map());
|
||||
const [files, setFiles] = createSignal<Map<string, { id: string, handle: FileSystemFileHandle }>>(new Map());
|
||||
|
||||
|
@ -379,7 +379,7 @@ const Editor: Component<{ root: FileSystemDirectoryHandle }> = (props) => {
|
|||
</div>;
|
||||
};
|
||||
|
||||
const Content: Component<{ directory: FileSystemDirectoryHandle, api?: Setter<GridApi | undefined>, entries?: Setter<Entries> }> = (props) => {
|
||||
const Content: Component<{ directory: FileSystemDirectoryHandle, api?: Setter<(GridApi & { addLocale(locale: string): void }) | undefined>, entries?: Setter<Entries> }> = (props) => {
|
||||
const [entries, setEntries] = createSignal<Entries>(new Map());
|
||||
const [locales, setLocales] = createSignal<string[]>([]);
|
||||
const [rows, setRows] = createSignal<Entry[]>([]);
|
||||
|
@ -390,7 +390,18 @@ const Content: Component<{ directory: FileSystemDirectoryHandle, api?: Setter<Gr
|
|||
});
|
||||
|
||||
createEffect(() => {
|
||||
props.api?.(api());
|
||||
const a = api();
|
||||
|
||||
if (!a) {
|
||||
return;
|
||||
}
|
||||
|
||||
props.api?.({
|
||||
...a,
|
||||
addLocale(locale) {
|
||||
setLocales(current => new Set([...current, locale]).values().toArray());
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
createEffect(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue