This commit is contained in:
2025-11-15 04:11:22 +01:00
parent bd3eab8b40
commit d0379c57ce
47 changed files with 558 additions and 703 deletions
@@ -28,7 +28,7 @@ interface UseAuthManagerArgs {
}
interface UseAuthManagerResult {
tokenRef: MutableRefObject<string | null | undefined>;
tokenRef: MutableRefObject<string | null>;
refreshAccessToken: () => Promise<string>;
handleLogout: () => Promise<void>;
}
@@ -57,7 +57,7 @@ const useAuthManager = ({
setStatusMessage,
setLoading,
}: UseAuthManagerArgs): UseAuthManagerResult => {
const tokenRef = useRef<string | null | undefined>(token);
const tokenRef = useRef<string | null>(token);
const refreshPromiseRef = useRef<Promise<string> | null>(null);
const initialRefreshAttemptedRef = useRef(Boolean(token));
@@ -47,8 +47,8 @@ const useCorrespondents = ({
}, [apiClient, notifyApiError, tenantIdRef]);
const handleCorrespondentUpdate = useCallback(
async (correspondentId: string | number | null | undefined, changes: { name?: string }) => {
if (!correspondentId) {
async (correspondentId: string | number, changes: { name?: string }) => {
if (correspondentId == null) {
throw new Error('Missing correspondent identifier.');
}
@@ -100,8 +100,8 @@ const useCorrespondents = ({
);
const handleCorrespondentDelete = useCallback(
async (correspondentId: string | number | null | undefined) => {
if (!correspondentId) {
async (correspondentId: string | number) => {
if (correspondentId == null) {
throw new Error('Missing correspondent identifier.');
}
@@ -12,10 +12,12 @@ interface CorrespondentOption {
[key: string]: unknown;
}
type Identifier = string | number;
interface UseDocumentCorrespondentActionsArgs {
apiClient: ApiClient;
correspondents: CorrespondentOption[];
handleCorrespondentCreate: (payload: { name: string }) => Promise<CorrespondentOption | null | undefined>;
handleCorrespondentCreate: (payload: { name: string }) => Promise<CorrespondentOption | null>;
refreshCurrentFolder: () => Promise<void>;
notifyApiError: (error: unknown, fallback: string) => void;
setStatusMessage: (message: string, variant?: string) => void;
@@ -41,10 +43,10 @@ const useDocumentCorrespondentActions = ({
const handleDocumentCorrespondentAttach = useCallback(
async (
{ documentId, correspondentId }: { documentId?: string | number | null; correspondentId?: string | number | null },
{ documentId, correspondentId }: { documentId: Identifier; correspondentId: Identifier },
{ notify = true, refresh = true }: { notify?: boolean; refresh?: boolean } = {},
) => {
if (!documentId || !correspondentId) {
if (documentId == null || correspondentId == null) {
throw new Error('Missing document or correspondent.');
}
try {
@@ -70,10 +72,10 @@ const useDocumentCorrespondentActions = ({
const handleCorrespondentRemove = useCallback(
async (
{ documentId, correspondentId }: { documentId?: string | number | null; correspondentId?: string | number | null },
{ documentId, correspondentId }: { documentId: Identifier; correspondentId: Identifier },
{ notify = true, refresh = true }: { notify?: boolean; refresh?: boolean } = {},
) => {
if (!documentId || !correspondentId) {
if (documentId == null || correspondentId == null) {
throw new Error('Missing document or correspondent.');
}
try {
@@ -30,8 +30,8 @@ interface UseDocumentDragHandlersOptions {
documentLookup: Map<Identifier, DocumentLike>;
setDraggedDocumentIds: (ids: Identifier[] | []) => void;
setDraggedFolderId: (id: FolderIdentifier | null) => void;
resolveDocumentRowKey: (id: Identifier) => string | null | undefined;
resolveFolderRowKey: (id: FolderIdentifier) => string | null | undefined;
resolveDocumentRowKey: (id: Identifier) => string | null;
resolveFolderRowKey: (id: FolderIdentifier) => string | null;
documentsViewMode: string;
}
@@ -211,7 +211,7 @@ const useDocumentDragHandlers = ({
);
const handleDocumentDragStart = useCallback(
(event: DragEvent<HTMLElement>, documentOrId: DocumentLike | Identifier | null | undefined) => {
(event: DragEvent<HTMLElement>, documentOrId: DocumentLike | Identifier | null) => {
const documentId: Identifier | null = Object(documentOrId) === documentOrId
? (documentOrId as DocumentLike)?.id ?? null
: (documentOrId as Identifier | null);
@@ -10,8 +10,8 @@ type NullableFolderId = FolderId | null;
type StatusLevel = 'success' | 'error' | 'info' | string;
type DocumentCacheMapper = (
doc: DocumentLike | null | undefined,
) => DocumentLike | null | undefined;
doc: DocumentLike | null,
) => DocumentLike | null;
type MapDocumentCaches = (mapper: DocumentCacheMapper) => void;
@@ -140,7 +140,7 @@ interface UseDocumentMutationsArgs {
tags: Tag[];
refreshTags: () => Promise<void>;
tagManager: TagManager;
extractDocumentFromResponse?: (payload: unknown) => DocumentLike | null | undefined;
extractDocumentFromResponse?: (payload: unknown) => DocumentLike | null;
}
interface UseDocumentMutationsResult {
+1 -1
View File
@@ -11,7 +11,7 @@ interface FolderContentsEntry {
}
interface UseDocumentsOptions {
setSearchResults: Dispatch<SetStateAction<DocumentLike[] | null | undefined>>;
setSearchResults: Dispatch<SetStateAction<DocumentLike[] | null>>;
setFolderContents: Dispatch<SetStateAction<Map<string, FolderContentsEntry>>>;
}
@@ -757,13 +757,12 @@ const useDocumentsWorkspace = ({
const removeDocumentsFromCaches = useCallback(
(documentIds: DocumentId[] | null | undefined) => {
const safeIds = Array.isArray(documentIds) ? documentIds : [];
if (!safeIds.length) {
(documentIds: DocumentId[]) => {
if (!documentIds.length) {
return;
}
const idSet = new Set<DocumentId>(safeIds);
const idSet = new Set<DocumentId>(documentIds);
setDocuments((prev) => prev.filter((doc) => !idSet.has(doc.id)));
setSearchResults((prev) => {
@@ -1275,7 +1274,7 @@ const useDocumentsWorkspace = ({
});
const inspectDocumentForDesk = useCallback(
(docOrId: DocumentLike | Identifier | null | undefined) => {
(docOrId?: DocumentLike | Identifier | null) => {
if (docOrId == null) {
return;
}
@@ -112,7 +112,7 @@ const useFolderTreeActions = ({
setCreatingFolder,
}: UseFolderTreeActionsOptions) => {
const moveFolder = useCallback(
async (folderId: FolderKey, targetFolderId: FolderKey | null | undefined) => {
async (folderId: FolderKey, targetFolderId: FolderKey | null) => {
const node = folderNodes.get(folderId);
if (!node) {
setStatusMessage('Folder metadata unavailable. Try refreshing.', 'error');
@@ -214,7 +214,7 @@ const useFolderTreeActions = ({
);
const loadFolder = useCallback(
async (folderId: FolderKey | null | undefined, { showLoading = true, preserveSearch = false }: LoadFolderOptions = {}) => {
async (folderId: FolderKey | null, { showLoading = true, preserveSearch = false }: LoadFolderOptions = {}) => {
const targetId = folderId || 'root';
setSelectedFolder(targetId);
await ensureFolderAncestorsLoaded(targetId);
@@ -256,7 +256,7 @@ const useFolderTreeActions = ({
);
const selectFolder = useCallback(
async (folderId: FolderKey | null | undefined, { replace = false, immediate = false }: SelectFolderOptions = {}) => {
async (folderId: FolderKey | null, { replace = false, immediate = false }: SelectFolderOptions = {}) => {
const targetId = folderId && folderId !== 'root' ? folderId : 'root';
await ensureFolderAncestorsLoaded(targetId);
+4 -4
View File
@@ -56,8 +56,8 @@ const useTags = ({
}, [apiClient, notifyApiError, tenantIdRef]);
const handleTagUpdate = useCallback(
async (tagId: string | number | null | undefined, changes: { label?: string; color?: string | null }) => {
if (!tagId) {
async (tagId: string | number, changes: { label?: string; color?: string | null }) => {
if (tagId == null) {
throw new Error('Missing tag identifier.');
}
@@ -104,8 +104,8 @@ const useTags = ({
);
const handleTagDelete = useCallback(
async (tagId: string | number | null | undefined) => {
if (!tagId) {
async (tagId: string | number) => {
if (tagId == null) {
throw new Error('Missing tag identifier.');
}
+3 -3
View File
@@ -30,7 +30,7 @@ type EnsureAssetUrl = (
options?: { start?: number; limit?: number; [key: string]: unknown },
) => Promise<unknown>;
type GetAsset = (document: DocumentLike, assetType: string) => AssetLike | null | undefined;
type GetAsset = (document: DocumentLike, assetType: string) => AssetLike | null;
interface AssetViewLike {
getCardinality: () => number;
@@ -41,7 +41,7 @@ interface AssetViewLike {
}
interface UseAssetNavigatorOptions {
document: DocumentLike | null | undefined;
document?: DocumentLike | null;
assetType: string;
ensureAssetUrl?: EnsureAssetUrl;
getAsset?: GetAsset;
@@ -50,7 +50,7 @@ interface UseAssetNavigatorOptions {
}
interface AssetNavigatorReturn {
document: DocumentLike | null | undefined;
document: DocumentLike | null;
documentId: Identifier | null;
asset: AssetLike | null;
assetType: string;