From e5d08c7a944652aec2d94ba04c8e519733d5b7ec Mon Sep 17 00:00:00 2001 From: Miu Razvan Date: Mon, 12 Oct 2020 00:47:37 +0300 Subject: [PATCH] Update --- src/components/theme/View/DefaultView.jsx | 53 +++++++++++++------ .../volto/components/theme/Search/Search.jsx | 2 +- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/components/theme/View/DefaultView.jsx b/src/components/theme/View/DefaultView.jsx index 3e761841..1e1294db 100644 --- a/src/components/theme/View/DefaultView.jsx +++ b/src/components/theme/View/DefaultView.jsx @@ -3,7 +3,9 @@ * @module components/theme/View/DefaultView */ -import React, { useState, useEffect } from 'react'; +import React, { useEffect, useRef } from 'react'; +import { connect } from 'react-redux'; +import { useHistory } from 'react-router-dom'; import PropTypes from 'prop-types'; import { defineMessages, injectIntl } from 'react-intl'; @@ -32,30 +34,45 @@ const messages = defineMessages({ * @param {Object} content Content object. * @returns {string} Markup of the component. */ -const DefaultView = ({ content, intl, location }) => { +const DefaultView = ({ content, intl, location, discodata_query }) => { + const history = useHistory(); const blocksFieldname = getBlocksFieldname(content); const blocksLayoutFieldname = getBlocksLayoutFieldname(content); const contentTypeBlocks = content['@components']?.layout?.[blocksFieldname]; + const hash = location.hash.replace('#', ''); + const timer = useRef(null); + const clock = useRef(0); useEffect(() => { - if (content['@type' === 'site_template']) { - const hashElement = document.getElementById( - location.hash.replace('#', ''), - ); - if (hashElement) { - hashElement.scrollIntoView(); - } + if ( + content['@type'] === 'site_template' && + !discodata_query.search.siteInspireId + ) { + history.push('/browse/explore-data-map/map'); } }, []); useEffect(() => { - if (content['@type' === 'site_template']) { - const hashElement = document.getElementById( - location.hash.replace('#', ''), - ); - if (hashElement) { - hashElement.scrollIntoView(); - } + if ( + content['@type'] === 'site_template' && + discodata_query.search.siteInspireId && + !timer.current + ) { + timer.current = setInterval(() => { + const hashElement = document.getElementById(hash); + clock.current += 1000; + if (hashElement) { + hashElement.scrollIntoView(); + clock.current = 0; + clearInterval(timer.current); + timer.current = null; + } + if (clock.current === 10000) { + clock.current = 0; + clearInterval(timer.current); + timer.current = null; + } + }, 1000); } }, [location.hash]); @@ -148,4 +165,6 @@ DefaultView.propTypes = { }).isRequired, }; -export default injectIntl(DefaultView); +export default connect((state, props) => ({ + discodata_query: state.discodata_query, +}))(injectIntl(DefaultView)); diff --git a/src/customizations/volto/components/theme/Search/Search.jsx b/src/customizations/volto/components/theme/Search/Search.jsx index 4e39c730..8f194737 100644 --- a/src/customizations/volto/components/theme/Search/Search.jsx +++ b/src/customizations/volto/components/theme/Search/Search.jsx @@ -401,7 +401,7 @@ class Search extends Component { key={`item-${pollutant.pollutantId}`} className="outline dark-blue" as="a" - to="/test" + to="/glossary/pollutants/pollutant-index" onClick={() => { this.props.setQueryParam({ queryParam: {