Skip to content

Commit fe8c5ba

Browse files
author
Ivan
committed
Add button to refresh facts
1 parent f15c06f commit fe8c5ba

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/pages/Home.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const Home = () => {
1414
const { t } = useTranslation();
1515
const [showChuckNorrisFact, setShowChuckNorrisFact] = useState(false);
1616
const [chuckNorrisFact, setChuckNorrisFact] = useState("...");
17+
const [getNewDisabled, setGetNewDisabled] = useState(true);
1718

1819
const saveCV = () => {
1920
saveAs(cv, "Koldakov_Ivan_CV.pdf");
@@ -187,13 +188,17 @@ export const Home = () => {
187188
];
188189

189190
const getChuckNorrisFact = () => {
191+
setGetNewDisabled(true);
190192
fetch("https://api.chucknorris.io/jokes/random")
191193
.then(response => response.json())
192-
.then(json => setChuckNorrisFact(json["value"]))
194+
.then(json => {
195+
setChuckNorrisFact(json["value"]);
196+
})
193197
.catch(error => {
194198
console.error(error);
195-
setChuckNorrisFact(t("UnknownHTTPError.text"))
196-
});
199+
setChuckNorrisFact(t("UnknownHTTPError.text"));
200+
})
201+
.finally(() => setGetNewDisabled(false));
197202
}
198203

199204
const handleCloseChuckNorrisFact = () => {
@@ -402,6 +407,9 @@ export const Home = () => {
402407
<Button variant="secondary" onClick={handleCloseChuckNorrisFact}>
403408
{t("Close.text")}
404409
</Button>
410+
<Button variant="success" onClick={getChuckNorrisFact} disabled={getNewDisabled}>
411+
{t("GetNew.text")}
412+
</Button>
405413
</Modal.Footer>
406414
</Modal>
407415
</>

0 commit comments

Comments
 (0)