Skip to content

Commit 194b387

Browse files
Merge pull request #51 from vishnukaushik/fix_get_definition_activity
fix: get definition activity
2 parents 3312a8a + dde15af commit 194b387

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

src/pages/activities/getDefinition.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@ import { useState } from "react";
22
import axios from "axios";
33
import "../../styles/pages/activities/getDefinition.css";
44

5+
const WordContent = ({definition})=>{
6+
if(definition){
7+
return(
8+
<div className="word-content">
9+
{
10+
definition?.map((def, index) => (
11+
<div className="word-definition">
12+
<div key={index}><em>Definition: </em>{def.definition}</div>
13+
<div key={index}><em>Example: </em>{def.example}</div>
14+
</div>
15+
)
16+
)
17+
}
18+
</div>
19+
)
20+
}
21+
return (
22+
<div className="word-content">
23+
<div className="no-definition">Word not found!</div>
24+
</div>
25+
)
26+
}
27+
528
export const SearchWord = () => {
629
const [term, setTerm] = useState();
730
const [definition, setDefinition] = useState([]);
@@ -20,7 +43,7 @@ export const SearchWord = () => {
2043
if (allDefinitions.length) {
2144
setDefinition(allDefinitions);
2245
} else {
23-
setDefinition("No definition found.");
46+
setDefinition(null);
2447
}
2548
})
2649
.catch((error) => console.error(error));
@@ -36,6 +59,7 @@ export const SearchWord = () => {
3659
}
3760
};
3861

62+
console.log(definition)
3963
return (
4064
<div className="rquote-root">
4165
<h1>Your Virtual Dictionary</h1>
@@ -52,14 +76,7 @@ export const SearchWord = () => {
5276
/>
5377
<button onClick={handleSearch} className="word-button">Search</button>
5478
</div>
55-
<div className="word-content">
56-
{definition.map((def, index) => (
57-
<div className="word-definition">
58-
<div key={index}><em>Definition: </em>{def.definition}</div>
59-
<div key={index}><em>Example: </em>{def.example}</div>
60-
</div>
61-
))}
62-
</div>
79+
<WordContent definition={definition}/>
6380
</div>
6481
);
65-
};
82+
};

src/styles/pages/activities/getDefinition.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
flex-direction: column;
1212
}
1313

14+
.no-definition{
15+
font-family: "Fira Code Light";
16+
color: rgb(255, 0, 0);
17+
font-size: 20px;
18+
overflow: hidden;
19+
margin: 1rem auto;
20+
}
21+
1422
.word-definition{
1523
font-family: "Fira Code Light";
1624
background: rgb(174,171,213);

0 commit comments

Comments
 (0)