refactor: Standardize document and folder identification with a new entryKey module.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useCallback } from 'react';
|
||||
import { createDocumentEntryKey, createFolderEntryKey } from '../app/entryKey';
|
||||
|
||||
export type PointerEventLike = MouseEvent | PointerEvent;
|
||||
|
||||
@@ -26,8 +27,6 @@ export interface WorkspaceEntry {
|
||||
}
|
||||
|
||||
interface UseEntryPointerOptions {
|
||||
resolveDocumentRowKey?: (id: string | number) => string | null;
|
||||
resolveFolderRowKey?: (id: string | number) => string | null;
|
||||
onSelectEntry?: (entry: WorkspaceEntry, event?: PointerEventLike | null, metadata?: EntryPointerMetadata) => void;
|
||||
onDocumentActivate?: (id: string | number, metadata?: EntryPointerMetadata) => void;
|
||||
}
|
||||
@@ -41,8 +40,6 @@ export interface EntryPointerMetadata {
|
||||
}
|
||||
|
||||
export const useEntryPointer = ({
|
||||
resolveDocumentRowKey,
|
||||
resolveFolderRowKey,
|
||||
onSelectEntry,
|
||||
onDocumentActivate,
|
||||
}: UseEntryPointerOptions) =>
|
||||
@@ -58,7 +55,7 @@ export const useEntryPointer = ({
|
||||
}
|
||||
|
||||
const rowKey = entry.key
|
||||
|| (type === 'document' ? resolveDocumentRowKey?.(id) : resolveFolderRowKey?.(id));
|
||||
|| (type === 'document' ? createDocumentEntryKey(id) : createFolderEntryKey(id));
|
||||
if (!rowKey) {
|
||||
return;
|
||||
}
|
||||
@@ -73,7 +70,7 @@ export const useEntryPointer = ({
|
||||
onDocumentActivate?.(id, metadata);
|
||||
}
|
||||
},
|
||||
[resolveDocumentRowKey, resolveFolderRowKey, onSelectEntry, onDocumentActivate],
|
||||
[onSelectEntry, onDocumentActivate],
|
||||
);
|
||||
|
||||
export default useEntryPointer;
|
||||
|
||||
Reference in New Issue
Block a user