-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add translation component in frontend
- Loading branch information
Showing
7 changed files
with
104 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type Translation = { | ||
original: string, | ||
japanese: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.translation { | ||
display: flex; | ||
flex-direction: column; | ||
width: 290px; | ||
} | ||
|
||
.translation-card { | ||
width: 290px; | ||
margin: 0; | ||
background: #FDF6E1; | ||
border: 1px; | ||
borderColor: "rgba(122,119,119,0.3)"; | ||
borderRadius: '15px' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import axios from "axios"; | ||
import {Translation} from "./Translation.ts"; | ||
import React, {useState} from "react"; | ||
import {Button, Card, CardActions, CardContent, Stack, TextField, Typography} from "@mui/material"; | ||
import DoDisturbOnIcon from "@mui/icons-material/DoDisturbOn"; | ||
import ChangeCircleIcon from '@mui/icons-material/ChangeCircle'; | ||
import "./TranslationCard.css" | ||
|
||
export default function TranslationCard() { | ||
|
||
const [translation, setTranslation] = useState<Translation>(); | ||
const [originalWord, setOriginalWord] = useState<string>(""); | ||
|
||
function getTranslation(original: string, language: string) { | ||
axios.get<Translation>("/api/translation?original=" + original + "&language=" + language) | ||
.then(response => response.data) | ||
.then(data => { | ||
setTranslation(data) | ||
}) | ||
.catch(console.error) | ||
} | ||
|
||
function inputOriginalWord(event: React.ChangeEvent<HTMLInputElement>) { | ||
setOriginalWord(event.target.value) | ||
} | ||
|
||
function displayTranslation() { | ||
getTranslation(originalWord, "EN"); | ||
} | ||
|
||
return ( | ||
<> | ||
<div> | ||
<img width={"150px"} height={"150px"} src={"/logos/translation-logo.png"} | ||
alt={"translation-logo"}/> | ||
</div> | ||
<div className={"translation"}> | ||
<Card className="translation-card" sx={{boxShadow: 0}}> | ||
<CardContent> | ||
<Typography sx={{fontSize: 14}} color="text.secondary" gutterBottom component="div"> | ||
Translate into Japanese | ||
</Typography> | ||
<Typography variant="h5" component="div"> | ||
<TextField id="original" label="your favorite word?" onInput={inputOriginalWord}/> | ||
</Typography> | ||
<Typography sx={{mb: 1.5}} color="text.secondary" component="div"> | ||
Japanese translation: {translation?.japanese} | ||
</Typography> | ||
</CardContent> | ||
<CardActions> | ||
<Stack className={"new-card-edit-stack"} direction="row" paddingBottom={3}> | ||
<Button id={"new-card-button"} onClick={displayTranslation} sx={{ | ||
m: 5, | ||
color: "#508356", | ||
boxShadow: 0, | ||
borderRadius: '15px' | ||
}}><ChangeCircleIcon/></Button> | ||
<Button id={"new-card-button"} sx={{ | ||
m: 5, | ||
color: "#D05F5F", | ||
boxShadow: 0, | ||
borderRadius: '15px' | ||
}}><DoDisturbOnIcon/></Button> | ||
</Stack> | ||
</CardActions> | ||
</Card> | ||
</div> | ||
</> | ||
) | ||
} |