-
-
Notifications
You must be signed in to change notification settings - Fork 151
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. (#131)
- Loading branch information
1 parent
6b736e6
commit 4d51c0f
Showing
3 changed files
with
62 additions
and
3 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; |