Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Oct 11, 2020
1 parent 7a71b72 commit e5d08c7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
53 changes: 36 additions & 17 deletions src/components/theme/View/DefaultView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -148,4 +165,6 @@ DefaultView.propTypes = {
}).isRequired,
};

export default injectIntl(DefaultView);
export default connect((state, props) => ({
discodata_query: state.discodata_query,
}))(injectIntl(DefaultView));
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit e5d08c7

Please sign in to comment.