Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix full screen bug + add full screen GET parameter #1883

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions front/src/actions/dashboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function createActions(store) {
const actions = {
setFullScreen(state, fullScreen) {
store.setState({
fullScreen
});
}
};
return actions;
}

export default createActions;
24 changes: 13 additions & 11 deletions front/src/routes/dashboard/DashboardPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ const DashboardPage = ({ children, ...props }) => (
</div>

<div class="page-options d-flex align-content-between flex-wrap">
{!props.dashboardNotConfigured && props.browserFullScreenCompatible && (
<button onClick={props.toggleFullScreen} class={cx('btn btn-outline-secondary ml-2 btn-sm')}>
<span>
{!props.fullScreen && <Text id="dashboard.enableFullScreen" />}
{props.fullScreen && <Text id="dashboard.disableFullScreen" />}{' '}
{!props.fullScreen && <i class="fe fe-maximize-2" />}
{props.fullScreen && <i class="fe fe-minimize-2" />}
</span>
</button>
)}
{props.currentDashboard && (
{!props.dashboardNotConfigured &&
props.browserFullScreenCompatible &&
!props.hideExitFullScreenButton && (
<button onClick={props.toggleFullScreen} class={cx('btn btn-outline-secondary ml-2 btn-sm')}>
<span>
{!props.fullScreen && <Text id="dashboard.enableFullScreen" />}
{props.fullScreen && <Text id="dashboard.disableFullScreen" />}{' '}
{!props.fullScreen && <i class="fe fe-maximize-2" />}
{props.fullScreen && <i class="fe fe-minimize-2" />}
</span>
</button>
)}
{props.currentDashboard && !props.hideExitFullScreenButton && (
<button onClick={props.editDashboard} class={cx('btn btn-outline-primary ml-2')}>
<span class={style.editDashboardText}>
<Text id="dashboard.editDashboardButton" />
Expand Down
55 changes: 38 additions & 17 deletions front/src/routes/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { route } from 'preact-router';

import DashboardPage from './DashboardPage';
import GatewayAccountExpired from '../../components/gateway/GatewayAccountExpired';
import actions from '../../actions/dashboard';
import get from 'get-value';

class Dashboard extends Component {
Expand Down Expand Up @@ -76,6 +77,16 @@ class Dashboard extends Component {
}
};

checkIfFullScreenParameterIsHere = () => {
if (this.props.fullscreen === 'force') {
try {
this.switchToFullScreen();
} catch (e) {
console.error(e);
}
}
};

init = async () => {
await this.getDashboards();
if (this.state.currentDashboardSelector) {
Expand All @@ -101,26 +112,34 @@ class Dashboard extends Component {
return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement;
};

switchToFullScreen = () => {
if (document.documentElement.requestFullscreen) {
// chrome & firefox
document.documentElement.requestFullscreen();
} else if (document.documentElement.webkitRequestFullscreen) {
// safari
document.documentElement.webkitRequestFullscreen();
}
this.props.setFullScreen(true);
};

exitFullScreen = () => {
if (document.exitFullscreen) {
// chrome & firefox
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
// safari
document.webkitExitFullscreen();
}
this.props.setFullScreen(false);
};

toggleFullScreen = () => {
const isFullScreen = this.isFullScreen();
if (!isFullScreen) {
if (document.documentElement.requestFullscreen) {
// chrome & firefox
document.documentElement.requestFullscreen();
} else if (document.documentElement.webkitRequestFullscreen) {
// safari
document.documentElement.webkitRequestFullscreen();
}
this.props.setFullScreen(true);
this.switchToFullScreen();
} else {
if (document.exitFullscreen) {
// chrome & firefox
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
// safari
document.webkitExitFullscreen();
}
this.props.setFullScreen(false);
this.exitFullScreen();
}
};

Expand Down Expand Up @@ -149,6 +168,7 @@ class Dashboard extends Component {
document.addEventListener('webkitfullscreenchange', this.onFullScreenChange, false);
document.addEventListener('mozfullscreenchange', this.onFullScreenChange, false);
document.addEventListener('click', this.closeDashboardDropdown, true);
this.checkIfFullScreenParameterIsHere();
}

componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -204,9 +224,10 @@ class Dashboard extends Component {
editDashboard={this.editDashboard}
toggleFullScreen={this.toggleFullScreen}
fullScreen={props.fullScreen}
hideExitFullScreenButton={props.fullscreen === 'force'}
/>
);
}
}

export default connect('user,fullScreen,currentUrl,httpClient,gatewayAccountExpired', {})(Dashboard);
export default connect('user,fullScreen,currentUrl,httpClient,gatewayAccountExpired', actions)(Dashboard);