refactor: Consolidate workspace utilities into new workspaceUtils.ts with typed entry keys, replacing appLayoutUtils.ts, and update related components.
This commit is contained in:
@@ -6,13 +6,11 @@ import type {
|
||||
DocumentLike as OcrDocumentLike,
|
||||
} from '../utils/ocr';
|
||||
|
||||
type ResolveApiPath = (path: string) => string;
|
||||
|
||||
export type DocumentLike = OcrDocumentLike;
|
||||
|
||||
const asyncFalse = async () => false;
|
||||
|
||||
const resolveDocumentDownloadHref = (document?: DocumentLike | null, resolveApiPath?: ResolveApiPath | null): string | null => {
|
||||
const resolveDocumentDownloadHref = (document?: DocumentLike | null): string | null => {
|
||||
if (!document) {
|
||||
return null;
|
||||
}
|
||||
@@ -20,7 +18,7 @@ const resolveDocumentDownloadHref = (document?: DocumentLike | null, resolveApiP
|
||||
if (!downloadUrl) {
|
||||
return null;
|
||||
}
|
||||
return resolveApiPath ? resolveApiPath(downloadUrl) : downloadUrl;
|
||||
return downloadUrl;
|
||||
};
|
||||
|
||||
const hasDocumentOcrAsset = (document?: DocumentLike | null, getDocumentAsset?: GetDocumentAsset | null): boolean => {
|
||||
@@ -32,7 +30,6 @@ const hasDocumentOcrAsset = (document?: DocumentLike | null, getDocumentAsset?:
|
||||
|
||||
interface CreateDocumentActionStateArgs {
|
||||
document: DocumentLike | null;
|
||||
resolveApiPath?: ResolveApiPath | null;
|
||||
ensurePreviewData: EnsurePreviewData;
|
||||
ensureAssetUrl: EnsureAssetUrl;
|
||||
getDocumentAsset?: GetDocumentAsset | null;
|
||||
@@ -42,7 +39,6 @@ interface CreateDocumentActionStateArgs {
|
||||
|
||||
export const createDocumentActionState = ({
|
||||
document,
|
||||
resolveApiPath,
|
||||
ensurePreviewData,
|
||||
ensureAssetUrl,
|
||||
getDocumentAsset,
|
||||
@@ -57,27 +53,27 @@ export const createDocumentActionState = ({
|
||||
};
|
||||
}
|
||||
|
||||
const downloadHref = resolveDocumentDownloadHref(document, resolveApiPath);
|
||||
const downloadHref = resolveDocumentDownloadHref(document);
|
||||
const hasOcr = hasDocumentOcrAsset(document, getDocumentAsset);
|
||||
|
||||
const openOcr = hasOcr
|
||||
? async () => {
|
||||
try {
|
||||
const success = await openOcrTextInNewTab({
|
||||
document,
|
||||
ensurePreviewData,
|
||||
getDocumentAsset,
|
||||
ensureAssetUrl,
|
||||
});
|
||||
if (!success) {
|
||||
notifyApiError?.(new Error('OCR text URL unavailable.'), ocrErrorMessage);
|
||||
}
|
||||
return success;
|
||||
} catch (error) {
|
||||
notifyApiError?.(error, ocrErrorMessage);
|
||||
throw error;
|
||||
try {
|
||||
const success = await openOcrTextInNewTab({
|
||||
document,
|
||||
ensurePreviewData,
|
||||
getDocumentAsset,
|
||||
ensureAssetUrl,
|
||||
});
|
||||
if (!success) {
|
||||
notifyApiError?.(new Error('OCR text URL unavailable.'), ocrErrorMessage);
|
||||
}
|
||||
return success;
|
||||
} catch (error) {
|
||||
notifyApiError?.(error, ocrErrorMessage);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
: asyncFalse;
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { formatFileSize } from '../utils/format';
|
||||
import { formatDateTime as defaultFormatDateTime } from '../utils/date';
|
||||
import { DEFAULT_FOLDER_NAME } from '../app/appLayoutUtils';
|
||||
import { DEFAULT_FOLDER_NAME } from '../app/workspaceUtils';
|
||||
|
||||
interface DocumentPageMetadata {
|
||||
page_count?: number | string | null;
|
||||
|
||||
Reference in New Issue
Block a user