Skip to content

Commit

Permalink
Merge pull request #831 from bounswe/bugfix/FE/830/games-search-null-fix
Browse files Browse the repository at this point in the history
bugfix search
  • Loading branch information
mtkamiloglu authored Dec 25, 2023
2 parents 0517e9d + a7f37ce commit 756f941
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions ludos/frontend/src/pages/GamesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const gameHighlight = [
},
];


const convertToSlug = (text) => {
return text
?.toString()
Expand All @@ -42,7 +41,7 @@ const convertToSlug = (text) => {
.replace(/[\s_]/g, "-") // Replace spaces or underscores with dashes
.replace(/[^\w-]+/g, "") // Remove non-word characters except dashes
.replace(/--+/g, "-"); // Replace multiple dashes with single dash
}
};

export default function GamesPage() {
const [searchValue, setSearchValue] = useState("");
Expand All @@ -51,7 +50,6 @@ export default function GamesPage() {
const [suggestedGames, setSuggestedGames] = useState([]);
const [upcomingTitles, setUpcomingTitles] = useState([]);


const axiosInstance = axios.create({
baseURL: `http://${process.env.REACT_APP_API_URL}`,
headers: {
Expand Down Expand Up @@ -89,7 +87,9 @@ export default function GamesPage() {
};

axiosInstance
.get("/post?isLiked=false&isDisliked=false&isUpcomingTitle=true&order=ASC&orderByKey=numberOfLikes")
.get(
"/post?isLiked=false&isDisliked=false&isUpcomingTitle=true&order=ASC&orderByKey=numberOfLikes",
)
.then((response) => {
const formattedTopics = response.data.items.map((topic) => ({
title: topic?.title,
Expand All @@ -109,22 +109,17 @@ export default function GamesPage() {
? topic?.upcomingTitle?.isUpcomingTitle
: false,
}));
console.log("formattedTopics:")
console.log("formattedTopics:");
console.log(formattedTopics);
setUpcomingTitles(formattedTopics);
console.log("upcomingTitles:");
console.log(upcomingTitles);
})
.catch((error) => {
console.log(error);
})




});
}, []);


useEffect(() => {
const fetchGames = async () => {
axiosInstance
Expand Down Expand Up @@ -215,7 +210,9 @@ export default function GamesPage() {
value={searchValue}
onChange={(event, newValue) => {
setSearchValue(newValue);
handleGameRoute(newValue);
if (newValue) {
handleGameRoute(newValue);
}
}}
options={games.map((game) => game.title)}
onInputChange={(event, newInputValue) => {
Expand Down Expand Up @@ -327,9 +324,8 @@ export default function GamesPage() {
style={{ gap: "16px", display: "flex", flexDirection: "column" }}
>
{upcomingTitles.map((topic, index) => {
return <ForumTopic key={index} topic={topic} />
return <ForumTopic key={index} topic={topic} />;
})}

</div>
</div>
</Container>
Expand Down

0 comments on commit 756f941

Please sign in to comment.