diff --git a/src/api/process/getText.ts b/src/api/process/getText.ts new file mode 100644 index 0000000..af7db26 --- /dev/null +++ b/src/api/process/getText.ts @@ -0,0 +1,34 @@ +import { useQuery } from '@tanstack/react-query'; +import { axios } from '../../lib/axios'; +import { ExtractFnReturnType, QueryConfig } from '../../lib/react-query'; +import { ProcessDescriptor, ScoreType, TextDescriptor } from './types'; +import { PROCESS_API_URL, TEXT_API_URL, TEXT_PARAM } from './urlKeys'; +import { QUERY_KEY_PROCESSES, QUERY_KEY_TEXTS } from './queryKeys'; + +export type GetTextResponse = TextDescriptor; + +export const getText = ({ textId, type = 'bert' }: { textId: number; type: ScoreType }): Promise => { + return axios.get(TEXT_API_URL.replace(`:${TEXT_PARAM}`, String(textId)), { + params: { + type + } + }); +}; + +type QueryFnType = typeof getText; + +type UseTextOptions = { + textId: number; + type: ScoreType; + config?: QueryConfig; +}; + +export const useText = ({ textId, type, config }: UseTextOptions) => { + return useQuery>({ + ...config, + queryKey: [QUERY_KEY_TEXTS, textId, type], + queryFn: async () => { + return await getText({ textId, type }); + } + }); +}; diff --git a/src/api/process/index.ts b/src/api/process/index.ts index 0383441..64691c3 100644 --- a/src/api/process/index.ts +++ b/src/api/process/index.ts @@ -1,2 +1,4 @@ export * from './types'; export * from './createProcess'; +export * from './getProcess'; +export * from './getText'; diff --git a/src/api/process/queryKeys.ts b/src/api/process/queryKeys.ts index 013feef..78d0df7 100644 --- a/src/api/process/queryKeys.ts +++ b/src/api/process/queryKeys.ts @@ -1 +1,2 @@ export const QUERY_KEY_PROCESSES = 'processes'; +export const QUERY_KEY_TEXTS = 'texts'; diff --git a/src/api/process/types.ts b/src/api/process/types.ts index 56aa9e6..a5f8e8f 100644 --- a/src/api/process/types.ts +++ b/src/api/process/types.ts @@ -1,6 +1,27 @@ +export type ScoreType = 'bert' | 'f'; + +export type ScoreDescriptor = { + [key in ScoreType]: { + text: string; + answer: string; + }; +}; + export type TextDescriptor = { - score: string; + id: number; + file_name: string; + description: + | { + [key in ScoreType]?: { + file?: string; + pdf?: string; + text: string; + }; + } + | null; text: string; + summary: string; + score: ScoreDescriptor; }; export type ProcessDescriptor = { diff --git a/src/api/process/urlKeys.ts b/src/api/process/urlKeys.ts index a171dcc..e2015a6 100644 --- a/src/api/process/urlKeys.ts +++ b/src/api/process/urlKeys.ts @@ -1,2 +1,5 @@ export const PROCESS_API_URL = '/process'; export const PROCESS_PARAM = 'processId'; + +export const TEXT_PARAM = 'textId'; +export const TEXT_API_URL = `/process/describe/:${TEXT_PARAM}`; diff --git a/src/app/routes/PathBuilder.ts b/src/app/routes/PathBuilder.ts index d837221..c0ff955 100644 --- a/src/app/routes/PathBuilder.ts +++ b/src/app/routes/PathBuilder.ts @@ -1,5 +1,6 @@ -import { TEXT_PAGE_PARAM, TEXT_PAGE_ROUTE } from './routes'; +import { RESPONSE_PAGE_PARAM, RESPONSE_PAGE_ROUTE, TEXT_PAGE_PARAM, TEXT_PAGE_ROUTE } from './routes'; export class PathBuilder { + static getProcessPath = (id: string) => RESPONSE_PAGE_ROUTE.replace(`:${RESPONSE_PAGE_PARAM}`, String(id)); static getTextPath = (id: number) => TEXT_PAGE_ROUTE.replace(`:${TEXT_PAGE_PARAM}`, String(id)); } diff --git a/src/components/Link/Link.module.scss b/src/components/Link/Link.module.scss index 4ec2b07..0c31c54 100644 --- a/src/components/Link/Link.module.scss +++ b/src/components/Link/Link.module.scss @@ -44,6 +44,10 @@ &:active { color: $color-brand-active; } + + &.Link_disabled { + color: $color-brand-disabled; + } } .Link_underlined { diff --git a/src/components/Modal/ModalBody/ModalBody.module.scss b/src/components/Modal/ModalBody/ModalBody.module.scss index 902e0c5..fb32d2e 100644 --- a/src/components/Modal/ModalBody/ModalBody.module.scss +++ b/src/components/Modal/ModalBody/ModalBody.module.scss @@ -7,5 +7,6 @@ @include media-down(tablet-small) { border-radius: 0 0 $radius-small $radius-small; + @include text-body-s-regular; } } diff --git a/src/config.ts b/src/config.ts index 39d1c17..a6f2860 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,5 +3,6 @@ // export const BACKEND_URL = 'https://ed68-77-234-219-9.ngrok-free.app'; // export const BACKEND_URL = 'https://16c2-77-234-219-9.ngrok-free.app'; export const BACKEND_URL = 'http://192.168.107.4'; +export const BACKEND_MEDIA_PORT = '8000'; export const API_URL = BACKEND_URL + '/api'; diff --git a/src/pages/home/HomePage.module.scss b/src/pages/home/HomePage.module.scss index 7f1f632..03c1253 100644 --- a/src/pages/home/HomePage.module.scss +++ b/src/pages/home/HomePage.module.scss @@ -81,6 +81,10 @@ $textarea-height: 192px; min-height: $textarea-height; } +.HomePage__textareaInput { + min-height: 160px; +} + .HomePage__filesContainer { @include flex-middle; flex-wrap: wrap; diff --git a/src/pages/home/HomePage.tsx b/src/pages/home/HomePage.tsx index 0a1965e..7cbe0aa 100644 --- a/src/pages/home/HomePage.tsx +++ b/src/pages/home/HomePage.tsx @@ -1,6 +1,7 @@ import { useCallback, useEffect, useState } from 'react'; import { SubmitHandler, useForm } from 'react-hook-form'; import { useDropzone } from 'react-dropzone'; +import { useNavigate } from 'react-router-dom'; import clsx from 'clsx'; import { ReactFCC } from '../../utils/ReactFCC'; import { Heading, HeadingSize } from '../../components/Heading'; @@ -14,6 +15,7 @@ import { useSingleTimeout } from '../../hooks/useSingleTimeout'; import { Upload } from '../../components/Upload'; import { Attachment } from '../../components/Attachment'; import { Loader } from '../../components/Loader'; +import { PathBuilder } from '../../app/routes'; import { ReactComponent as PlusIcon } from './assets/plus.svg'; import s from './HomePage.module.scss'; @@ -61,12 +63,10 @@ export const HomePage: ReactFCC = () => { const onSubmit: SubmitHandler = useCallback( async (data) => { - const response = await createProcess({ + await createProcess({ text: data.text, files: data.files }); - - // setProcessId(response.id); }, [createProcess] ); @@ -88,6 +88,14 @@ export const HomePage: ReactFCC = () => { } }, [processId, refetchProcess, timeout]); + const navigate = useNavigate(); + + useEffect(() => { + if (processId && process && process.current === process.total) { + navigate(PathBuilder.getProcessPath(processId)); + } + }, [navigate, process, processId]); + // ------ Обработка DnD ------ const currentText = watch('text'); @@ -141,6 +149,9 @@ export const HomePage: ReactFCC = () => { {currentFiles.length === 0 ? (