forked from VinokurovVE/tests
docx, xlsx, pdf viewers, dropzone for uploading, cleanup
This commit is contained in:
@ -2,6 +2,7 @@ import useSWR from "swr";
|
||||
import RoleService from "../services/RoleService";
|
||||
import UserService from "../services/UserService";
|
||||
import { blobFetcher, fetcher } from "../http/axiosInstance";
|
||||
import { fileTypeFromBlob } from "file-type/core";
|
||||
|
||||
export function useRoles() {
|
||||
const { data, error, isLoading } = useSWR(`/auth/roles`, RoleService.getRoles)
|
||||
@ -68,10 +69,9 @@ export function useDocuments(folder_id?: number) {
|
||||
export function useDownload(folder_id?: number, id?: number) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
folder_id && id ? `/info/document/${folder_id}&${id}` : null,
|
||||
blobFetcher,
|
||||
folder_id && id ? blobFetcher : null,
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnMount: false
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
)
|
||||
|
||||
@ -82,6 +82,22 @@ export function useDownload(folder_id?: number, id?: number) {
|
||||
}
|
||||
}
|
||||
|
||||
export function useFileType(fileName?: string, file?: Blob) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
fileName && file ? `/filetype/${fileName}` : null,
|
||||
file ? (key: string) => fileTypeFromBlob(file) : null,
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
fileType: data?.mime,
|
||||
isLoading,
|
||||
isError: error
|
||||
}
|
||||
}
|
||||
|
||||
export function useReport(city_id: number) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
city_id ? `/info/reports/${city_id}?to_export=false` : null,
|
||||
@ -96,10 +112,4 @@ export function useReport(city_id: number) {
|
||||
isLoading,
|
||||
isError: error
|
||||
}
|
||||
}
|
||||
|
||||
// export function useFileType(file?: Blob){
|
||||
// const { data, error, isLoading } = useSWR(
|
||||
// file ? `${file.}`
|
||||
// )
|
||||
// }
|
||||
}
|
Reference in New Issue
Block a user