refactor: extract various constants

This commit is contained in:
2025-11-25 10:10:42 +01:00
parent 4d30e47ee8
commit ccc22beda2
40 changed files with 326 additions and 216 deletions
@@ -1,6 +1,5 @@
import React from 'react';
const NBSP = String.fromCharCode(160);
import { NBSP } from '../constants/ui';
export interface CorrespondentLinkEntry {
id?: string | null;
@@ -5,6 +5,7 @@ import {
resolveDocumentAssetUrl,
resolveAssetUrl,
} from '../asset_manager';
import { DEFAULT_THUMBNAIL_SIZE } from '../constants/documents';
import type {
DocumentLike as AssetManagerDocumentLike,
AssetLike as AssetManagerAssetLike,
@@ -12,8 +13,6 @@ import type {
GetAsset as AssetManagerGetAsset,
} from '../asset_manager';
const DEFAULT_THUMBNAIL_SIZE = 48;
// Detect when an element becomes visible within a scroll container so we can delay loading.
const useLazyVisibility = (
rootRef: MutableRefObject<Element | null> | null,
@@ -12,10 +12,9 @@ import SelectionAssignmentMenu, { SelectionAssignmentMenuItem } from './Selectio
import SelectionSummary from './SelectionSummary';
import { useAppState } from '../app/appState';
import { useWorkspaceSelectionContext } from '../app/WorkspaceSelectionContext';
import { DEFAULT_FOLDER_NAME } from '../constants/workspace';
import type { DocumentId } from '../types/identifiers';
const ROOT_FOLDER_LABEL = 'Documents';
type NullableDocumentId = DocumentId | null;
type SelectedIdList = NullableDocumentId[] | null;
@@ -128,11 +127,11 @@ const buildFolderTreeOptions = (tree?: FolderTreeNode[] | null): SelectionAssign
});
};
traverse(Array.isArray(tree) ? tree : [], [ROOT_FOLDER_LABEL]);
traverse(Array.isArray(tree) ? tree : [], [DEFAULT_FOLDER_NAME]);
entries.sort((a, b) => (a.label || '').localeCompare(b.label || '', undefined, { sensitivity: 'base' }));
return [{ id: 'root', label: ROOT_FOLDER_LABEL, state: 'none', payload: { id: 'root' } }, ...entries];
return [{ id: 'root', label: DEFAULT_FOLDER_NAME, state: 'none', payload: { id: 'root' } }, ...entries];
};
const buildTagAssignments = (
@@ -18,10 +18,9 @@ import DocumentsPanelHeader, {
import { SelectionFloatingPanel } from '../SelectionFloatingActions';
import { createDocumentsTableHeaderActions } from './DocumentsToolbar';
import { useDocumentsFilter } from '../context/DocumentsFilterContext';
import { DEFAULT_GRID_ICON_SIZE } from '../../constants/documents';
import type { Identifier } from '../../types/identifiers';
const DEFAULT_GRID_ICON_SIZE = 144;
const EntryType = {
folder: 'folder',
document: 'document',
@@ -1,19 +1,7 @@
import React, { useCallback, useMemo } from 'react';
import { SORT_LABEL_LOOKUP, SORT_OPTIONS } from '../../constants/documents';
import QuickAddMenu from '../../ui/QuickAddMenu';
const SORT_OPTIONS = [
{ value: 'title', label: 'Title' },
{ value: 'issued_at', label: 'Issued date' },
{ value: 'created_at', label: 'Added' },
{ value: 'updated_at', label: 'Updated date' },
];
const SORT_LABEL_LOOKUP = SORT_OPTIONS.reduce((acc, option) => {
const next = acc;
next[option.value] = option.label;
return next;
}, {});
interface SortFieldQuickMenuProps {
sortField: string;
onChange?: (value: string) => void;
+1 -3
View File
@@ -1,7 +1,5 @@
import type { DocumentId, TagId } from '../types/identifiers';
const TAG_MIME_TYPES = ['application/x-papercrate-tag', 'text/papercrate-tag'];
const TAG_TEXT_MIME_TYPE = 'text/plain';
import { TAG_MIME_TYPES, TAG_TEXT_MIME_TYPE } from '../constants/documents';
interface TagPayload {
id: TagId;