2021-12-08 07:24:10 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
import usePopover from '@/_hooks/use-popover';
|
2021-12-09 03:43:32 +00:00
|
|
|
import { SketchPicker } from 'react-color';
|
2022-04-21 16:38:54 +00:00
|
|
|
import { Confirm } from '../Viewer/Confirm';
|
2021-12-09 03:43:32 +00:00
|
|
|
|
2021-12-08 07:24:10 +00:00
|
|
|
import { LeftSidebarItem } from './SidebarItem';
|
2022-06-01 11:18:12 +00:00
|
|
|
import FxButton from '../CodeBuilder/Elements/FxButton';
|
|
|
|
|
import { CodeHinter } from '../CodeBuilder/CodeHinter';
|
|
|
|
|
import { resolveReferences } from '@/_helpers/utils';
|
2021-12-08 07:24:10 +00:00
|
|
|
|
2022-04-21 16:38:54 +00:00
|
|
|
export const LeftSidebarGlobalSettings = ({
|
|
|
|
|
globalSettings,
|
|
|
|
|
globalSettingsChanged,
|
|
|
|
|
darkMode,
|
|
|
|
|
toggleAppMaintenance,
|
|
|
|
|
is_maintenance_on,
|
2022-06-01 11:18:12 +00:00
|
|
|
currentState,
|
2022-04-21 16:38:54 +00:00
|
|
|
}) => {
|
2021-12-08 07:24:10 +00:00
|
|
|
const [open, trigger, content] = usePopover(false);
|
2022-06-01 11:18:12 +00:00
|
|
|
const { hideHeader, canvasMaxWidth, canvasMaxHeight, canvasBackgroundColor, backgroundFxQuery } = globalSettings;
|
2021-12-09 03:43:32 +00:00
|
|
|
const [showPicker, setShowPicker] = React.useState(false);
|
2022-06-01 11:18:12 +00:00
|
|
|
const [forceCodeBox, setForceCodeBox] = React.useState(true);
|
|
|
|
|
const [realState, setRealState] = React.useState(currentState);
|
2022-04-21 16:38:54 +00:00
|
|
|
const [showConfirmation, setConfirmationShow] = React.useState(false);
|
2021-12-09 03:43:32 +00:00
|
|
|
const coverStyles = {
|
|
|
|
|
position: 'fixed',
|
|
|
|
|
top: '0px',
|
|
|
|
|
right: '0px',
|
|
|
|
|
bottom: '0px',
|
|
|
|
|
left: '0px',
|
|
|
|
|
};
|
2022-06-01 11:18:12 +00:00
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
setRealState(currentState);
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [currentState.components]);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
backgroundFxQuery &&
|
|
|
|
|
globalSettingsChanged('canvasBackgroundColor', resolveReferences(backgroundFxQuery, realState));
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [JSON.stringify(resolveReferences(backgroundFxQuery, realState))]);
|
|
|
|
|
|
2021-12-08 07:24:10 +00:00
|
|
|
return (
|
|
|
|
|
<>
|
2022-04-21 16:38:54 +00:00
|
|
|
<Confirm
|
|
|
|
|
show={showConfirmation}
|
|
|
|
|
message={
|
|
|
|
|
is_maintenance_on
|
|
|
|
|
? 'Users will now be able to launch the released version of this app, do you wish to continue?'
|
|
|
|
|
: 'Users will not be able to launch the app until maintenance mode is turned off, do you wish to continue?'
|
|
|
|
|
}
|
|
|
|
|
onConfirm={() => toggleAppMaintenance()}
|
|
|
|
|
onCancel={() => setConfirmationShow(false)}
|
|
|
|
|
darkMode={darkMode}
|
|
|
|
|
/>
|
2021-12-08 07:24:10 +00:00
|
|
|
<LeftSidebarItem
|
|
|
|
|
tip="Global settings"
|
|
|
|
|
{...trigger}
|
|
|
|
|
icon="settings"
|
2022-03-11 03:06:38 +00:00
|
|
|
className={`left-sidebar-item left-sidebar-layout ${open && 'active'}`}
|
|
|
|
|
text={'Settings'}
|
2021-12-08 07:24:10 +00:00
|
|
|
/>
|
2022-03-16 16:49:48 +00:00
|
|
|
<div {...content} className={`card popover global-settings-popover ${open ? 'show' : 'hide'}`}>
|
2021-12-08 07:24:10 +00:00
|
|
|
<div style={{ marginTop: '1rem' }} className="card-body">
|
|
|
|
|
<div>
|
|
|
|
|
<div className="d-flex mb-3">
|
|
|
|
|
<span>Hide header for launched apps</span>
|
|
|
|
|
<div className="ms-auto form-check form-switch position-relative">
|
|
|
|
|
<input
|
|
|
|
|
className="form-check-input"
|
|
|
|
|
type="checkbox"
|
|
|
|
|
checked={hideHeader}
|
|
|
|
|
onChange={(e) => globalSettingsChanged('hideHeader', e.target.checked)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-04-21 16:38:54 +00:00
|
|
|
<div className="d-flex mb-3">
|
|
|
|
|
<span>Maintenance mode</span>
|
|
|
|
|
<div className="ms-auto form-check form-switch position-relative">
|
|
|
|
|
<input
|
|
|
|
|
className="form-check-input"
|
|
|
|
|
type="checkbox"
|
|
|
|
|
checked={is_maintenance_on}
|
|
|
|
|
onChange={() => setConfirmationShow(true)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-12-08 07:24:10 +00:00
|
|
|
<div className="d-flex mb-3">
|
2021-12-09 03:43:32 +00:00
|
|
|
<span className="w-full m-auto">Max width of canvas</span>
|
|
|
|
|
<div className="position-relative">
|
2021-12-08 07:24:10 +00:00
|
|
|
<div className="input-with-icon">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
className={`form-control form-control-sm`}
|
2022-05-09 08:36:59 +00:00
|
|
|
placeholder={'0'}
|
2021-12-08 07:24:10 +00:00
|
|
|
onChange={(e) => {
|
|
|
|
|
globalSettingsChanged('canvasMaxWidth', e.target.value);
|
|
|
|
|
}}
|
|
|
|
|
value={canvasMaxWidth}
|
|
|
|
|
/>
|
|
|
|
|
<span className="input-group-text">px</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-05-09 08:36:59 +00:00
|
|
|
<div className="d-flex mb-3">
|
|
|
|
|
<span className="w-full m-auto">Max height of canvas</span>
|
|
|
|
|
<div className="position-relative">
|
|
|
|
|
<div className="input-with-icon">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
className={`form-control form-control-sm`}
|
|
|
|
|
placeholder={'0'}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
const height = e.target.value;
|
|
|
|
|
if (!Number.isNaN(height) && height <= 2400) globalSettingsChanged('canvasMaxHeight', height);
|
|
|
|
|
}}
|
|
|
|
|
value={canvasMaxHeight}
|
|
|
|
|
/>
|
|
|
|
|
<span className="input-group-text">px</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-12-08 07:24:10 +00:00
|
|
|
<div className="d-flex">
|
2022-06-01 11:18:12 +00:00
|
|
|
<span className="w-full">Background color of canvas</span>
|
|
|
|
|
<div className="canvas-codehinter-container">
|
2021-12-09 03:43:32 +00:00
|
|
|
{showPicker && (
|
|
|
|
|
<div>
|
|
|
|
|
<div style={coverStyles} onClick={() => setShowPicker(false)} />
|
|
|
|
|
<SketchPicker
|
|
|
|
|
className="canvas-background-picker"
|
|
|
|
|
onFocus={() => setShowPicker(true)}
|
|
|
|
|
color={canvasBackgroundColor}
|
2022-06-01 11:18:12 +00:00
|
|
|
onChangeComplete={(color) => {
|
|
|
|
|
globalSettingsChanged('canvasBackgroundColor', [color.hex, color.rgb]);
|
|
|
|
|
globalSettingsChanged('backgroundFxQuery', null);
|
|
|
|
|
}}
|
2021-12-09 03:43:32 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2022-06-01 11:18:12 +00:00
|
|
|
{forceCodeBox && (
|
|
|
|
|
<div
|
|
|
|
|
className="row mx-0 form-control form-control-sm canvas-background-holder"
|
|
|
|
|
onClick={() => setShowPicker(true)}
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
className="col-auto"
|
|
|
|
|
style={{
|
|
|
|
|
float: 'right',
|
|
|
|
|
width: '20px',
|
|
|
|
|
height: '20px',
|
|
|
|
|
backgroundColor: canvasBackgroundColor,
|
|
|
|
|
border: `0.25px solid ${
|
|
|
|
|
['#ffffff', '#fff', '#1f2936'].includes(canvasBackgroundColor) && '#c5c8c9'
|
|
|
|
|
}`,
|
|
|
|
|
}}
|
|
|
|
|
></div>
|
|
|
|
|
<div className="col">{canvasBackgroundColor}</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2021-12-09 03:43:32 +00:00
|
|
|
<div
|
2022-06-01 11:18:12 +00:00
|
|
|
className={`${!forceCodeBox && 'hinter-canvas-input'} ${!darkMode && 'hinter-canvas-input-light'} `}
|
2021-12-09 03:43:32 +00:00
|
|
|
>
|
2022-06-01 11:18:12 +00:00
|
|
|
{!forceCodeBox && (
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={realState}
|
|
|
|
|
initialValue={backgroundFxQuery ? backgroundFxQuery : canvasBackgroundColor}
|
|
|
|
|
value={backgroundFxQuery ? backgroundFxQuery : canvasBackgroundColor}
|
|
|
|
|
theme={darkMode ? 'monokai' : 'duotone-light'}
|
|
|
|
|
mode="javascript"
|
|
|
|
|
className="canvas-hinter-wrap"
|
|
|
|
|
lineNumbers={false}
|
|
|
|
|
onChange={(color) => {
|
|
|
|
|
globalSettingsChanged('canvasBackgroundColor', resolveReferences(color, realState));
|
|
|
|
|
globalSettingsChanged('backgroundFxQuery', color);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
<div className={`fx-canvas ${!darkMode && 'fx-canvas-light'} `}>
|
|
|
|
|
<FxButton
|
|
|
|
|
active={!forceCodeBox ? true : false}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
setForceCodeBox(!forceCodeBox);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2021-12-09 03:43:32 +00:00
|
|
|
</div>
|
2021-12-08 07:24:10 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|