apiclient
This commit is contained in:
@@ -57,7 +57,7 @@ const SettingsRoute: React.FC<SettingsRouteProps> = ({ open = true, onClose }) =
|
||||
capabilities,
|
||||
capabilitiesLoading,
|
||||
refreshCapabilities,
|
||||
} = useCapabilities({ api, notifyApiError, token });
|
||||
} = useCapabilities({ notifyApiError, token });
|
||||
|
||||
useEffect(() => {
|
||||
refreshTokens();
|
||||
|
||||
@@ -4,6 +4,7 @@ import type {
|
||||
MutableRefObject,
|
||||
SetStateAction,
|
||||
} from 'react';
|
||||
import { fetchDocument } from '../lib/apiClient';
|
||||
|
||||
type DocumentId = string | number;
|
||||
type FolderId = DocumentId | 'root';
|
||||
@@ -23,10 +24,6 @@ type DocumentLink = {
|
||||
expiresAt?: number;
|
||||
};
|
||||
|
||||
interface ApiClient {
|
||||
get: <T = unknown>(path: string) => Promise<{ data: T }>;
|
||||
}
|
||||
|
||||
type NavigateHandler = (path: string, options?: { replace?: boolean }) => void;
|
||||
|
||||
interface UseDocumentPreviewArgs {
|
||||
@@ -39,7 +36,6 @@ interface UseDocumentPreviewArgs {
|
||||
ingest: (docs: unknown[]) => { canonical: DocumentLike[]; changed: boolean };
|
||||
};
|
||||
selectedFolder?: FolderId | null;
|
||||
api: ApiClient;
|
||||
notifyApiError: (error: unknown, message: string) => void;
|
||||
navigate: NavigateHandler;
|
||||
locationPathname: string;
|
||||
@@ -65,7 +61,6 @@ const useDocumentPreview = ({
|
||||
routeDocumentId,
|
||||
documentsManager,
|
||||
selectedFolder,
|
||||
api,
|
||||
notifyApiError,
|
||||
navigate,
|
||||
locationPathname,
|
||||
@@ -120,8 +115,8 @@ const useDocumentPreview = ({
|
||||
|
||||
const request: Promise<DocumentLink | null> = (async () => {
|
||||
try {
|
||||
const docResponse = await api.get<{ document?: Record<string, any> }>(`/documents/${documentId}`);
|
||||
const download = docResponse.data?.document?.current_version?.download || null;
|
||||
const docResponse = await fetchDocument(documentId);
|
||||
const download = docResponse?.current_version?.download || null;
|
||||
const downloadUrl = download?.url;
|
||||
if (!downloadUrl) {
|
||||
throw new Error('Document missing download url');
|
||||
@@ -129,8 +124,8 @@ const useDocumentPreview = ({
|
||||
|
||||
const entry: DocumentLink = {
|
||||
url: downloadUrl,
|
||||
contentType: docResponse.data?.document?.current_version?.version?.content_type || null,
|
||||
filename: docResponse.data?.document?.filename,
|
||||
contentType: docResponse?.content_type || null,
|
||||
filename: docResponse?.filename,
|
||||
expiresAt: download?.expires_at,
|
||||
};
|
||||
setDocumentLinks((prev) => {
|
||||
@@ -150,7 +145,7 @@ const useDocumentPreview = ({
|
||||
previewInflightRef.current.set(documentId, request);
|
||||
return request;
|
||||
},
|
||||
[documentLinks, api, notifyApiError],
|
||||
[documentLinks, notifyApiError],
|
||||
);
|
||||
|
||||
const ensurePreviewData = useCallback(
|
||||
@@ -166,8 +161,7 @@ const useDocumentPreview = ({
|
||||
}
|
||||
|
||||
if (!doc) {
|
||||
const { data } = await api.get(`/documents/${documentId}`);
|
||||
const fetched = (data as { document?: DocumentLike })?.document || data;
|
||||
const fetched = await fetchDocument(documentId);
|
||||
const { canonical } = documentsManager.ingest([fetched as unknown]);
|
||||
doc = (canonical[0] as DocumentLike | undefined) || null;
|
||||
if (!doc) {
|
||||
@@ -189,7 +183,6 @@ const useDocumentPreview = ({
|
||||
documentsManager,
|
||||
ensureDownloadUrl,
|
||||
setActivePreviewId,
|
||||
api,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import type { Dispatch, SetStateAction } from 'react';
|
||||
import { TAG_FILTER_UNTAGGED } from './appLayoutUtils';
|
||||
import { listDocuments } from '../lib/apiClient';
|
||||
|
||||
type Identifier = string | number;
|
||||
|
||||
@@ -227,7 +228,7 @@ const useDocumentsSearch = ({
|
||||
if (documentsSortDirection) {
|
||||
params.dir = documentsSortDirection;
|
||||
}
|
||||
const { data } = await api.get<unknown[]>('/documents', { params });
|
||||
const data = await listDocuments(params);
|
||||
if (cancelled) return;
|
||||
|
||||
const results = Array.isArray(data) ? data : [];
|
||||
|
||||
Reference in New Issue
Block a user