Skip to content

Get definition #12 #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/data/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RandomQuote } from "../pages/activities/RandomQuote";
import { MagicSquares } from "../pages/games/MagicSquares";
import { TicTacToe } from "../pages/games/TicTacToe";
import {FortuneCard} from "../pages/activities/FotuneCard";
import {SearchWord} from "../pages/activities/getDefinition";
import numberblocs from "../assets/numberblocks.png"

export const activities = [
Expand All @@ -19,6 +20,13 @@ export const activities = [
icon: "https://aws.astrotalk.com/assets/images/wheel_of_fortune.webp" ,
urlTerm: "get-your-fortune",
element: <FortuneCard />
},
{
title: "Search Words",
description: "Get any definition",
icon: "https://www.i2symbol.com/pictures/emojis/f/2/0/4/f2042fedcbc0cdaee2967c4449b62845.png" ,
urlTerm: "search-any-word",
element: <SearchWord />
}
];

Expand Down
59 changes: 59 additions & 0 deletions src/pages/activities/getDefinition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useState } from "react";
import axios from "axios";
import "../../styles/pages/activities/getDefinition.css";

export const SearchWord = () => {
const [term, setTerm] = useState();
const [definition, setDefinition] = useState();

const generateDefinition = () => {
axios({
method: "GET",
url: "https://api.urbandictionary.com/v0/define",
params: {
term: term,
},
})
.then((res) => {
const firstDefinition = res.data.list[0];
if (firstDefinition) {
setDefinition(firstDefinition.definition);
} else {
setDefinition("No definition found.");
}
})
.catch((error) => console.error(error));
};

const handleSearch = () => {
generateDefinition();
};

const handleKeyPress = (e) => {
if (e.key === "Enter") {
generateDefinition();
}
};

return (
<div className="rquote-root">
<h1>Your Virtual Dictionary</h1>
<div>Search a word to get the Meaning Instantly!</div>
<div><br></br></div>
<div className="search-bar">
<input
id="Search"
type="text"
placeholder="Enter a word"
value={term}
onChange={(e) => setTerm(e.target.value)}
onKeyPress={handleKeyPress}
/>
<button onClick={handleSearch} className="word-button">Search</button>
</div>
<div className="word-content">
<div className="word-definition">{definition}</div>
</div>
</div>
);
};
28 changes: 28 additions & 0 deletions src/styles/pages/activities/getDefinition.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#Search{
width: 300px;
height: 20px;
border-radius: 15px;
}

.word-definition{
font-family: "Fira Code Light";
font-style: italic;
font-size: 20px;
}


.word-button {
font-size: 23px;
background: white;
border-radius: 10px;
padding: 10px;
margin: 10px;
transition-duration: 300ms;
}

.word-button:hover {
cursor: pointer;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
background: #4c99fc;
}