Reactjs ReactiveSearch Select an offer in DataSearch then Redirect to search page where there is the...
I try to open a new page /search/ when the user chooses an offer in the home page, where the search page contains offers related to the keyword selected in the Datasearch.
I am using a Datasearch in the home page header, where the user writes or select an existing offer then when he press Ok / Enter he'll be redirected to next page contain ResultCards contain a selection of offers related to that Keywords:
Here my Datasearch on Homepage:
constructor (props) {
super(props);
this.state = {
SearchQuery: "",
queryChanged: false,
value: "",
redirect: false
};
}
render() {
const { value } = this.props;
const { redirect } = this.state;
if (redirect) {
return <Redirect to={`search/${this.state.SearchQuery}`}/>;
}
return (
<div className="header-header-search-bar-input">
<DataSearch
componentId="SearchSensor"
dataField={['modele', 'marque', 'titre']}
fieldWeights={[2, 1]}
categoryField="titre.keyword"
placeholder="Trouvez une voiture..."
react={{
and: ['result_card', 'carsmodel', 'carsbrand', 'cardate', 'drivenrange', 'ratingsSensor', 'pricerange'],
}}
showFilter
showClear
filterLabel="Recherche"
className="headerTopSearch"
queryFormat="and"
URLParams={true}
innerRef={this.innerRef}
onQueryChange={
function(prevQuery, nextQuery) {
console.log('prevQuery', prevQuery);
console.log('nextQuery', nextQuery);
}}
onValueSelected={(value, cause, source) => {
console.log("onValueSelected_value:",value);
this.state.SearchQuery = value;
console.log("SearchQuery", this.state.SearchQuery);
this.setState({redirect:true});
}
}
onValueChange={
function(value) {
console.log("onValueChange value: ", value)
}
}
/>
</div>
);
}
}
Here is the ResultCard Code in the searchPage:
constructor(props) {
super (props);
this.state = {
queryChanged: false,
initialQuery:
'{"query":{"bool":{"must":[{"bool":{"must":[{"range":{"annee":{"gte":1986,"lte":2018,"boost":2}}},{"range":{"kilometrage":{"gte":0,"lte":500000,"boost":2}}},{"range":{"prix":{"gte":0,"lte":400000,"boost":2}}}]}}]}},"size":12,"from":0,"sort":[{"inseredate":{"order":"desc"}}]}',
queryToSave:"",
SearchQuery:"",
};
this.onData = this.onData.bind(this);
this.customQuery = this.customQuery.bind(this);
this.queryChanged = this.queryChanged.bind(this);
}
onData(data) {
const url = sha256(data.url);
console.log('data:', data);
console.log("url",url);
const urlan = `/search/${data.marque}/${data.modele}/${url}`;
console.log("urlan",urlan);
return {
title: <div
className="title-card"
dangerouslySetInnerHTML={{ __html: data.titre }}
/>,
description: (
<HomePageCard data={data} />
),
image: data.url_image[0],
url: urlan,
};
}
customQuery(value, props) {
console.log(value); //return undefined
console.log(props); //return undefined
//const query = this.props.search.SearchQuery; //I am not sure of this
return JSON.parse(query);
}
queryChanged(prevQuery, nextQuery) {
console.log(prevQuery);
console.log(nextQuery);
}
render() {
const { defaultQuery } = this.props;
console.log('defaultQuery:', defaultQuery);
return (
<div className="search-search-result-cards">
<ResultCard
componentId="result_card"
className="autorobot-cards"
size={13}
pages={4}
dataField="modele.keyword"
pagination={true}
sortOptions={[
{ label: 'Les plus récentes', dataField: 'inseredate', sortBy: 'desc' },
{ label: 'Les plus anciennes', dataField: 'inseredate', sortBy: 'asc' },
{ label: 'Prix le plus bas', dataField: 'prix', sortBy: 'asc' },
{ label: 'Prix le plus élevé', dataField: 'prix', sortBy: 'desc' },
]}
onQueryChange={(prevQuery, nextQuery) => {
this.queryChanged(prevQuery, nextQuery);
}}
react={{
and: ["SearchSensor"]
}}
innerClass={{
title: 'text-title',
listItem: 'cardItem',
sortOptions: 'sortOptions',
pagination: 'paginationCards',
}}
onData={this.onData}
customQuery={this.customQuery}
defaultQuery={this.customQuery}
target="_blank"
onNoResults="Aucun résultat trouvé."
showResultStats={false}
URLParams={true}
/>
</div>
);
}
}
And here the search page route:
path: '',
name: '',
childRoutes: [
{ path: '/search/:SearchQuery', name: 'Home page search', component: HomePageSearch },
],
};
reactjs redirect reactivesearch
add a comment |
I try to open a new page /search/ when the user chooses an offer in the home page, where the search page contains offers related to the keyword selected in the Datasearch.
I am using a Datasearch in the home page header, where the user writes or select an existing offer then when he press Ok / Enter he'll be redirected to next page contain ResultCards contain a selection of offers related to that Keywords:
Here my Datasearch on Homepage:
constructor (props) {
super(props);
this.state = {
SearchQuery: "",
queryChanged: false,
value: "",
redirect: false
};
}
render() {
const { value } = this.props;
const { redirect } = this.state;
if (redirect) {
return <Redirect to={`search/${this.state.SearchQuery}`}/>;
}
return (
<div className="header-header-search-bar-input">
<DataSearch
componentId="SearchSensor"
dataField={['modele', 'marque', 'titre']}
fieldWeights={[2, 1]}
categoryField="titre.keyword"
placeholder="Trouvez une voiture..."
react={{
and: ['result_card', 'carsmodel', 'carsbrand', 'cardate', 'drivenrange', 'ratingsSensor', 'pricerange'],
}}
showFilter
showClear
filterLabel="Recherche"
className="headerTopSearch"
queryFormat="and"
URLParams={true}
innerRef={this.innerRef}
onQueryChange={
function(prevQuery, nextQuery) {
console.log('prevQuery', prevQuery);
console.log('nextQuery', nextQuery);
}}
onValueSelected={(value, cause, source) => {
console.log("onValueSelected_value:",value);
this.state.SearchQuery = value;
console.log("SearchQuery", this.state.SearchQuery);
this.setState({redirect:true});
}
}
onValueChange={
function(value) {
console.log("onValueChange value: ", value)
}
}
/>
</div>
);
}
}
Here is the ResultCard Code in the searchPage:
constructor(props) {
super (props);
this.state = {
queryChanged: false,
initialQuery:
'{"query":{"bool":{"must":[{"bool":{"must":[{"range":{"annee":{"gte":1986,"lte":2018,"boost":2}}},{"range":{"kilometrage":{"gte":0,"lte":500000,"boost":2}}},{"range":{"prix":{"gte":0,"lte":400000,"boost":2}}}]}}]}},"size":12,"from":0,"sort":[{"inseredate":{"order":"desc"}}]}',
queryToSave:"",
SearchQuery:"",
};
this.onData = this.onData.bind(this);
this.customQuery = this.customQuery.bind(this);
this.queryChanged = this.queryChanged.bind(this);
}
onData(data) {
const url = sha256(data.url);
console.log('data:', data);
console.log("url",url);
const urlan = `/search/${data.marque}/${data.modele}/${url}`;
console.log("urlan",urlan);
return {
title: <div
className="title-card"
dangerouslySetInnerHTML={{ __html: data.titre }}
/>,
description: (
<HomePageCard data={data} />
),
image: data.url_image[0],
url: urlan,
};
}
customQuery(value, props) {
console.log(value); //return undefined
console.log(props); //return undefined
//const query = this.props.search.SearchQuery; //I am not sure of this
return JSON.parse(query);
}
queryChanged(prevQuery, nextQuery) {
console.log(prevQuery);
console.log(nextQuery);
}
render() {
const { defaultQuery } = this.props;
console.log('defaultQuery:', defaultQuery);
return (
<div className="search-search-result-cards">
<ResultCard
componentId="result_card"
className="autorobot-cards"
size={13}
pages={4}
dataField="modele.keyword"
pagination={true}
sortOptions={[
{ label: 'Les plus récentes', dataField: 'inseredate', sortBy: 'desc' },
{ label: 'Les plus anciennes', dataField: 'inseredate', sortBy: 'asc' },
{ label: 'Prix le plus bas', dataField: 'prix', sortBy: 'asc' },
{ label: 'Prix le plus élevé', dataField: 'prix', sortBy: 'desc' },
]}
onQueryChange={(prevQuery, nextQuery) => {
this.queryChanged(prevQuery, nextQuery);
}}
react={{
and: ["SearchSensor"]
}}
innerClass={{
title: 'text-title',
listItem: 'cardItem',
sortOptions: 'sortOptions',
pagination: 'paginationCards',
}}
onData={this.onData}
customQuery={this.customQuery}
defaultQuery={this.customQuery}
target="_blank"
onNoResults="Aucun résultat trouvé."
showResultStats={false}
URLParams={true}
/>
</div>
);
}
}
And here the search page route:
path: '',
name: '',
childRoutes: [
{ path: '/search/:SearchQuery', name: 'Home page search', component: HomePageSearch },
],
};
reactjs redirect reactivesearch
Were you able to figure this out? If you can share a codesandbox showing your approach, it would help in pointing out the potential issue.
– sidi
Dec 9 '18 at 23:51
add a comment |
I try to open a new page /search/ when the user chooses an offer in the home page, where the search page contains offers related to the keyword selected in the Datasearch.
I am using a Datasearch in the home page header, where the user writes or select an existing offer then when he press Ok / Enter he'll be redirected to next page contain ResultCards contain a selection of offers related to that Keywords:
Here my Datasearch on Homepage:
constructor (props) {
super(props);
this.state = {
SearchQuery: "",
queryChanged: false,
value: "",
redirect: false
};
}
render() {
const { value } = this.props;
const { redirect } = this.state;
if (redirect) {
return <Redirect to={`search/${this.state.SearchQuery}`}/>;
}
return (
<div className="header-header-search-bar-input">
<DataSearch
componentId="SearchSensor"
dataField={['modele', 'marque', 'titre']}
fieldWeights={[2, 1]}
categoryField="titre.keyword"
placeholder="Trouvez une voiture..."
react={{
and: ['result_card', 'carsmodel', 'carsbrand', 'cardate', 'drivenrange', 'ratingsSensor', 'pricerange'],
}}
showFilter
showClear
filterLabel="Recherche"
className="headerTopSearch"
queryFormat="and"
URLParams={true}
innerRef={this.innerRef}
onQueryChange={
function(prevQuery, nextQuery) {
console.log('prevQuery', prevQuery);
console.log('nextQuery', nextQuery);
}}
onValueSelected={(value, cause, source) => {
console.log("onValueSelected_value:",value);
this.state.SearchQuery = value;
console.log("SearchQuery", this.state.SearchQuery);
this.setState({redirect:true});
}
}
onValueChange={
function(value) {
console.log("onValueChange value: ", value)
}
}
/>
</div>
);
}
}
Here is the ResultCard Code in the searchPage:
constructor(props) {
super (props);
this.state = {
queryChanged: false,
initialQuery:
'{"query":{"bool":{"must":[{"bool":{"must":[{"range":{"annee":{"gte":1986,"lte":2018,"boost":2}}},{"range":{"kilometrage":{"gte":0,"lte":500000,"boost":2}}},{"range":{"prix":{"gte":0,"lte":400000,"boost":2}}}]}}]}},"size":12,"from":0,"sort":[{"inseredate":{"order":"desc"}}]}',
queryToSave:"",
SearchQuery:"",
};
this.onData = this.onData.bind(this);
this.customQuery = this.customQuery.bind(this);
this.queryChanged = this.queryChanged.bind(this);
}
onData(data) {
const url = sha256(data.url);
console.log('data:', data);
console.log("url",url);
const urlan = `/search/${data.marque}/${data.modele}/${url}`;
console.log("urlan",urlan);
return {
title: <div
className="title-card"
dangerouslySetInnerHTML={{ __html: data.titre }}
/>,
description: (
<HomePageCard data={data} />
),
image: data.url_image[0],
url: urlan,
};
}
customQuery(value, props) {
console.log(value); //return undefined
console.log(props); //return undefined
//const query = this.props.search.SearchQuery; //I am not sure of this
return JSON.parse(query);
}
queryChanged(prevQuery, nextQuery) {
console.log(prevQuery);
console.log(nextQuery);
}
render() {
const { defaultQuery } = this.props;
console.log('defaultQuery:', defaultQuery);
return (
<div className="search-search-result-cards">
<ResultCard
componentId="result_card"
className="autorobot-cards"
size={13}
pages={4}
dataField="modele.keyword"
pagination={true}
sortOptions={[
{ label: 'Les plus récentes', dataField: 'inseredate', sortBy: 'desc' },
{ label: 'Les plus anciennes', dataField: 'inseredate', sortBy: 'asc' },
{ label: 'Prix le plus bas', dataField: 'prix', sortBy: 'asc' },
{ label: 'Prix le plus élevé', dataField: 'prix', sortBy: 'desc' },
]}
onQueryChange={(prevQuery, nextQuery) => {
this.queryChanged(prevQuery, nextQuery);
}}
react={{
and: ["SearchSensor"]
}}
innerClass={{
title: 'text-title',
listItem: 'cardItem',
sortOptions: 'sortOptions',
pagination: 'paginationCards',
}}
onData={this.onData}
customQuery={this.customQuery}
defaultQuery={this.customQuery}
target="_blank"
onNoResults="Aucun résultat trouvé."
showResultStats={false}
URLParams={true}
/>
</div>
);
}
}
And here the search page route:
path: '',
name: '',
childRoutes: [
{ path: '/search/:SearchQuery', name: 'Home page search', component: HomePageSearch },
],
};
reactjs redirect reactivesearch
I try to open a new page /search/ when the user chooses an offer in the home page, where the search page contains offers related to the keyword selected in the Datasearch.
I am using a Datasearch in the home page header, where the user writes or select an existing offer then when he press Ok / Enter he'll be redirected to next page contain ResultCards contain a selection of offers related to that Keywords:
Here my Datasearch on Homepage:
constructor (props) {
super(props);
this.state = {
SearchQuery: "",
queryChanged: false,
value: "",
redirect: false
};
}
render() {
const { value } = this.props;
const { redirect } = this.state;
if (redirect) {
return <Redirect to={`search/${this.state.SearchQuery}`}/>;
}
return (
<div className="header-header-search-bar-input">
<DataSearch
componentId="SearchSensor"
dataField={['modele', 'marque', 'titre']}
fieldWeights={[2, 1]}
categoryField="titre.keyword"
placeholder="Trouvez une voiture..."
react={{
and: ['result_card', 'carsmodel', 'carsbrand', 'cardate', 'drivenrange', 'ratingsSensor', 'pricerange'],
}}
showFilter
showClear
filterLabel="Recherche"
className="headerTopSearch"
queryFormat="and"
URLParams={true}
innerRef={this.innerRef}
onQueryChange={
function(prevQuery, nextQuery) {
console.log('prevQuery', prevQuery);
console.log('nextQuery', nextQuery);
}}
onValueSelected={(value, cause, source) => {
console.log("onValueSelected_value:",value);
this.state.SearchQuery = value;
console.log("SearchQuery", this.state.SearchQuery);
this.setState({redirect:true});
}
}
onValueChange={
function(value) {
console.log("onValueChange value: ", value)
}
}
/>
</div>
);
}
}
Here is the ResultCard Code in the searchPage:
constructor(props) {
super (props);
this.state = {
queryChanged: false,
initialQuery:
'{"query":{"bool":{"must":[{"bool":{"must":[{"range":{"annee":{"gte":1986,"lte":2018,"boost":2}}},{"range":{"kilometrage":{"gte":0,"lte":500000,"boost":2}}},{"range":{"prix":{"gte":0,"lte":400000,"boost":2}}}]}}]}},"size":12,"from":0,"sort":[{"inseredate":{"order":"desc"}}]}',
queryToSave:"",
SearchQuery:"",
};
this.onData = this.onData.bind(this);
this.customQuery = this.customQuery.bind(this);
this.queryChanged = this.queryChanged.bind(this);
}
onData(data) {
const url = sha256(data.url);
console.log('data:', data);
console.log("url",url);
const urlan = `/search/${data.marque}/${data.modele}/${url}`;
console.log("urlan",urlan);
return {
title: <div
className="title-card"
dangerouslySetInnerHTML={{ __html: data.titre }}
/>,
description: (
<HomePageCard data={data} />
),
image: data.url_image[0],
url: urlan,
};
}
customQuery(value, props) {
console.log(value); //return undefined
console.log(props); //return undefined
//const query = this.props.search.SearchQuery; //I am not sure of this
return JSON.parse(query);
}
queryChanged(prevQuery, nextQuery) {
console.log(prevQuery);
console.log(nextQuery);
}
render() {
const { defaultQuery } = this.props;
console.log('defaultQuery:', defaultQuery);
return (
<div className="search-search-result-cards">
<ResultCard
componentId="result_card"
className="autorobot-cards"
size={13}
pages={4}
dataField="modele.keyword"
pagination={true}
sortOptions={[
{ label: 'Les plus récentes', dataField: 'inseredate', sortBy: 'desc' },
{ label: 'Les plus anciennes', dataField: 'inseredate', sortBy: 'asc' },
{ label: 'Prix le plus bas', dataField: 'prix', sortBy: 'asc' },
{ label: 'Prix le plus élevé', dataField: 'prix', sortBy: 'desc' },
]}
onQueryChange={(prevQuery, nextQuery) => {
this.queryChanged(prevQuery, nextQuery);
}}
react={{
and: ["SearchSensor"]
}}
innerClass={{
title: 'text-title',
listItem: 'cardItem',
sortOptions: 'sortOptions',
pagination: 'paginationCards',
}}
onData={this.onData}
customQuery={this.customQuery}
defaultQuery={this.customQuery}
target="_blank"
onNoResults="Aucun résultat trouvé."
showResultStats={false}
URLParams={true}
/>
</div>
);
}
}
And here the search page route:
path: '',
name: '',
childRoutes: [
{ path: '/search/:SearchQuery', name: 'Home page search', component: HomePageSearch },
],
};
reactjs redirect reactivesearch
reactjs redirect reactivesearch
edited Nov 21 '18 at 15:59
Afef Mokhtari
asked Nov 12 '18 at 15:00
Afef MokhtariAfef Mokhtari
206
206
Were you able to figure this out? If you can share a codesandbox showing your approach, it would help in pointing out the potential issue.
– sidi
Dec 9 '18 at 23:51
add a comment |
Were you able to figure this out? If you can share a codesandbox showing your approach, it would help in pointing out the potential issue.
– sidi
Dec 9 '18 at 23:51
Were you able to figure this out? If you can share a codesandbox showing your approach, it would help in pointing out the potential issue.
– sidi
Dec 9 '18 at 23:51
Were you able to figure this out? If you can share a codesandbox showing your approach, it would help in pointing out the potential issue.
– sidi
Dec 9 '18 at 23:51
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264830%2freactjs-reactivesearch-select-an-offer-in-datasearch-then-redirect-to-search-pag%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264830%2freactjs-reactivesearch-select-an-offer-in-datasearch-then-redirect-to-search-pag%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Were you able to figure this out? If you can share a codesandbox showing your approach, it would help in pointing out the potential issue.
– sidi
Dec 9 '18 at 23:51