-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
235 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import TextBlock from "./components/view/TextBlock"; | ||
import ImageBlock from "./components/view/ImageBlock"; | ||
import {Accordion, AccordionDetails, AccordionSummary, Button, IconButton} from "@mui/material"; | ||
import {Delete} from "@mui/icons-material"; | ||
import HistoryIcon from '@mui/icons-material/History'; | ||
import EditIcon from "@mui/icons-material/Edit"; | ||
import {Box} from "@mui/system"; | ||
import Wysiwyg from "./components/editor/Wysiwyg"; | ||
import React, {useState} from "react"; | ||
import FileUploader from "./components/editor/FileUploader"; | ||
import "../../Styles/Block.css" | ||
import Menu from "@mui/material/Menu"; | ||
import MoreVertIcon from '@mui/icons-material/MoreVert'; | ||
import MenuItem from "@mui/material/MenuItem"; | ||
|
||
|
||
export default function BlockComponent(props) { | ||
|
||
const [showEditor, setShowEditor] = useState(false) | ||
const [block, setBlock] = useState(props.block) | ||
const [anchorEl, setAnchorEl] = useState(null); | ||
const handleClick = (event: React.MouseEvent<HTMLElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
const [showMenu, setShowMenu] = useState(false); | ||
|
||
const handleMouseEnter = () => { | ||
setShowMenu(true); | ||
}; | ||
|
||
const handleMouseLeave = () => { | ||
setShowMenu(false); | ||
}; | ||
|
||
|
||
const getBlockView = () =>{ | ||
switch(block.type_block) { | ||
case 'TEXT': | ||
return <TextBlock block={block}/> | ||
case 'IMG': | ||
return <ImageBlock block={block} /> | ||
} | ||
} | ||
|
||
const getBlockEditor = () => { | ||
switch(block.type_block) { | ||
case 'TEXT': | ||
return <Wysiwyg block={block} onChange={handleChange}/> | ||
case 'IMG': | ||
return <FileUploader block={block} onChange={handleChange}/> | ||
} | ||
} | ||
|
||
const getTools = () => { | ||
switch(props.mode) { | ||
case 'view': | ||
return( | ||
<div style={{float: 'right'}}> | ||
<MenuItem onClick={handleShowHistory}> | ||
<HistoryIcon/> | ||
</MenuItem> | ||
</div> | ||
) | ||
case 'edit': | ||
return( | ||
<div > | ||
<MenuItem onClick={handleDelete}> | ||
<Delete/> | ||
</MenuItem> | ||
<MenuItem onClick={handleShowHistory}> | ||
<HistoryIcon/> | ||
</MenuItem> | ||
<MenuItem onClick={handleShowEditor}> | ||
<EditIcon/> | ||
</MenuItem> | ||
</div> | ||
/*case 'version': | ||
return ( | ||
<div style={{float: 'right'}}> | ||
<IconButton onClick={handleDelete}> | ||
<Delete/> | ||
</IconButton> | ||
</div>*/ | ||
) | ||
} | ||
} | ||
|
||
const handleAddAbove = () => { | ||
//props.onAddAbove(block) | ||
} | ||
|
||
const handleAddBelow = () => { | ||
//props.onAddBelow(block) | ||
} | ||
|
||
const handleMoveDown = () => { | ||
//props.onMoveDown(block) | ||
} | ||
|
||
const handleMoveUp = () => { | ||
//props.onMoveUp(block) | ||
} | ||
|
||
const handleDelete = () => { | ||
props.onDelete(block) | ||
} | ||
|
||
const handleShowHistory = () => { | ||
props.onShowHistory(block) | ||
} | ||
|
||
const handleShowEditor = () => { | ||
setShowEditor(!showEditor) | ||
} | ||
|
||
const handleChange = (newBlock) => { | ||
setBlock(newBlock) | ||
props.onChange() | ||
} | ||
|
||
|
||
return ( | ||
<div | ||
className={"block-container"} | ||
onMouseEnter={handleMouseEnter} | ||
onMouseLeave={handleMouseLeave} | ||
> | ||
{showEditor ? | ||
<div className={"block-editor"}> | ||
{getBlockEditor()} | ||
</div> : | ||
<div className={"block-view"}> | ||
{getBlockView()} | ||
</div> | ||
} | ||
<div className={showMenu ? "block__toolbar_visibility_visible" : "block__toolbar_visibility_hidden"}> | ||
<Button onClick={handleClick}> | ||
<MoreVertIcon/> | ||
</Button> | ||
<Menu | ||
open={Boolean(anchorEl)} | ||
onClose={handleClose} | ||
anchorEl={anchorEl} | ||
> | ||
{getTools()} | ||
</Menu> | ||
</div> | ||
</div> | ||
) | ||
} |
18 changes: 18 additions & 0 deletions
18
frontend/src/Components/Block/components/editor/FileUploader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {api} from "../../../../Config/app.config"; | ||
|
||
|
||
export default function FileUploader({block, onChange}){ | ||
|
||
const handleChange = (e) => { | ||
const file = e.target.files[0]; | ||
if (file) { | ||
let formData = new FormData(); | ||
formData.append('file', file); | ||
api.updateFileBlockData(block.id, formData).then((newBlock) => { | ||
onChange(newBlock) | ||
}); | ||
} | ||
} | ||
|
||
return(<input type="file" onChange={handleChange}/>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
export default function ImageBlock({block}){ | ||
|
||
return( | ||
<img src={block.link} width="600"/> | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
frontend/src/Components/Block/components/view/TextBlock.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Typography} from "@mui/material"; | ||
import React from "react"; | ||
|
||
|
||
export default function TextBlock({block}){ | ||
|
||
return( | ||
<Typography dangerouslySetInnerHTML={{ __html: block.content}} /> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.