This commit is contained in:
llama 2025-07-04 17:50:38 +08:00
parent db0b86e90f
commit 024a31f597
No known key found for this signature in database
GPG key ID: 0B7543854B9413C3

View file

@ -22,8 +22,12 @@ export function getGlobalNotetype(meta: CsvMetadata): CsvMetadata_MappedNotetype
return meta.notetype.case === "globalNotetype" ? meta.notetype.value : null; return meta.notetype.case === "globalNotetype" ? meta.notetype.value : null;
} }
export function getDeckId(meta: CsvMetadata): bigint | null { export function getDeckId(meta: CsvMetadata): bigint {
return meta.deck.case === "deckId" ? meta.deck.value : null; return meta.deck.case === "deckId" ? meta.deck.value : 0n;
}
export function getDeckName(meta: CsvMetadata): string | null {
return meta.deck.case === "deckName" ? meta.deck.value : null;
} }
export class ImportCsvState { export class ImportCsvState {
@ -35,6 +39,7 @@ export class ImportCsvState {
readonly defaultIsHtml: boolean; readonly defaultIsHtml: boolean;
readonly defaultNotetypeId: bigint | null; readonly defaultNotetypeId: bigint | null;
readonly defaultDeckId: bigint | null; readonly defaultDeckId: bigint | null;
readonly newDeckName: string | null;
readonly metadata: Writable<CsvMetadata>; readonly metadata: Writable<CsvMetadata>;
readonly globalNotetype: Writable<CsvMetadata_MappedNotetype | null>; readonly globalNotetype: Writable<CsvMetadata_MappedNotetype | null>;
@ -83,6 +88,7 @@ export class ImportCsvState {
this.defaultIsHtml = metadata.isHtml; this.defaultIsHtml = metadata.isHtml;
this.defaultNotetypeId = this.lastGlobalNotetype?.id || null; this.defaultNotetypeId = this.lastGlobalNotetype?.id || null;
this.defaultDeckId = this.lastDeckId; this.defaultDeckId = this.lastDeckId;
this.newDeckName = getDeckName(metadata);
} }
doImport(): Promise<ImportResponse> { doImport(): Promise<ImportResponse> {
@ -104,7 +110,7 @@ export class ImportCsvState {
path: this.path, path: this.path,
delimiter: changed.delimiter, delimiter: changed.delimiter,
notetypeId: getGlobalNotetype(changed)?.id, notetypeId: getGlobalNotetype(changed)?.id,
deckId: getDeckId(changed) ?? undefined, deckId: getDeckId(changed) || undefined,
isHtml: changed.isHtml, isHtml: changed.isHtml,
}); });
// carry over tags // carry over tags
@ -157,7 +163,13 @@ export class ImportCsvState {
this.lastDeckId = deckId; this.lastDeckId = deckId;
if (deckId !== null) { if (deckId !== null) {
this.metadata.update((metadata) => { this.metadata.update((metadata) => {
metadata.deck.value = deckId; if (deckId !== 0n) {
metadata.deck.case = "deckId";
metadata.deck.value = deckId;
} else {
metadata.deck.case = "deckName";
metadata.deck.value = this.newDeckName!;
}
return metadata; return metadata;
}); });
} }