Introduce new batch metadata update function

This commit is contained in:
schroda
2026-03-06 21:40:41 +01:00
parent 430939a47a
commit 57e05bf20d
5 changed files with 266 additions and 54 deletions

View File

@@ -34,7 +34,7 @@ import {
SourceNameInfo,
} from '@/features/source/Source.types.ts';
import { Sources } from '@/features/source/services/Sources';
import { getSourceMetadata, updateSourceMetadata } from '@/features/source/services/SourceMetadata.ts';
import { batchUpdateSourceMetadata, getSourceMetadata } from '@/features/source/services/SourceMetadata.ts';
import { requestManager } from '@/lib/requests/RequestManager.ts';
import { ListCardAvatar } from '@/base/components/lists/cards/ListCardAvatar.tsx';
import { makeToast } from '@/base/utils/Toast.ts';
@@ -113,10 +113,21 @@ export const SourceLanguageSelect = ({
const handleOk = () => {
setOpen(false);
Promise.all(
Object.entries(tmpSourceIdToEnabledState).map(([sourceId, enabled]) =>
updateSourceMetadata(sources.find((source) => source.id === sourceId)!, 'isEnabled', enabled),
),
batchUpdateSourceMetadata(
Object.entries(tmpSourceIdToEnabledState)
.map(([sourceId, enabled]) => {
const source = sources.find((sourceToEnable) => sourceToEnable.id === sourceId);
if (!source) {
return null;
}
return {
sources: [source],
entries: [{ metadataKey: 'isEnabled' as const, value: enabled }],
};
})
.filter((entry) => entry !== null),
).catch((e) => makeToast(t`Failed to save changes`, 'error', getErrorMessage(e)));
setTmpSourceIdToEnabledState({});
setSelectedLanguages(toUniqueLanguageCodes(tmpSelectedLanguages));