diff --git a/fastapi/app/main.py b/fastapi/app/main.py index c185fe0..6d1c835 100644 --- a/fastapi/app/main.py +++ b/fastapi/app/main.py @@ -5,10 +5,18 @@ import requests from pydantic import BaseModel from bs4 import BeautifulSoup - +from fastapi.middleware.cors import CORSMiddleware app = FastAPI() +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + class ArticleResponse(BaseModel): article: str diff --git a/ui/src/components/TranslationSection.tsx b/ui/src/components/TranslationSection.tsx index a4227ce..58ad18e 100644 --- a/ui/src/components/TranslationSection.tsx +++ b/ui/src/components/TranslationSection.tsx @@ -130,7 +130,6 @@ const TranslationSection = () => { }; const [availableTranslationLanguages, setAvailableTranslationLanguages] = useState[]>([]) const [isLoading, setIsLoading] = useState(false) - const [articleContent, setArticleContent] = useState(''); const form = useForm({ defaultValues: { sourceArticleUrl: '', @@ -147,10 +146,9 @@ const TranslationSection = () => { setValue, } = form - /*const onSubmit = useCallback(async (data: TranslationFormType) => { + const onSubmit = useCallback(async (data: TranslationFormType) => { try { setIsLoading(true) - const response = await fetchArticle({ translationTool, deepLApiKey: APIKey, @@ -162,32 +160,13 @@ const TranslationSection = () => { Object.entries(response.data.articleLanguages).map(([key, value]) => ({ value, label: key, - }))) - + }))) } catch (error) { console.log(error) } finally { setIsLoading(false) } - }, [setValue, translationTool, APIKey])*/ - - const onSubmit = useCallback(async (data: { sourceArticleUrl: string }) => { - try { - setIsLoading(true) - - const mockResponse = { - title: 'Pizza', - content: - 'Pizza is a popular Italian dish made of flattened bread dough topped with tomatoes, cheese, and other ingredients, baked in an oven.', - url: 'https://en.wikipedia.org/wiki/Pizza', - } - setArticleContent(mockResponse.content) - } catch (error) { - console.error('Error fetching article:', error) - } finally { - setIsLoading(false) - } - }, []) + }, [setValue, translationTool, APIKey]) const onLanguageChange = useCallback(async (translateArticleUrl: string) => { try { @@ -289,20 +268,6 @@ const TranslationSection = () => { {text.editing} ))} - {articleContent ? ( - - {articleContent} - - Translation functionality is not implemented yet. - - - ) : ( - - No article content yet. - No translation available. - - )} -