diff --git a/src/Pages/Search.js b/src/Pages/Search.js index 0a6a8a8151f5c9120b9c5c731714296e64406da5..2cfbd93dcf7a1a005d9723a8b96aedca0b8c266d 100644 --- a/src/Pages/Search.js +++ b/src/Pages/Search.js @@ -106,26 +106,16 @@ export default function Search(props) { getRequest(url, handleSuccessfulGet, (error) => { console.log(error) }) }; -(function(history){ - const pushState = history.pushState; - history.pushState = function(state) { - if (typeof history.onpushstate == "function") { - history.onpushstate({state: state}); - } - // Call your custom function here - return pushState.apply(history, arguments); - } -})(window.history); - useEffect(() => { - dispatch({ - type: "HANDLE_SEARCH_BAR", - opened: false, - }); + setIsLoading(true) + const urlParams = new URLSearchParams(window.location.search); const query = urlParams.get("query"); const searchClass = urlParams.get("search_class"); + console.log(query) + console.log(searchClass) + if (state.search.query !== query || state.search.class !== searchClass) { dispatch({ type: "SAVE_SEARCH", @@ -136,12 +126,14 @@ export default function Search(props) { }); } + collectStuff(searchClass) + return () => dispatch({ type: "HANDLE_SEARCH_BAR", opened: false, }); - }, []); + }, [window.history.state.key]) useEffect(() => { setIsLoading(true); @@ -171,6 +163,7 @@ export default function Search(props) { <Dropdown options={options} value={optionResult} onChange={(e) => { setIsLoading(true); + console.log(window.history) currOption = e.value; setOption(currOption); collectStuff(currOption, ""); @@ -223,10 +216,10 @@ export default function Search(props) { tags={card.tags} rating={card.review_average} id={card.id} - author={card.owner.name} + author={card.owner ? card.owner.name : ""} description={card.description} thumbnails={card.items_thumbnails} - avatar={card.owner.avatar} + avatar={card.owner ? card.owner.avatar : ""} likeCount={card.likes_count} followed={card.followed} liked={card.liked} @@ -281,7 +274,7 @@ export default function Search(props) { {resultsResource.map((card) => ( <Grid item xs={12} sm={6} md={4} lg={3} key={card.id}> <ResourceCardFunction - avatar={card.publisher.avatar} + avatar={card.publisher ? card.publisher.avatar : ""} id={card.id} thumbnail={card.thumbnail} type={card.object_type ? card.object_type : "Outros"}