Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
egorov-m committed Dec 20, 2023
2 parents 5ade9e7 + 904889a commit accbaa8
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 127 deletions.
12 changes: 6 additions & 6 deletions docs/demo/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"files": {
"main.css": "https://egorov-m.github.io/wiki/demo/static/css/main.5a8c60d4.css",
"main.js": "https://egorov-m.github.io/wiki/demo/static/js/main.dededf10.js",
"main.css": "https://egorov-m.github.io/wiki/demo/static/css/main.89c56776.css",
"main.js": "https://egorov-m.github.io/wiki/demo/static/js/main.78de1325.js",
"index.html": "https://egorov-m.github.io/wiki/demo/index.html",
"main.5a8c60d4.css.map": "https://egorov-m.github.io/wiki/demo/static/css/main.5a8c60d4.css.map",
"main.dededf10.js.map": "https://egorov-m.github.io/wiki/demo/static/js/main.dededf10.js.map"
"main.89c56776.css.map": "https://egorov-m.github.io/wiki/demo/static/css/main.89c56776.css.map",
"main.78de1325.js.map": "https://egorov-m.github.io/wiki/demo/static/js/main.78de1325.js.map"
},
"entrypoints": [
"static/css/main.5a8c60d4.css",
"static/js/main.dededf10.js"
"static/css/main.89c56776.css",
"static/js/main.78de1325.js"
]
}
2 changes: 1 addition & 1 deletion docs/demo/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="https://egorov-m.github.io/wiki/demo/favicon.ico"/><link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;600;700&display=swap"/><link rel="manifest" href="https://egorov-m.github.io/wiki/demo/manifest.json"/><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Inter:wght@700&family=Montserrat:wght@700&display=swap" rel="stylesheet"><title>React App</title><script defer="defer" src="https://egorov-m.github.io/wiki/demo/static/js/main.dededf10.js"></script><link href="https://egorov-m.github.io/wiki/demo/static/css/main.5a8c60d4.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="https://egorov-m.github.io/wiki/demo/favicon.ico"/><link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;600;700&display=swap"/><link rel="manifest" href="https://egorov-m.github.io/wiki/demo/manifest.json"/><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Inter:wght@700&family=Montserrat:wght@700&display=swap" rel="stylesheet"><title>React App</title><script defer="defer" src="https://egorov-m.github.io/wiki/demo/static/js/main.78de1325.js"></script><link href="https://egorov-m.github.io/wiki/demo/static/css/main.89c56776.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1 change: 0 additions & 1 deletion docs/demo/static/css/main.5a8c60d4.css.map

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/demo/static/css/main.89c56776.css.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion frontend/src/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,35 @@ export default class Api {
}

async deleteDoc(doc_id){
await instance.delete(`/document?document_id=${doc_id}`)
await instance.delete(`/document/${doc_id}`)
}

async exportDoc(doc_id, filename) {
await instance.post(`/document/export?document_id=${doc_id}`,
{},
{responseType: 'arraybuffer'}).then((resp) => {
const downloadUrl = this.createDownloadUrl(resp.data);
const link = document.createElement('a');
link.href = downloadUrl;
link.download = `${filename}.docx`;
link.click();
})
}

createDownloadUrl(streamOfBits) {
const blob = new Blob([streamOfBits], {type: 'application/octet-stream'});
return window.URL.createObjectURL(blob);
}

getFilename(contentDisposition) {
const regex = /filename\*?=['"]?(?:UTF-\d['"]*)?([^;\s'"]*)['"]?;?/i;
const match = contentDisposition.match(regex);
if (match && match.length > 1) {
return decodeURIComponent(match[1]);
}
return null;
}

async addBlock(document_id, position, type_block){
await instance.post(`/blocks`,{
"document_id": document_id,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function App() {
const response = await api.getMe();
setUser(response);
} catch (error) {
console.log(error)
setUser(null)
}
setUserLoad(false)
};
Expand All @@ -48,10 +48,10 @@ export default function App() {
<BrowserRouter basename={"/wiki/demo"}>
<AppNavbar user={user}/>
<Routes>
<Route path={"/"} element={<Home/>}/>
<Route path={"/"} element={<Home user={user}/>}/>
<Route path={"/login"} element={<Login/>}/>
<Route path={"/verify"} element={<Verify onRefresh={handleRefresh}/>}/>
<Route path={"/signup"} element={<SignUp/>}/>
{/*<Route path={"/signup"} element={<SignUp/>}/>*/}
<Route path={"/logout"} element={<Logout onRefresh={handleRefresh}/>}/>
<Route element={<ProtectedRoute requirement={
user !== null && user.wiki_api_client !== null && user.wiki_api_client.responsibility === 'ADMIN'
Expand Down
128 changes: 58 additions & 70 deletions frontend/src/Components/Block/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ export default function BlockComponent(props) {
const [showEditor, setShowEditor] = useState(false)
const [block, setBlock] = useState(props.block)
const [anchorEl, setAnchorEl] = useState(null);
const [showMenu, setShowMenu] = useState(false);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};

const [showMenu, setShowMenu] = useState(false);


const handleMouseEnter = () => {
setShowMenu(true);
Expand All @@ -36,59 +37,25 @@ export default function BlockComponent(props) {
setShowMenu(false);
};


const getBlockView = () =>{
switch(block.type_block) {
const getBlockView = (type_block) =>{
switch(type_block) {
case 'TEXT':
return <TextBlock block={block}/>
case 'IMG':
return <ImageBlock block={block} />
}
}

const getBlockEditor = () => {
switch(block.type_block) {
const getBlockEditor = (type_block) => {
switch(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)
}
Expand All @@ -104,6 +71,7 @@ export default function BlockComponent(props) {
const handleMoveUp = () => {
//props.onMoveUp(block)
}
*/

const handleDelete = () => {
props.onDelete(block)
Expand All @@ -122,36 +90,56 @@ export default function BlockComponent(props) {
props.onChange()
}


return (
<div
className={"block-container"}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
{showEditor ?
<div className={"block-editor"}>
{getBlockEditor()}
</div> :
<div className={"block-view"}>
{getBlockView()}
switch(props.mode){
case "view" :
return(
<div className={"block-container"}>
<div className={"block-view"}>
{getBlockView(block.type_block)}
</div>
</div>
}

<div className={"tools-container"}>
<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>
)

case "edit" :
return (
<div
className={"block-container block-container_hover"}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
{showEditor ?
<div className={"block-editor"}>
{getBlockEditor(block.type_block)}
</div> :
<div className={"block-view"}>
{getBlockView(block.type_block)}
</div>
}
<div className={"tools-container"}>
<div className={showMenu? "block__toolbar_visibility_visible" : "block__toolbar_visibility_hidden"}>
<Button onClick={handleClick}>
<MoreVertIcon/>
</Button>
<Menu
open={Boolean(anchorEl)}
onClose={handleClose}
anchorEl={anchorEl}
>
<div >
<MenuItem onClick={handleDelete}>
<Delete/>
</MenuItem>
<MenuItem onClick={handleShowHistory}>
<HistoryIcon/>
</MenuItem>
<MenuItem onClick={handleShowEditor}>
<EditIcon/>
</MenuItem>
</div>
</Menu>
</div>
</div>
</div>
</div>
</div>
)
)
}
}
8 changes: 4 additions & 4 deletions frontend/src/Components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export default function AppNavbar(props) {
id="typography-home">
ГЛАВНАЯ
</Typography>
<Typography variant="h6"
{/*<Typography variant="h6"
component="a"
href="https://d-element.ru/?ysclid=lolx8ntig9911662351"
id="typography-home">
ПЕРЕЙТИ НА САЙТ
</Typography>
</Typography>*/}
</div>

if (props.user !== null && props.user.wiki_api_client !== null) {
Expand Down Expand Up @@ -131,12 +131,12 @@ export default function AppNavbar(props) {
}}>
ВОЙТИ
</Button>
<Button id="accent-button" /*sx={{background:'#b07285', color: '#423e42', ':hover': {backgroundColor: '#8a4a5d'}}}*/
{/* <Button id="accent-button" /*sx={{background:'#b07285', color: '#423e42', ':hover': {backgroundColor: '#8a4a5d'}}}
variant="contained" onClick={() => {
navigate("/signup")
}}>
ЗАРЕГИСТРИРОВАТЬСЯ
</Button>
</Button>*/}
</Stack>
);
} else {
Expand Down
16 changes: 11 additions & 5 deletions frontend/src/Components/Sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export function Sidebar(){
const [sidebarData, setSidebarData] = useState([]);
const [workspace, setWorkspace] = useState(null)
let navigate = useNavigate()
let {wp_id} = useParams();
let {wp_id, mode} = useParams();


useEffect(() => {

Expand All @@ -45,6 +46,7 @@ export function Sidebar(){
try {
const response = await api.getDocumentsTree(workspaceID)
setSidebarData(response)
console.log(sidebarData)
setDocsLoad(false)
}
catch (e){
Expand Down Expand Up @@ -75,6 +77,10 @@ export function Sidebar(){
fetchDocs(wp_id)
}

const handleExport = async (document_id, filename) => {
await api.exportDoc(document_id, filename)
}

const handleClick = (id, mode) => {
navigate(`/workspace/${wp_id}/document/${id}/${mode}`)
}
Expand All @@ -95,8 +101,8 @@ export function Sidebar(){
<DocumentTreeItemEditButton onClick={() => handleClick(item.id, "edit")}/>
<DocumentTreeItemMenuButton
onClickNewDocument={(title) => handleAdd(title, item.id)}
// onClickRename={onClickRename}
// onClickDelete={onClickDelete}
onClickDelete={() => handleDelete(item.id)}
onClickExport={() => handleExport(item.id, item.title)}
/>
</>
)}
Expand Down Expand Up @@ -150,8 +156,8 @@ export function Sidebar(){
<DocumentTreeItemEditButton onClick={() => handleClick(item.id, "edit")}/>
<DocumentTreeItemMenuButton
onClickNewDocument={(title) => handleAdd(title, item.id)}
// onClickRename={onClickRename}
// onClickDelete={onClickDelete}
onClickDelete={() => handleDelete(item.id)}
onClickExport={() => handleExport(item.id, item.title)}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ButtonAddDocument from "../../../ModalButton/ButtonAddDocument";
import {Form, Modal} from "react-bootstrap";
import Button from "@mui/material/Button";

const DocumentTreeItemMenuButton = ({ onClickNewDocument, onClickRename, onClickDelete, workspaceId, documentId }) => {
const DocumentTreeItemMenuButton = ({ onClickNewDocument, onClickExport, onClickDelete }) => {
const [anchorEl, setAnchorEl] = React.useState(null);

const [show, setShow] = useState(false);
Expand Down Expand Up @@ -40,6 +40,10 @@ const DocumentTreeItemMenuButton = ({ onClickNewDocument, onClickRename, onClick
onClickDelete()
handleCloseMenu()
}}>Delete</MenuItem>
<MenuItem onClick={() => {
onClickExport()
handleCloseMenu()
}}>Export</MenuItem>
</Menu>

<Modal show={show} onHide={handleClose}
Expand Down
Loading

0 comments on commit accbaa8

Please sign in to comment.