Skip to content

Commit

Permalink
Iframe height by viewport; Sidebar anchor update.
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Oct 11, 2020
1 parent a804b74 commit 8672665
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 33 deletions.
48 changes: 26 additions & 22 deletions src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1275,28 +1275,32 @@ const OpenlayersMapView = (props) => {
<Dimmer id="map-loader" active={loader}>
<Loader />
</Dimmer>
<Portal node={document.getElementById('map-view-your-area-button')}>
<div id="view-your-area" className="ol-unselectable ol-control">
<button
className="toggle-button"
onClick={() => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
return centerPosition(state.map.element, position, 12);
},
(error) => {
console.log(error);
},
{ timeout: 10000 },
);
}
}}
>
<VoltoIcon name={navigationSVG} size="1em" fill="white" />
</button>
</div>
</Portal>
{document.getElementById('map-view-your-area-button') ? (
<Portal node={document.getElementById('map-view-your-area-button')}>
<div id="view-your-area" className="ol-unselectable ol-control">
<button
className="toggle-button"
onClick={() => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
return centerPosition(state.map.element, position, 12);
},
(error) => {
console.log(error);
},
{ timeout: 10000 },
);
}
}}
>
<VoltoIcon name={navigationSVG} size="1em" fill="white" />
</button>
</div>
</Portal>
) : (
''
)}
</div>
);
};
Expand Down
12 changes: 10 additions & 2 deletions src/components/manage/Blocks/Iframe/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@ const getSchema = (props) => {
title: 'Width',
type: 'text',
},
height: {
title: 'Height',
desktopHeight: {
title: 'Desktop height',
type: 'text',
},
tabletHeight: {
title: 'Tablet height',
type: 'text',
},
mobileHeight: {
title: 'Mobile height',
type: 'text',
},
hideToolbar: {
Expand Down
21 changes: 19 additions & 2 deletions src/components/manage/Blocks/Iframe/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@ const View = ({ content, ...props }) => {
description = '',
descriptionClassName = '',
width = '100%',
height = 'auto',
desktopHeight = '',
tabletHeight = '',
mobileHeight = '',
} = data;
const { hideToolbar = false, overflow = false, preset = null } = data;
const url = {
desktop: desktopUrl,
tablet: tabletUrl || desktopUrl,
mobile: mobileUrl || tabletUrl || desktopUrl,
};
const height = {
desktop: desktopHeight || data.height,
tablet: tabletHeight || desktopHeight || data.height,
mobile: mobileHeight || tabletHeight || desktopHeight || data.height,
};

useEffect(() => {
if (props.data.queryParameters?.value) {
Expand Down Expand Up @@ -137,6 +144,16 @@ const View = ({ content, ...props }) => {
];
};

const getHeightByWidth = () => {
return height[
Object.keys(breakPoints).filter(
(breakPoint) =>
breakPoints[breakPoint][0] >= windowWidth &&
breakPoints[breakPoint][1] <= windowWidth,
)[0]
];
};

const applyQueryParameters = (url, query) => {
try {
new URL(url);
Expand Down Expand Up @@ -192,7 +209,7 @@ const View = ({ content, ...props }) => {
...getPresetQueries(),
})}
width={width}
height={height}
height={getHeightByWidth()}
className="embeded-iframe"
display="initial"
position="relative"
Expand Down
19 changes: 13 additions & 6 deletions src/components/manage/Blocks/SidebarBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,21 @@ const makeNewNavigation = (
...[
{
title: 'Pollutant Releases',
url: `${item.items[0]?.url}#pollutant_releases_tableau`,
url: item.items[0]?.url,
flag: 'has_release_data',
id: 'pollutant_releases_tableau',
},
{
title: 'Pollutant Transfers',
url: `${item.items[0]?.url}#pollutant_transfers_tableau`,
url: item.items[0]?.url,
flag: 'has_transfer_data',
id: 'pollutant_transfers_tableau',
},
{
title: 'Waste Transfers',
url: `${item.items[0]?.url}#pollutant_waste_tableau`,
url: item.items[0]?.url,
flag: 'has_waste_data',
id: 'pollutant_waste_tableau',
},
]
.filter(
Expand All @@ -150,7 +153,7 @@ const makeNewNavigation = (
// pathname.includes(child.url)
// );
},
onClick: (pathname) => {
onClick: (pathname, location) => {
if (
facility.facilityInspireId !== search.facilityInspireId
) {
Expand All @@ -162,9 +165,13 @@ const makeNewNavigation = (
}),
);
}

if (pathname !== child.url) {
history.push(child.url);
history.push(`${child.url}#${child.id}`);
} else {
const hashElement = document.getElementById(child.id);
if (hashElement) {
hashElement.scrollIntoView();
}
}
},
})),
Expand Down
13 changes: 12 additions & 1 deletion src/components/theme/View/DefaultView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module components/theme/View/DefaultView
*/

import React from 'react';
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { defineMessages, injectIntl } from 'react-intl';

Expand Down Expand Up @@ -37,6 +37,17 @@ const DefaultView = ({ content, intl, location }) => {
const blocksLayoutFieldname = getBlocksLayoutFieldname(content);
const contentTypeBlocks = content['@components']?.layout?.[blocksFieldname];

useEffect(() => {
if (content['@type' === 'site_template']) {
const hashElement = document.getElementById(
location.hash.replace('#', ''),
);
if (hashElement) {
hashElement.scrollIntoView();
}
}
}, [location.hash]);

return hasBlocksData(content) ? (
<div id="page-document" className="ui container">
{map(content[blocksLayoutFieldname].items, (block) => {
Expand Down

0 comments on commit 8672665

Please sign in to comment.