();
+
+ useEffect(() => {
+ client.get(`/api/v1/anime/source/${sourceId}`)
+ .then((response) => response.data)
+ .then((data: { name: string }) => setTitle(`Search: ${data.name}`));
+ }, []);
+
+ function processInput() {
+ if (textInput.current) {
+ const { value } = textInput.current;
+ if (value === '') {
+ setError(true);
+ setMessage('Type something to search');
+ } else {
+ setError(false);
+ setSearchTerm(value);
+ setMangas([]);
+ setMessage('loading...');
+ }
+ }
+ }
+
+ useEffect(() => {
+ if (searchTerm.length > 0) {
+ client.get(`/api/v1/anime/source/${sourceId}/search/${searchTerm}/${lastPageNum}`)
+ .then((response) => response.data)
+ .then((data: { mangaList: IManga[], hasNextPage: boolean }) => {
+ setMessage('');
+ if (data.mangaList.length > 0) {
+ setMangas([
+ ...mangas,
+ ...data.mangaList.map((it) => ({
+ title: it.title, thumbnailUrl: it.thumbnailUrl, id: it.id,
+ }))]);
+ setHasNextPage(data.hasNextPage);
+ } else {
+ setMessage('search query returned nothing.');
+ }
+ });
+ }
+ }, [searchTerm]);
+
+ const mangaGrid = (
+
+ );
+
+ return (
+ <>
+
+ e.key === 'Enter' && processInput()}
+ />
+
+
+ {mangaGrid}
+ >
+ );
+}