Skip to content

Commit

Permalink
Bug #23: Handled blacklisted searches and implemented no-result response
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0is1 committed Oct 13, 2024
1 parent 911860e commit e64bfa8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/libs/APIParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ class ServiceProvider {
"B=ffe5a4383fa531151b96f993e2586d32; CT=MjgzNjUxNTc3; DL=english; L=hindi; geo=152.58.76.33%2CIN%2CPunjab%2CLudhiana%2C141007; mm_latlong=31.0048%2C75.9463; CH=G03%2CA07%2CO00%2CL03",
},
});

const data = await response.json();
return data;
if(response.status < 400){
const data = await response.json();
return data;
}
return null;
} catch (error) {
ToastAndroid.show(error, ToastAndroid.LONG);
}
Expand Down
18 changes: 11 additions & 7 deletions src/screens/SearchScreen/SearchScreen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ const SearchScreen = () => {
clearTimeout(timer);
}
const newTimer = setTimeout(async () => {
const response = await serviceProvider.getSearch(
encodeURIComponent(searchInput),
1,
searchType,
);
setResp(response?.results);
}, 1000);
try {
const response = await serviceProvider.getSearch(
encodeURIComponent(searchInput),
1,
searchType,
);
setResp(response?.results);
} catch (error) {
setResp(null);
}
}, 500);
setTimer(newTimer);
} else {
const fetchRecommendData = async () => {
Expand Down
20 changes: 17 additions & 3 deletions src/screens/SearchScreen/components/SearchList.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { StyleSheet } from "react-native";
import { StyleSheet, Text, View } from "react-native";
import React from "react";
import MasonryList from "@react-native-seoul/masonry-list";
import Card from "../../AlbumsScreen/components/Card";

const SearchList = ({ searchData }) => {
const renderCard = ({ item, index }) => (
<Card albumData={item} index={index} />
);

return (
searchData && (
(searchData.length > 0) ? (
<MasonryList
data={searchData}
keyExtractor={(item) => item.id}
Expand All @@ -17,13 +19,25 @@ const SearchList = ({ searchData }) => {
onEndReachedThreshold={0.1}
/>
)
: (
<View style={styles.noResultsContainer}>
<Text style={styles.noResultsText}>No results found</Text>
</View>
)
);
};

export default SearchList;

const styles = StyleSheet.create({
container: {
noResultsContainer: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
noResultsText: {
fontSize: 18,
fontWeight: "500",
color: "#555",
},
});

0 comments on commit e64bfa8

Please sign in to comment.