From 1a4189901aa23e7067b8de5cf202c217ce38534f Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Mon, 17 Oct 2022 16:59:45 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=9D=D0=B0=20=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=86=D0=B5=20=D1=81=D0=BA=D0=B0=D1=87=D0=B8=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=B0=20=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=BD=D0=B0=20=D0=BF=D1=80=D0=B5=D0=B4=D1=8B?= =?UTF-8?q?=D0=B4=D1=83=D1=89=D1=83=D1=8E=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=86=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/FileDownload.jsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/pages/FileDownload.jsx b/src/pages/FileDownload.jsx index c18b51c..9995ae9 100644 --- a/src/pages/FileDownload.jsx +++ b/src/pages/FileDownload.jsx @@ -1,4 +1,4 @@ -import { Link, useNavigate, useParams } from 'react-router-dom' +import { Link, useLocation, useNavigate, useParams } from 'react-router-dom' import { memo, useCallback, useEffect, useState } from 'react' import { InfoCircleFilled, CloseCircleOutlined } from '@ant-design/icons' import { Button, Result, Typography } from 'antd' @@ -20,6 +20,8 @@ const FileDownload = memo(function FileDownload() { const [isError, setIsError] = useState(false) const navigate = useNavigate() + const location = useLocation() + const isFirstOpenApp = location.key === 'default' useEffect(() => { invokeWebApiWrapperAsync( @@ -33,10 +35,8 @@ const FileDownload = memo(function FileDownload() { 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, () => { @@ -48,7 +48,7 @@ const FileDownload = memo(function FileDownload() { }, [idWell, idFile]) const download = useCallback(async () => { - if (!await downloadFile(file)) + if (!file || !await downloadFile(file)) setIsError(true) }, [file]) @@ -60,13 +60,16 @@ const FileDownload = memo(function FileDownload() { <> Вы перешли к странице загрузки файла!
- Файл "{file.name ?? ('№' + idFile)}", скважина "{well.caption ?? ('№' + idWell)}". + Файл "{file?.name ?? ('№' + idFile)}", скважина "{well.caption ?? ('№' + idWell)}". )} // subTitle={} extra={( <> - + {isFirstOpenApp + ? + : + } )} From 53a1d33a5503cced37e75402430432711820d73d Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Mon, 17 Oct 2022 17:19:13 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=9D=D0=B0=20=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=86=D0=B5=20=D1=81=D0=BA=D0=B0=D1=87=D0=B8=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=B0=20=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=BD=D0=B0=20=D0=BF=D1=80=D0=B5=D0=B4=D1=8B?= =?UTF-8?q?=D0=B4=D1=83=D1=89=D1=83=D1=8E=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=86=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/FileDownload.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/FileDownload.jsx b/src/pages/FileDownload.jsx index 9995ae9..496826b 100644 --- a/src/pages/FileDownload.jsx +++ b/src/pages/FileDownload.jsx @@ -1,5 +1,5 @@ import { Link, useLocation, useNavigate, useParams } from 'react-router-dom' -import { memo, useCallback, useEffect, useState } from 'react' +import { memo, useCallback, useEffect, useMemo, useState } from 'react' import { InfoCircleFilled, CloseCircleOutlined } from '@ant-design/icons' import { Button, Result, Typography } from 'antd' @@ -21,7 +21,7 @@ const FileDownload = memo(function FileDownload() { const navigate = useNavigate() const location = useLocation() - const isFirstOpenApp = location.key === 'default' + const isFirstOpenApp = useMemo(() => location.key === 'default', [location]) useEffect(() => { invokeWebApiWrapperAsync( @@ -45,7 +45,7 @@ const FileDownload = memo(function FileDownload() { }, { actionName: 'Получение информации о файле' } ) - }, [idWell, idFile]) + }, [idFile]) const download = useCallback(async () => { if (!file || !await downloadFile(file)) From 5dd1fc8258d3c1a3805a713c7bcddf30ab19eb2e Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Wed, 19 Oct 2022 15:19:19 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BE=D0=B1=20id=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/FileDownload.jsx | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/pages/FileDownload.jsx b/src/pages/FileDownload.jsx index 496826b..810894e 100644 --- a/src/pages/FileDownload.jsx +++ b/src/pages/FileDownload.jsx @@ -5,17 +5,16 @@ import { Button, Result, Typography } from 'antd' import { downloadFile, invokeWebApiWrapperAsync } from '@components/factory' import { wrapPrivateComponent } from '@utils' -import { FileService, WellService } from '@api' +import { FileService } from '@api' import AccessDenied from './AccessDenied' 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) @@ -23,15 +22,6 @@ const FileDownload = memo(function FileDownload() { const location = useLocation() const isFirstOpenApp = useMemo(() => location.key === 'default', [location]) - useEffect(() => { - invokeWebApiWrapperAsync( - async () => setWell(await WellService.get(idWell)), - null, - 'Не удалось получить информацию о скважине', - { actionName: 'Получение данных о скважине' } - ) - }, [idWell]) - useEffect(() => { invokeWebApiWrapperAsync( async () => { @@ -60,7 +50,7 @@ const FileDownload = memo(function FileDownload() { <> Вы перешли к странице загрузки файла!
- Файл "{file?.name ?? ('№' + idFile)}", скважина "{well.caption ?? ('№' + idWell)}". + Файл "{file?.name ?? ('№' + idFile)}". )} // subTitle={} @@ -106,5 +96,5 @@ FileDownload.displayName = 'FileDownloadMemo' export default wrapPrivateComponent(FileDownload, { requirements: ['File.get'], - route: 'file_download/:idWell/:idFile/*', + route: 'file_download/:idFile/*', }, ) From ccbc0e1938be1f3a8bb2ca6b2b2a8ef409dcdcb8 Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Thu, 27 Oct 2022 10:35:32 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=80=D0=BE=D1=83=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B0=20FileDo?= =?UTF-8?q?wnload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 */}