|
| 1 | +import { Editor } from "../../../components/Editor"; |
| 2 | +import { PreviewMode } from "../../../components/Editor/PreviewMode"; |
| 3 | +import { |
| 4 | + Box, |
| 5 | + Stack, |
| 6 | + IconButton, |
| 7 | + Tooltip, |
| 8 | + useMediaQuery, |
| 9 | + Grid, |
| 10 | +} from "@mui/material"; |
| 11 | +import { StartRounded, DesktopMacRounded } from "@mui/icons-material"; |
| 12 | +import { Actions } from "./Actions"; |
| 13 | +import { useLocalStorage } from "react-use"; |
| 14 | +import { useContext } from "react"; |
| 15 | +import { DuoModeContext } from "../../../../../../../shell/contexts/duoModeContext"; |
| 16 | +import { FieldError } from "../../../components/Editor/FieldError"; |
| 17 | +import { BlockTabs } from "../components/BlockTabs"; |
| 18 | + |
| 19 | +export default function Content(props) { |
| 20 | + const [showSidebar, setShowSidebar] = useLocalStorage( |
| 21 | + "zesty:content:sidebarOpen", |
| 22 | + false |
| 23 | + ); |
| 24 | + |
| 25 | + const { |
| 26 | + value: showDuoModeContextValue, |
| 27 | + setValue: setShowDuoMode, |
| 28 | + isDisabled, |
| 29 | + } = useContext(DuoModeContext); |
| 30 | + |
| 31 | + const xLarge = useMediaQuery((theme) => theme.breakpoints.up("xl")); |
| 32 | + |
| 33 | + const isFocusMode = !showDuoMode && !showSidebar; |
| 34 | + |
| 35 | + const showDuoMode = props?.model?.type === "block" || showDuoModeContextValue; |
| 36 | + |
| 37 | + return ( |
| 38 | + <> |
| 39 | + <Box |
| 40 | + bgcolor="grey.50" |
| 41 | + height="100%" |
| 42 | + overflow="hidden" |
| 43 | + pt={2.5} |
| 44 | + px={4} |
| 45 | + boxSizing="border-box" |
| 46 | + position="relative" |
| 47 | + sx={{ |
| 48 | + "*": { |
| 49 | + scrollbarWidth: "none", |
| 50 | + "-ms-overflow-style": "none", |
| 51 | + "&::-webkit-scrollbar": { |
| 52 | + display: "none", |
| 53 | + }, |
| 54 | + }, |
| 55 | + }} |
| 56 | + > |
| 57 | + <Grid |
| 58 | + container |
| 59 | + spacing={0} |
| 60 | + columnGap={3} |
| 61 | + columns={2} |
| 62 | + flexWrap="nowrap" |
| 63 | + sx={{ |
| 64 | + height: "100%", |
| 65 | + width: "100%", |
| 66 | + boxSizing: "border-box", |
| 67 | + }} |
| 68 | + > |
| 69 | + <Grid |
| 70 | + item |
| 71 | + xs={ |
| 72 | + !showDuoMode && !showSidebar |
| 73 | + ? 2 |
| 74 | + : showSidebar && !showDuoMode |
| 75 | + ? 1.85 |
| 76 | + : "auto" |
| 77 | + } |
| 78 | + sx={{ |
| 79 | + position: "relative", |
| 80 | + height: "100%", |
| 81 | + width: "100%", |
| 82 | + }} |
| 83 | + > |
| 84 | + <Box |
| 85 | + boxSizing="border-box" |
| 86 | + height="100%" |
| 87 | + flexGrow={0} |
| 88 | + sx={{ |
| 89 | + display: "flex", |
| 90 | + justifyContent: |
| 91 | + (!showDuoMode && !showSidebar) || xLarge |
| 92 | + ? "center" |
| 93 | + : "flex-start", |
| 94 | + overflowY: "scroll", |
| 95 | + width: "100%", |
| 96 | + maxWidth: showDuoMode ? 640 : "100%", |
| 97 | + minWidth: isFocusMode ? 640 : "auto", |
| 98 | + }} |
| 99 | + > |
| 100 | + <Box width={isFocusMode && !showDuoMode ? "60%" : "100%"}> |
| 101 | + {props.saveClicked && props.hasErrors && ( |
| 102 | + <Box mb={3}> |
| 103 | + <FieldError |
| 104 | + ref={props.fieldErrorRef} |
| 105 | + errors={props.fieldErrors} |
| 106 | + fields={props.activeFields} |
| 107 | + /> |
| 108 | + </Box> |
| 109 | + )} |
| 110 | + <Editor |
| 111 | + // active={this.state.makeActive} |
| 112 | + // scrolled={() => this.setState({ makeActive: "" })} |
| 113 | + model={props.model} |
| 114 | + itemZUID={props.itemZUID} |
| 115 | + item={props.item} |
| 116 | + dispatch={props.dispatch} |
| 117 | + isDirty={props.item.dirty} |
| 118 | + onSave={props.onSave} |
| 119 | + modelZUID={props.modelZUID} |
| 120 | + saveClicked={props.saveClicked} |
| 121 | + fieldErrors={props.fieldErrors} |
| 122 | + onUpdateFieldErrors={props.onUpdateFieldErrors} |
| 123 | + hasErrors={props.hasErrors} |
| 124 | + /> |
| 125 | + </Box> |
| 126 | + </Box> |
| 127 | + </Grid> |
| 128 | + <Grid |
| 129 | + item |
| 130 | + xs |
| 131 | + sx={{ |
| 132 | + position: "relative", |
| 133 | + height: "100%", |
| 134 | + }} |
| 135 | + > |
| 136 | + {!showDuoMode ? ( |
| 137 | + <Box display="flex" gap={1}> |
| 138 | + <Stack |
| 139 | + gap={1.5} |
| 140 | + sx={{ |
| 141 | + ...(!showSidebar && { |
| 142 | + position: "absolute", |
| 143 | + right: 0, |
| 144 | + }), |
| 145 | + }} |
| 146 | + > |
| 147 | + <Tooltip |
| 148 | + title={showSidebar ? "Close Info Bar" : "Open Info Bar"} |
| 149 | + placement="left" |
| 150 | + > |
| 151 | + <IconButton |
| 152 | + size="small" |
| 153 | + onClick={() => setShowSidebar(!showSidebar)} |
| 154 | + data-cy="ContentSidebarToggle" |
| 155 | + > |
| 156 | + <StartRounded |
| 157 | + fontSize="small" |
| 158 | + sx={{ |
| 159 | + transform: showSidebar |
| 160 | + ? "rotate(0deg)" |
| 161 | + : "rotate(180deg)", |
| 162 | + }} |
| 163 | + /> |
| 164 | + </IconButton> |
| 165 | + </Tooltip> |
| 166 | + {!isDisabled && ( |
| 167 | + <Tooltip title="Open DUO Mode" placement="left" dark> |
| 168 | + <IconButton |
| 169 | + size="small" |
| 170 | + onClick={() => { |
| 171 | + setShowDuoMode(true); |
| 172 | + }} |
| 173 | + > |
| 174 | + <DesktopMacRounded fontSize="small" /> |
| 175 | + </IconButton> |
| 176 | + </Tooltip> |
| 177 | + )} |
| 178 | + </Stack> |
| 179 | + |
| 180 | + {showSidebar && ( |
| 181 | + <Box |
| 182 | + maxWidth={320} |
| 183 | + pl={4} |
| 184 | + sx={{ |
| 185 | + borderLeft: (theme) => |
| 186 | + `1px solid ${theme.palette.grey[200]}`, |
| 187 | + overflowY: "auto", |
| 188 | + boxSizing: "border-box", |
| 189 | + }} |
| 190 | + data-cy="ContentSidebar" |
| 191 | + > |
| 192 | + <Actions |
| 193 | + {...props} |
| 194 | + site={{}} |
| 195 | + set={{ |
| 196 | + type: props.model?.type, |
| 197 | + }} |
| 198 | + /> |
| 199 | + </Box> |
| 200 | + )} |
| 201 | + </Box> |
| 202 | + ) : ( |
| 203 | + <Box |
| 204 | + height="100%" |
| 205 | + flex="1 1 auto" |
| 206 | + minWidth={360} |
| 207 | + display="flex" |
| 208 | + flexDirection="column" |
| 209 | + gap={2} |
| 210 | + > |
| 211 | + <Box flex={1}> |
| 212 | + <PreviewMode |
| 213 | + dirty={props.item.dirty} |
| 214 | + version={props.item.meta.version} |
| 215 | + onClose={() => setShowDuoMode(false)} |
| 216 | + onSave={() => props.onSave()} |
| 217 | + hasErrors={props.hasErrors} |
| 218 | + model={props.model} |
| 219 | + /> |
| 220 | + </Box> |
| 221 | + {props?.model?.type === "block" && ( |
| 222 | + <Box |
| 223 | + flex="1" |
| 224 | + sx={{ |
| 225 | + overflowY: "auto", |
| 226 | + }} |
| 227 | + > |
| 228 | + <BlockTabs {...props} /> |
| 229 | + </Box> |
| 230 | + )} |
| 231 | + </Box> |
| 232 | + )} |
| 233 | + </Grid> |
| 234 | + </Grid> |
| 235 | + </Box> |
| 236 | + </> |
| 237 | + ); |
| 238 | +} |
0 commit comments