diff --git a/src/App.tsx b/src/App.tsx
index 7498b86..0ac3eb0 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -42,7 +42,7 @@ export const App = memo(() => (
{/* User pages */}
}>
- } />
+ } />
}>
{/* Admin pages */}
diff --git a/src/pages/FileDownload.jsx b/src/pages/FileDownload.jsx
index 217edfb..4da1a72 100644
--- a/src/pages/FileDownload.jsx
+++ b/src/pages/FileDownload.jsx
@@ -1,40 +1,30 @@
-import { Link, useNavigate, useParams } from 'react-router-dom'
-import { memo, useCallback, useEffect, useState } from 'react'
+import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'
+import { memo, useCallback, useEffect, useMemo, useState } from 'react'
import { InfoCircleFilled, CloseCircleOutlined } from '@ant-design/icons'
import { Button, Result, Typography } from 'antd'
import { downloadFile, invokeWebApiWrapperAsync } from '@components/factory'
import { withPermissions } from '@utils'
-import { FileService, WellService } from '@api'
+import { FileService } from '@api'
const { Paragraph, Text } = Typography
-export const getLinkToFile = (fileInfo) => `/file_download/${fileInfo.idWell}/${fileInfo.id}`
+export const getLinkToFile = (fileInfo) => `/file_download/${fileInfo.id}`
const FileDownload = memo(function FileDownload() {
- const { idWell, idFile } = useParams()
- const [well, setWell] = useState({})
+ const { idFile } = useParams()
const [file, setFile] = useState({})
const [isError, setIsError] = useState(false)
const navigate = useNavigate()
-
- useEffect(() => {
- invokeWebApiWrapperAsync(
- async () => setWell(await WellService.get(idWell)),
- null,
- 'Не удалось получить информацию о скважине',
- { actionName: 'Получение данных о скважине' }
- )
- }, [idWell])
+ const location = useLocation()
+ const isFirstOpenApp = useMemo(() => location.key === 'default', [location])
useEffect(() => {
invokeWebApiWrapperAsync(
async () => {
- const files = await FileService.getFilesInfo(idWell)
- // TODO Получается только одна категория файлов.
- // Поменять при появлении метода получения инфы о конкретном файле
- setFile(files.items.find((file) => file.id === idFile) ?? { id: idFile, idWell, name: `File_${idWell}_${idFile}` })
+ const file = await FileService.getFileInfo(idFile)
+ setFile(file)
},
null,
() => {
@@ -43,10 +33,10 @@ const FileDownload = memo(function FileDownload() {
},
{ actionName: 'Получение информации о файле' }
)
- }, [idWell, idFile])
+ }, [idFile])
const download = useCallback(async () => {
- if (!await downloadFile(file))
+ if (!file || !await downloadFile(file))
setIsError(true)
}, [file])
@@ -58,13 +48,16 @@ const FileDownload = memo(function FileDownload() {
<>
Вы перешли к странице загрузки файла!
- Файл "{file.name ?? ('№' + idFile)}", скважина "{well.caption ?? ('№' + idWell)}".
+ Файл "{file?.name ?? ('№' + idFile)}".
>
)}
// subTitle={}
extra={(
<>
-
+ {isFirstOpenApp
+ ?
+ :
+ }
>
)}