Skip to content

Commit

Permalink
Fix: Fullscreen when reseting
Browse files Browse the repository at this point in the history
  • Loading branch information
SverreNystad committed Oct 21, 2023
1 parent 0bbfca6 commit 25af00e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
28 changes: 2 additions & 26 deletions frontend/src/components/settingspage/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,8 @@ import React, { useContext } from 'react';
import { SettingsContext } from '../../contexts/SettingsContext'; // adjust the import path as needed

const SettingsPage = () => {
const { settings, updateSetting, resetToDefaults } = useContext(SettingsContext);
const toggleFullScreen = () => {
if (!document.fullscreenElement) {
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) { /* Firefox */
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
document.documentElement.webkitRequestFullscreen();
} else if (document.documentElement.msRequestFullscreen) { /* IE/Edge */
document.documentElement.msRequestFullscreen();
}
updateSetting('isFullscreen', true); // update your state variable
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) { /* Firefox */
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE/Edge */
document.msExitFullscreen();
}
updateSetting('isFullscreen', false); // update your state variable
}
}
const { settings, updateSetting, resetToDefaults, toggleFullScreen } = useContext(SettingsContext);

// handler for changes in settings
const handleSettingChange = (setting) => (e) => {
updateSetting(setting, e.target.value);
Expand Down
31 changes: 30 additions & 1 deletion frontend/src/contexts/SettingsContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ export const SettingsProvider = ({ children }) => {
[key]: value,
}));
};
const toggleFullScreen = () => {
if (!document.fullscreenElement) {
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) { /* Firefox */
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
document.documentElement.webkitRequestFullscreen();
} else if (document.documentElement.msRequestFullscreen) { /* IE/Edge */
document.documentElement.msRequestFullscreen();
}
updateSetting('isFullscreen', true); // update your state variable
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) { /* Firefox */
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE/Edge */
document.msExitFullscreen();
}
updateSetting('isFullscreen', false); // update your state variable
}
}

// Function to reset all settings to default
const resetToDefaults = () => {
Expand All @@ -33,11 +58,15 @@ export const SettingsProvider = ({ children }) => {
mute: false,
// ... other settings ...
});
toggleFullScreen();

};

return (
<SettingsContext.Provider value={{ settings, updateSetting, resetToDefaults }}>
<SettingsContext.Provider value={{ settings, updateSetting, resetToDefaults, toggleFullScreen}}>
{children}
</SettingsContext.Provider>
);
};


0 comments on commit 25af00e

Please sign in to comment.