forked from shravan20/github-readme-quotes
-
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.
Added Author selection option to the frontend for improved quote pers…
…onalization. (shravan20#131)
- Loading branch information
1 parent
8e07360
commit 703bb55
Showing
3 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
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,39 @@ | ||
import { useState, useCallback, useEffect } from "react"; | ||
|
||
import { serverUrl } from "../../components/Constants/urlConfig"; | ||
|
||
const useQuoteAuthors = () => { | ||
const originUrl = serverUrl; | ||
const [quoteAuthors, setQuoteAuthors] = useState([]); | ||
const [loadingQuoteAuthors, setLoadingQuoteAuthors] = useState(false); | ||
|
||
const fetchQuoteAuthors = useCallback(async () => { | ||
setLoadingQuoteAuthors(true); | ||
try { | ||
const response = await fetch(`${originUrl}/authors`); | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
|
||
const data = await response.json(); | ||
if (data) { | ||
setQuoteAuthors(data); | ||
} | ||
} catch (error) { | ||
console.error("Failed to fetch quote authors:", error); | ||
} finally { | ||
setLoadingQuoteAuthors(false); | ||
} | ||
}, [originUrl]); | ||
|
||
useEffect(() => { | ||
fetchQuoteAuthors(); | ||
}, [fetchQuoteAuthors]); | ||
|
||
return { | ||
quoteAuthors, | ||
loadingQuoteAuthors | ||
}; | ||
} | ||
|
||
export default useQuoteAuthors; |