mirror of
https://github.com/litruv/AudioSort.git
synced 2026-07-24 02:36:01 +10:00
chore: update dependencies and add patch-package for better-sqlite3
feat: implement just-split category filter and enhance metadata parsing fix: improve type imports and variable handling in services
This commit is contained in:
38
package.json
38
package.json
@@ -16,32 +16,34 @@
|
|||||||
"start": "cross-env NODE_ENV=production electron ./dist/main/main/index.js",
|
"start": "cross-env NODE_ENV=production electron ./dist/main/main/index.js",
|
||||||
"pack": "npm run build && electron-builder --dir",
|
"pack": "npm run build && electron-builder --dir",
|
||||||
"dist": "npm run build && electron-builder",
|
"dist": "npm run build && electron-builder",
|
||||||
"dist:win": "npm run build && electron-builder --win"
|
"dist:win": "npm run build && electron-builder --win",
|
||||||
|
"postinstall": "patch-package"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "^11.0.0",
|
"better-sqlite3": "^12.4.1",
|
||||||
"csv-parse": "^5.5.5",
|
"csv-parse": "^6.1.0",
|
||||||
"fast-glob": "^3.3.2",
|
"fast-glob": "^3.3.3",
|
||||||
"fuse.js": "^6.6.2",
|
"fuse.js": "^7.1.0",
|
||||||
"music-metadata": "^10.5.0",
|
"music-metadata": "^11.10.0",
|
||||||
"react": "^18.3.1",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^19.2.0",
|
||||||
"standardized-audio-context": "^25.3.12",
|
"standardized-audio-context": "^25.3.77",
|
||||||
"wavefile": "^11.0.0"
|
"wavefile": "^11.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/better-sqlite3": "^7.6.8",
|
"@types/better-sqlite3": "^7.6.13",
|
||||||
"@types/node": "^20.12.7",
|
"@types/node": "^24.10.0",
|
||||||
"@types/react": "^18.3.3",
|
"@types/react": "^19.2.2",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^19.2.2",
|
||||||
"@vitejs/plugin-react": "^4.3.3",
|
"@vitejs/plugin-react": "^5.1.0",
|
||||||
"concurrently": "^8.2.2",
|
"concurrently": "^9.2.1",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^10.1.0",
|
||||||
"electron": "^39.1.2",
|
"electron": "^39.1.2",
|
||||||
"electron-builder": "^26.0.12",
|
"electron-builder": "^26.0.12",
|
||||||
|
"patch-package": "^8.0.1",
|
||||||
"tree-kill": "^1.2.2",
|
"tree-kill": "^1.2.2",
|
||||||
"tsx": "^4.15.7",
|
"tsx": "^4.20.6",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.9.3",
|
||||||
"vite": "^7.2.2"
|
"vite": "^7.2.2"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
|
|||||||
13
patches/better-sqlite3+12.4.1.patch
Normal file
13
patches/better-sqlite3+12.4.1.patch
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
diff --git a/node_modules/better-sqlite3/src/better_sqlite3.cpp b/node_modules/better-sqlite3/src/better_sqlite3.cpp
|
||||||
|
index 024bb4f..28a4d55 100644
|
||||||
|
--- a/node_modules/better-sqlite3/src/better_sqlite3.cpp
|
||||||
|
+++ b/node_modules/better-sqlite3/src/better_sqlite3.cpp
|
||||||
|
@@ -46,7 +46,7 @@ class Backup;
|
||||||
|
#include "objects/statement-iterator.cpp"
|
||||||
|
|
||||||
|
NODE_MODULE_INIT(/* exports, context */) {
|
||||||
|
- v8::Isolate* isolate = context->GetIsolate();
|
||||||
|
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
|
Addon::ConfigureURI();
|
||||||
|
|
||||||
@@ -12,6 +12,15 @@ import { SearchService } from './SearchService';
|
|||||||
import { WaveFile } from 'wavefile';
|
import { WaveFile } from 'wavefile';
|
||||||
import { OrganizationService } from './OrganizationService';
|
import { OrganizationService } from './OrganizationService';
|
||||||
|
|
||||||
|
type MusicMetadataParser = (path: string, options?: { duration?: boolean }) => Promise<{
|
||||||
|
format: { duration?: number | null; sampleRate?: number | null; bitsPerSample?: number | null };
|
||||||
|
common: { comment?: unknown[]; genre?: unknown[]; subtitle?: unknown };
|
||||||
|
}>;
|
||||||
|
|
||||||
|
type MusicMetadataNamespace = Partial<{ parseFile: MusicMetadataParser }> & {
|
||||||
|
default?: Partial<{ parseFile: MusicMetadataParser }>;
|
||||||
|
};
|
||||||
|
|
||||||
interface CsvCategoryRow {
|
interface CsvCategoryRow {
|
||||||
Category: string;
|
Category: string;
|
||||||
SubCategory: string;
|
SubCategory: string;
|
||||||
@@ -32,6 +41,7 @@ export class LibraryService {
|
|||||||
private metadataSuggestionCache: { authors: Set<string> } | null = null;
|
private metadataSuggestionCache: { authors: Set<string> } | null = null;
|
||||||
private readonly waveformPreviewCache = new Map<number, { modifiedAt: number; pointCount: number; samples: number[]; rms: number }>();
|
private readonly waveformPreviewCache = new Map<number, { modifiedAt: number; pointCount: number; samples: number[]; rms: number }>();
|
||||||
private offlineAudioContextCtor: (new (channelCount: number, length: number, sampleRate: number) => any) | null = null;
|
private offlineAudioContextCtor: (new (channelCount: number, length: number, sampleRate: number) => any) | null = null;
|
||||||
|
private musicMetadataParseFile: MusicMetadataParser | null = null;
|
||||||
public constructor(
|
public constructor(
|
||||||
private readonly database: DatabaseService,
|
private readonly database: DatabaseService,
|
||||||
private readonly settings: SettingsService,
|
private readonly settings: SettingsService,
|
||||||
@@ -1342,6 +1352,29 @@ export class LibraryService {
|
|||||||
return value.replace(/\\/g, '/');
|
return value.replace(/\\/g, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves and caches the music-metadata parseFile implementation.
|
||||||
|
*/
|
||||||
|
private async resolveMusicMetadataParser(): Promise<MusicMetadataParser> {
|
||||||
|
if (this.musicMetadataParseFile) {
|
||||||
|
return this.musicMetadataParseFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
const namespace = (await import('music-metadata')) as MusicMetadataNamespace;
|
||||||
|
const candidate = typeof namespace.parseFile === 'function'
|
||||||
|
? namespace.parseFile
|
||||||
|
: namespace.default && typeof namespace.default.parseFile === 'function'
|
||||||
|
? namespace.default.parseFile
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (!candidate) {
|
||||||
|
throw new Error('music-metadata parseFile not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.musicMetadataParseFile = candidate;
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts metadata from the WAV container, falling back to defaults when parsing fails.
|
* Extracts metadata from the WAV container, falling back to defaults when parsing fails.
|
||||||
*/
|
*/
|
||||||
@@ -1353,22 +1386,8 @@ export class LibraryService {
|
|||||||
categories: string[];
|
categories: string[];
|
||||||
}> {
|
}> {
|
||||||
try {
|
try {
|
||||||
const mmImport = await import('music-metadata');
|
const parseFile = await this.resolveMusicMetadataParser();
|
||||||
const mm = (mmImport as { default?: unknown }).default ?? mmImport;
|
const metadata = await parseFile(filePath, { duration: true });
|
||||||
|
|
||||||
const loadMusicMetadata = typeof mm === 'object' && mm !== null && 'loadMusicMetadata' in mm
|
|
||||||
? (mm as { loadMusicMetadata: () => Promise<{ parseFile: (path: string, opts?: { duration?: boolean }) => Promise<{
|
|
||||||
format: { duration?: number | null; sampleRate?: number | null; bitsPerSample?: number | null };
|
|
||||||
common: { comment?: unknown[]; genre?: unknown[]; subtitle?: unknown };
|
|
||||||
}> }> }).loadMusicMetadata
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (!loadMusicMetadata) {
|
|
||||||
throw new Error('music-metadata loadMusicMetadata not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
const musicMetadata = await loadMusicMetadata();
|
|
||||||
const metadata = await musicMetadata.parseFile(filePath, { duration: true });
|
|
||||||
const infoTags = this.tagService.readInfoTags(filePath);
|
const infoTags = this.tagService.readInfoTags(filePath);
|
||||||
const splitInfoValues = (input: string | undefined): string[] =>
|
const splitInfoValues = (input: string | undefined): string[] =>
|
||||||
input
|
input
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import Fuse from 'fuse.js';
|
import Fuse, { type FuseResult, type IFuseOptions } from 'fuse.js';
|
||||||
import { AudioFileSummary } from '../../shared/models';
|
import { AudioFileSummary } from '../../shared/models';
|
||||||
import { DatabaseService } from './DatabaseService';
|
import { DatabaseService } from './DatabaseService';
|
||||||
import { TagService } from './TagService';
|
import { TagService } from './TagService';
|
||||||
@@ -76,7 +76,7 @@ export class SearchService {
|
|||||||
|
|
||||||
return fuseInstance
|
return fuseInstance
|
||||||
.search(remainingQuery)
|
.search(remainingQuery)
|
||||||
.map((result: Fuse.FuseResult<AudioFileSummary>) => result.item)
|
.map((result: FuseResult<AudioFileSummary>) => result.item)
|
||||||
.filter((file) => (filters.length === 0 ? true : this.matchesAdvancedFilters(file, filters)));
|
.filter((file) => (filters.length === 0 ? true : this.matchesAdvancedFilters(file, filters)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ export class SearchService {
|
|||||||
/**
|
/**
|
||||||
* Provides the standard Fuse configuration used by the service.
|
* Provides the standard Fuse configuration used by the service.
|
||||||
*/
|
*/
|
||||||
private createFuseOptions(): Fuse.IFuseOptions<AudioFileSummary> {
|
private createFuseOptions(): IFuseOptions<AudioFileSummary> {
|
||||||
return {
|
return {
|
||||||
includeScore: true,
|
includeScore: true,
|
||||||
threshold: 0.35,
|
threshold: 0.35,
|
||||||
@@ -114,7 +114,7 @@ export class SearchService {
|
|||||||
{ name: 'tags', weight: 0.2 },
|
{ name: 'tags', weight: 0.2 },
|
||||||
{ name: 'categories', weight: 0.1 }
|
{ name: 'categories', weight: 0.1 }
|
||||||
]
|
]
|
||||||
} satisfies Fuse.IFuseOptions<AudioFileSummary>;
|
} satisfies IFuseOptions<AudioFileSummary>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -163,8 +163,8 @@ export class TagService {
|
|||||||
.filter((entry) => entry.length > 0);
|
.filter((entry) => entry.length > 0);
|
||||||
|
|
||||||
const tagText = tagValuesList.length > 0 ? tagValuesList.join('; ') : null;
|
const tagText = tagValuesList.length > 0 ? tagValuesList.join('; ') : null;
|
||||||
const categoryText = categoryValuesList.length > 0 ? categoryValuesList.join('; ') : null;
|
const categoryText = categoryValuesList.length > 0 ? categoryValuesList.join('; ') : null;
|
||||||
const primaryCategory = categoryValuesList.at(0) ?? null;
|
const primaryCategory = categoryValuesList.length > 0 ? categoryValuesList[0] : null;
|
||||||
const trimmedTitle = metadata.title?.toString().trim();
|
const trimmedTitle = metadata.title?.toString().trim();
|
||||||
const effectiveTitle = trimmedTitle && trimmedTitle.length > 0 ? trimmedTitle : null;
|
const effectiveTitle = trimmedTitle && trimmedTitle.length > 0 ? trimmedTitle : null;
|
||||||
const trimmedAuthor = metadata.author?.toString().trim();
|
const trimmedAuthor = metadata.author?.toString().trim();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState, type JSX } from 'react';
|
||||||
import FileList from './components/FileList';
|
import FileList from './components/FileList';
|
||||||
import FileDetailPanel from './components/FileDetailPanel';
|
import FileDetailPanel from './components/FileDetailPanel';
|
||||||
import MultiFileEditor from './components/MultiFileEditor';
|
import MultiFileEditor from './components/MultiFileEditor';
|
||||||
@@ -274,8 +274,7 @@ function App(): JSX.Element {
|
|||||||
setActiveTab('listen');
|
setActiveTab('listen');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditModeSplitComplete = async (created: AudioFileSummary[]) => {
|
const handleEditModeSplitComplete = (created: AudioFileSummary[]) => {
|
||||||
await libraryStore.rescan();
|
|
||||||
setActiveTab('listen');
|
setActiveTab('listen');
|
||||||
if (created.length > 0) {
|
if (created.length > 0) {
|
||||||
libraryStore.selectFile(created[0].id);
|
libraryStore.selectFile(created[0].id);
|
||||||
@@ -294,6 +293,7 @@ function App(): JSX.Element {
|
|||||||
categories={library.categories}
|
categories={library.categories}
|
||||||
files={library.files}
|
files={library.files}
|
||||||
activeFilter={library.categoryFilter}
|
activeFilter={library.categoryFilter}
|
||||||
|
justSplitIds={library.justSplitFileIds}
|
||||||
onSelect={handleCategorySelect}
|
onSelect={handleCategorySelect}
|
||||||
onDropFiles={handleDropFilesToCategory}
|
onDropFiles={handleDropFilesToCategory}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import type { AudioFileSummary, CategoryRecord } from '../../../shared/models';
|
import type { AudioFileSummary, CategoryRecord } from '../../../shared/models';
|
||||||
import { CATEGORY_FILTER_UNTAGGED, type CategoryFilterValue } from '../stores/LibraryStore';
|
import { CATEGORY_FILTER_JUST_SPLIT, CATEGORY_FILTER_UNTAGGED, type CategoryFilterValue } from '../stores/LibraryStore';
|
||||||
import {
|
import {
|
||||||
buildCategorySwatch,
|
buildCategorySwatch,
|
||||||
createCategoryStyleVars,
|
createCategoryStyleVars,
|
||||||
@@ -11,6 +11,8 @@ export interface CategorySidebarProps {
|
|||||||
categories: CategoryRecord[];
|
categories: CategoryRecord[];
|
||||||
files: AudioFileSummary[];
|
files: AudioFileSummary[];
|
||||||
activeFilter: CategoryFilterValue;
|
activeFilter: CategoryFilterValue;
|
||||||
|
/** Identifiers of files created during the most recent split action. */
|
||||||
|
justSplitIds: number[];
|
||||||
onSelect(filter: CategoryFilterValue): void;
|
onSelect(filter: CategoryFilterValue): void;
|
||||||
onDropFiles?(fileIds: number[], categoryId: string): void;
|
onDropFiles?(fileIds: number[], categoryId: string): void;
|
||||||
}
|
}
|
||||||
@@ -37,7 +39,7 @@ function deriveCounts(files: AudioFileSummary[]): {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CategorySidebar({ categories, files, activeFilter, onSelect, onDropFiles }: CategorySidebarProps): JSX.Element {
|
export function CategorySidebar({ categories, files, activeFilter, justSplitIds, onSelect, onDropFiles }: CategorySidebarProps): JSX.Element {
|
||||||
const { total, untagged, categoryCounts } = deriveCounts(files);
|
const { total, untagged, categoryCounts } = deriveCounts(files);
|
||||||
const swatchMap = useMemo(() => {
|
const swatchMap = useMemo(() => {
|
||||||
const map = new Map<string, ReturnType<typeof buildCategorySwatch>>();
|
const map = new Map<string, ReturnType<typeof buildCategorySwatch>>();
|
||||||
@@ -103,6 +105,17 @@ export function CategorySidebar({ categories, files, activeFilter, onSelect, onD
|
|||||||
<span className="category-sidebar__label">TO TAG</span>
|
<span className="category-sidebar__label">TO TAG</span>
|
||||||
<span className="category-sidebar__count">{untagged}</span>
|
<span className="category-sidebar__count">{untagged}</span>
|
||||||
</button>
|
</button>
|
||||||
|
{justSplitIds.length > 0 ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="category-sidebar__item"
|
||||||
|
data-active={activeFilter === CATEGORY_FILTER_JUST_SPLIT}
|
||||||
|
onClick={() => handleSelect(CATEGORY_FILTER_JUST_SPLIT)}
|
||||||
|
>
|
||||||
|
<span className="category-sidebar__label">JUST SPLIT</span>
|
||||||
|
<span className="category-sidebar__count">{justSplitIds.length}</span>
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
{sortedGroups.map(([groupName, records]) => {
|
{sortedGroups.map(([groupName, records]) => {
|
||||||
const sortedRecords = records
|
const sortedRecords = records
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import type {
|
|||||||
type ChangeListener = () => void;
|
type ChangeListener = () => void;
|
||||||
|
|
||||||
export const CATEGORY_FILTER_UNTAGGED = 'untagged' as const;
|
export const CATEGORY_FILTER_UNTAGGED = 'untagged' as const;
|
||||||
export type CategoryFilterValue = string | typeof CATEGORY_FILTER_UNTAGGED | null;
|
/** Filter key that exposes files generated by the most recent split action. */
|
||||||
|
export const CATEGORY_FILTER_JUST_SPLIT = 'just-split' as const;
|
||||||
|
export type CategoryFilterValue = string | typeof CATEGORY_FILTER_UNTAGGED | typeof CATEGORY_FILTER_JUST_SPLIT | null;
|
||||||
|
|
||||||
export interface LibrarySnapshot {
|
export interface LibrarySnapshot {
|
||||||
initialized: boolean;
|
initialized: boolean;
|
||||||
@@ -25,6 +27,8 @@ export interface LibrarySnapshot {
|
|||||||
categoryFilter: CategoryFilterValue;
|
categoryFilter: CategoryFilterValue;
|
||||||
lastScan: LibraryScanSummary | null;
|
lastScan: LibraryScanSummary | null;
|
||||||
metadataSuggestionsVersion: number;
|
metadataSuggestionsVersion: number;
|
||||||
|
/** Files created by the most recent split action during this app session. */
|
||||||
|
justSplitFileIds: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,7 +47,8 @@ export class LibraryStore extends EventTarget {
|
|||||||
searchQuery: '',
|
searchQuery: '',
|
||||||
categoryFilter: null,
|
categoryFilter: null,
|
||||||
lastScan: null,
|
lastScan: null,
|
||||||
metadataSuggestionsVersion: 0
|
metadataSuggestionsVersion: 0,
|
||||||
|
justSplitFileIds: []
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,7 +75,8 @@ export class LibraryStore extends EventTarget {
|
|||||||
searchQuery: '',
|
searchQuery: '',
|
||||||
categoryFilter: null,
|
categoryFilter: null,
|
||||||
lastScan: null,
|
lastScan: null,
|
||||||
metadataSuggestionsVersion: nextVersion
|
metadataSuggestionsVersion: nextVersion,
|
||||||
|
justSplitFileIds: []
|
||||||
};
|
};
|
||||||
this.refreshVisibleFiles(this.snapshot.selectedFileId ?? null);
|
this.refreshVisibleFiles(this.snapshot.selectedFileId ?? null);
|
||||||
}
|
}
|
||||||
@@ -263,7 +269,10 @@ export class LibraryStore extends EventTarget {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let visible: AudioFileSummary[];
|
let visible: AudioFileSummary[];
|
||||||
if (filter === CATEGORY_FILTER_UNTAGGED) {
|
if (filter === CATEGORY_FILTER_JUST_SPLIT) {
|
||||||
|
const justSplitIds = new Set(this.snapshot.justSplitFileIds);
|
||||||
|
visible = files.filter((file) => justSplitIds.has(file.id));
|
||||||
|
} else if (filter === CATEGORY_FILTER_UNTAGGED) {
|
||||||
visible = files.filter((file) => file.categories.length === 0);
|
visible = files.filter((file) => file.categories.length === 0);
|
||||||
} else if (filter) {
|
} else if (filter) {
|
||||||
visible = files.filter((file) => file.categories.includes(filter));
|
visible = files.filter((file) => file.categories.includes(filter));
|
||||||
@@ -275,7 +284,8 @@ export class LibraryStore extends EventTarget {
|
|||||||
...this.snapshot,
|
...this.snapshot,
|
||||||
visibleFiles: visible,
|
visibleFiles: visible,
|
||||||
selectedFileId,
|
selectedFileId,
|
||||||
focusedFile
|
focusedFile,
|
||||||
|
justSplitFileIds: this.snapshot.justSplitFileIds
|
||||||
};
|
};
|
||||||
this.emitChange();
|
this.emitChange();
|
||||||
}
|
}
|
||||||
@@ -398,21 +408,29 @@ export class LibraryStore extends EventTarget {
|
|||||||
public async splitFile(fileId: number, segments: SplitSegmentRequest[]): Promise<AudioFileSummary[]> {
|
public async splitFile(fileId: number, segments: SplitSegmentRequest[]): Promise<AudioFileSummary[]> {
|
||||||
const created = await window.api.splitFile(fileId, segments);
|
const created = await window.api.splitFile(fileId, segments);
|
||||||
const files = await window.api.listAudioFiles();
|
const files = await window.api.listAudioFiles();
|
||||||
const { categoryFilter } = this.snapshot;
|
const createdIds = created.map((record) => record.id);
|
||||||
let visible: AudioFileSummary[];
|
const fileLookup = new Map(files.map((record) => [record.id, record] as const));
|
||||||
if (categoryFilter === CATEGORY_FILTER_UNTAGGED) {
|
// Prefer fresh copies from the library list so downstream consumers see current metadata.
|
||||||
visible = files.filter((file) => file.categories.length === 0);
|
const justSplitRecords: AudioFileSummary[] = createdIds
|
||||||
} else if (categoryFilter) {
|
.map((id) => fileLookup.get(id) ?? created.find((record) => record.id === id) ?? null)
|
||||||
visible = files.filter((file) => file.categories.includes(categoryFilter));
|
.filter((record): record is AudioFileSummary => record !== null);
|
||||||
} else {
|
|
||||||
visible = files.slice();
|
const primaryId = justSplitRecords.at(0)?.id ?? null;
|
||||||
|
const nextSelection = new Set<number>(justSplitRecords.map((record) => record.id));
|
||||||
|
if (primaryId !== null) {
|
||||||
|
nextSelection.add(primaryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.snapshot = {
|
this.snapshot = {
|
||||||
...this.snapshot,
|
...this.snapshot,
|
||||||
files,
|
files,
|
||||||
visibleFiles: visible,
|
visibleFiles: justSplitRecords,
|
||||||
metadataSuggestionsVersion: this.snapshot.metadataSuggestionsVersion + 1
|
metadataSuggestionsVersion: this.snapshot.metadataSuggestionsVersion + 1,
|
||||||
|
categoryFilter: CATEGORY_FILTER_JUST_SPLIT,
|
||||||
|
justSplitFileIds: justSplitRecords.map((record) => record.id),
|
||||||
|
selectedFileId: primaryId,
|
||||||
|
selectedFileIds: nextSelection,
|
||||||
|
focusedFile: primaryId !== null ? fileLookup.get(primaryId) ?? justSplitRecords.at(0) ?? null : null
|
||||||
};
|
};
|
||||||
this.emitChange();
|
this.emitChange();
|
||||||
return created;
|
return created;
|
||||||
@@ -462,8 +480,13 @@ export class LibraryStore extends EventTarget {
|
|||||||
|
|
||||||
private refreshVisibleFiles(preferredId?: number | null, emit = true): void {
|
private refreshVisibleFiles(preferredId?: number | null, emit = true): void {
|
||||||
const { files, categoryFilter } = this.snapshot;
|
const { files, categoryFilter } = this.snapshot;
|
||||||
|
const availableIds = new Set(files.map((file) => file.id));
|
||||||
|
const justSplitIds = this.snapshot.justSplitFileIds.filter((id) => availableIds.has(id));
|
||||||
let visible: AudioFileSummary[];
|
let visible: AudioFileSummary[];
|
||||||
if (categoryFilter === CATEGORY_FILTER_UNTAGGED) {
|
if (categoryFilter === CATEGORY_FILTER_JUST_SPLIT) {
|
||||||
|
const justSplitSet = new Set(justSplitIds);
|
||||||
|
visible = files.filter((file) => justSplitSet.has(file.id));
|
||||||
|
} else if (categoryFilter === CATEGORY_FILTER_UNTAGGED) {
|
||||||
visible = files.filter((file) => file.categories.length === 0);
|
visible = files.filter((file) => file.categories.length === 0);
|
||||||
} else if (categoryFilter) {
|
} else if (categoryFilter) {
|
||||||
visible = files.filter((file) => file.categories.includes(categoryFilter));
|
visible = files.filter((file) => file.categories.includes(categoryFilter));
|
||||||
@@ -500,7 +523,8 @@ export class LibraryStore extends EventTarget {
|
|||||||
visibleFiles: visible,
|
visibleFiles: visible,
|
||||||
selectedFileId: nextSelected,
|
selectedFileId: nextSelected,
|
||||||
selectedFileIds: nextSelectionSet,
|
selectedFileIds: nextSelectionSet,
|
||||||
focusedFile: nextFocused
|
focusedFile: nextFocused,
|
||||||
|
justSplitFileIds: justSplitIds
|
||||||
};
|
};
|
||||||
|
|
||||||
if (emit) {
|
if (emit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user