improve modal window rendering params handlers

This commit is contained in:
SrGooglo 2025-04-09 15:44:34 +00:00
parent deed590d9e
commit 599e6f9ea9
5 changed files with 105 additions and 101 deletions

View File

@ -171,17 +171,14 @@ export default class WindowManager extends Core {
} }
// remove the element from the DOM // remove the element from the DOM
this.console.debug(`Removing element from DOM for window ${id}`)
win.node.unmount() win.node.unmount()
this.root.removeChild(element) this.root.removeChild(element)
// remove the window from the list // remove the window from the list
this.console.debug(`Removing window from list for window ${id}`)
this.windows = this.windows.filter((node) => { this.windows = this.windows.filter((node) => {
return node.id !== id return node.id !== id
}) })
this.console.debug(`Window ${id} closed`)
return true return true
} }
} }

View File

@ -93,19 +93,23 @@ export default () => {
app.cores.window_mng.render( app.cores.window_mng.render(
id, id,
<Modal <Modal
onClose={() => {
app.cores.window_mng.close(id)
}}
framed={framed}
className={className} className={className}
framed={framed}
confirmOnOutsideClick={confirmOnOutsideClick} confirmOnOutsideClick={confirmOnOutsideClick}
confirmOnClickTitle={confirmOnClickTitle} confirmOnClickTitle={confirmOnClickTitle}
confirmOnClickContent={confirmOnClickContent} confirmOnClickContent={confirmOnClickContent}
onClose={() => {
app.cores.window_mng.close(id)
}}
> >
{React.isValidElement(render) {React.isValidElement(render)
? React.cloneElement(render, props) ? React.cloneElement(render, props)
: React.createElement(render, props)} : React.createElement(render, props)}
</Modal>, </Modal>,
{
useFrame: false,
closeOnClickOutside: false,
},
) )
} }

View File

@ -7,104 +7,106 @@ import { Icons } from "@components/Icons"
import "./index.less" import "./index.less"
class Modal extends React.Component { class Modal extends React.Component {
state = { state = {
visible: false, visible: false,
} }
contentRef = React.createRef() contentRef = React.createRef()
escTimeout = null escTimeout = null
componentDidMount() { componentDidMount() {
setTimeout(() => { setTimeout(() => {
this.setState({ this.setState({
visible: true, visible: true,
}) })
}, 10) }, 10)
document.addEventListener("keydown", this.handleEsc, false) document.addEventListener("keydown", this.handleEsc, false)
} }
componentWillUnmount() { componentWillUnmount() {
document.removeEventListener("keydown", this.handleEsc, false) document.removeEventListener("keydown", this.handleEsc, false)
} }
close = () => { close = () => {
this.setState({ this.setState({
visible: false, visible: false,
}) })
setTimeout(() => { setTimeout(() => {
if (typeof this.props.onClose === "function") { if (typeof this.props.onClose === "function") {
this.props.onClose() this.props.onClose()
} }
}, 250) }, 250)
} }
handleEsc = (e) => { handleEsc = (e) => {
if (e.key === "Escape") { if (e.key === "Escape") {
if (this.escTimeout !== null) { if (this.escTimeout !== null) {
clearTimeout(this.escTimeout) clearTimeout(this.escTimeout)
return this.close() return this.close()
} }
this.escTimeout = setTimeout(() => { this.escTimeout = setTimeout(() => {
this.escTimeout = null this.escTimeout = null
}, 250) }, 250)
} }
} }
handleClickOutside = (e) => { handleClickOutside = (e) => {
if (this.props.confirmOnOutsideClick) { console.log(e)
return AntdModal.confirm({ // check if event click is outside of content of the modal
title: this.props.confirmOnClickTitle ?? "Are you sure?", if (this.contentRef.current.contains(e.target)) {
content: this.props.confirmOnClickContent ?? "Are you sure you want to close this window?", return false
onOk: () => { }
this.close()
}
})
}
return this.close() if (this.props.confirmOnOutsideClick) {
} return AntdModal.confirm({
title: this.props.confirmOnClickTitle ?? "Are you sure?",
content:
this.props.confirmOnClickContent ??
"Are you sure you want to close this window?",
onOk: () => {
this.close()
},
})
}
render() { return this.close()
return <div }
className={classnames(
"app_modal_wrapper",
{
["active"]: this.state.visible,
["framed"]: this.props.framed,
}
)}
>
<div
id="mask_trigger"
onTouchEnd={this.handleClickOutside}
onMouseDown={this.handleClickOutside}
/>
<div
className="app_modal_content"
ref={this.contentRef}
style={this.props.frameContentStyle}
>
{
this.props.includeCloseButton && <div
className="app_modal_close"
onClick={this.close}
>
<Icons.MdClose />
</div>
}
{ render() {
React.cloneElement(this.props.children, { return (
close: this.close <div
}) className={classnames("app_modal_wrapper", {
} ["active"]: this.state.visible,
</div> ["framed"]: this.props.framed,
</div> })}
} >
<div
id="mask_trigger"
onTouchEnd={this.handleClickOutside}
onMouseDown={this.handleClickOutside}
/>
<div
className="app_modal_content"
ref={this.contentRef}
style={this.props.frameContentStyle}
>
{this.props.includeCloseButton && (
<div className="app_modal_close" onClick={this.close}>
<Icons.MdClose />
</div>
)}
{React.cloneElement(this.props.children, {
close: this.close,
})}
</div>
</div>
)
}
} }
export default Modal export default Modal

View File

@ -23,6 +23,8 @@
#mask_trigger { #mask_trigger {
position: fixed; position: fixed;
z-index: 450;
top: 0; top: 0;
left: 0; left: 0;
@ -60,6 +62,8 @@
.app_modal_content { .app_modal_content {
position: relative; position: relative;
z-index: 500;
box-sizing: border-box; box-sizing: border-box;
display: flex; display: flex;
@ -109,13 +113,6 @@
-webkit-box-shadow: @card-shadow; -webkit-box-shadow: @card-shadow;
-moz-box-shadow: @card-shadow; -moz-box-shadow: @card-shadow;
} }
.searcher {
box-sizing: border-box;
width: 48vw;
height: 80vh;
}
} }
} }

View File

@ -1,6 +1,10 @@
import { Lightbox } from "react-modal-image" import { Lightbox } from "react-modal-image"
import { NotificationsCenter, PostCreator, Searcher } from "@components"
import NotificationsCenter from "@components/NotificationsCenter"
import PostCreator from "@components/PostCreator"
import Searcher from "@components/Searcher"
import AppsMenu from "@components/AppsMenu" import AppsMenu from "@components/AppsMenu"
import config from "@config" import config from "@config"
import deleteInternalStorage from "@utils/deleteInternalStorage" import deleteInternalStorage from "@utils/deleteInternalStorage"