diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f8bbdf9..ea2f631 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -159,7 +159,7 @@ export default function App() { element={}> - }> + }> }> }> diff --git a/frontend/src/Translation/TranslationCard.css b/frontend/src/Translation/TranslationCard.css index f475ce6..96988cf 100644 --- a/frontend/src/Translation/TranslationCard.css +++ b/frontend/src/Translation/TranslationCard.css @@ -6,7 +6,7 @@ .translation-card { width: 290px; - height: 300px; + height: 550px; margin: 0; background: #FDF6E1; border: 1px; diff --git a/frontend/src/Translation/TranslationCard.tsx b/frontend/src/Translation/TranslationCard.tsx index 9fe493d..b844133 100644 --- a/frontend/src/Translation/TranslationCard.tsx +++ b/frontend/src/Translation/TranslationCard.tsx @@ -2,22 +2,41 @@ import axios from "axios"; import {Translation} from "./Translation.ts"; import React, {useState} from "react"; import { + Box, Button, Card, CardActions, - CardContent, IconButton, + CardContent, Dialog, DialogActions, DialogTitle, IconButton, Modal, Stack, TextField, Typography } from "@mui/material"; +import {styled} from '@mui/material/styles'; +import Paper from "@mui/material/Paper"; import ChangeCircleIcon from '@mui/icons-material/ChangeCircle'; import LibraryAddIcon from '@mui/icons-material/LibraryAdd'; import "./TranslationCard.css" +import {Conversion} from "./Conversion.ts"; +import {GameCard} from "../Game/GameCard.ts"; -export default function TranslationCard() { +type Props = { + onSaveCard: () => void +} + +export default function TranslationCard(props: Props) { const [translation, setTranslation] = useState(); const [originalWord, setOriginalWord] = useState(""); + const [conversion, setConversion] = useState(); + const [isOpenSelectModal, setIsOpenSelectModal] = useState(false); + + const Item = styled(Paper)(({theme}) => ({ + backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff', + ...theme.typography.body2, + padding: theme.spacing(1), + textAlign: 'start', + color: theme.palette.text.secondary, + })); function getTranslation(original: string, language: string) { axios.get("/api/translation?original=" + original + "&language=" + language) @@ -28,12 +47,49 @@ export default function TranslationCard() { .catch(console.error) } + function getConversion() { + axios.post( + "/api/converter", translation) + .then((response) => response.data) + .then(data => { + setConversion(data) + props.onSaveCard() + }) + .catch(console.error) + } + function inputOriginalWord(event: React.ChangeEvent) { setOriginalWord(event.target.value) } - function displayTranslation() { - getTranslation(originalWord, "EN"); + function openSelectModal() { + setIsOpenSelectModal(true); + } + + function closeSelectModal() { + setIsOpenSelectModal(false); + } + + function selectCharacter(result: string) { + let title = "" + if (conversion) { + if (result === "kanji") { + title = conversion.kanji + } else { + title= conversion.kana + } + } + axios.post( + "/api/game_cards", { + "title": title, + "reading": conversion?.alphabet, + "cardSetName": "new words" + } as GameCard) + .then(()=> { + closeSelectModal() + props.onSaveCard() + }) + .catch(console.error) } return ( @@ -48,36 +104,74 @@ export default function TranslationCard() { borderRadius: '15px' }}> - - What is the japanese word for - - +
- + { + getTranslation(originalWord, "EN") + }} sx={{boxShadow: 0}}>
- - {translation?.japanese} + + + + + JP: {translation?.japanese} + + + If you need to convert this translation into other Japanese characters click the green button below. + To create a new card with this translation, click the red button below. + + + kanji: {conversion?.kanji} + kana: {conversion?.kana} + reading: {conversion?.alphabet} + +
- - + + + + Do you want to create a new card with kanji or kana? + + + + + + + +