mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
use new modal controller
This commit is contained in:
parent
effdd5cb6e
commit
4b13c84bc1
@ -76,13 +76,12 @@ import {
|
|||||||
NotFound,
|
NotFound,
|
||||||
RenderError,
|
RenderError,
|
||||||
Crash,
|
Crash,
|
||||||
Navigation,
|
|
||||||
Login,
|
Login,
|
||||||
UserRegister,
|
UserRegister,
|
||||||
Searcher,
|
Searcher,
|
||||||
NotificationsCenter,
|
NotificationsCenter,
|
||||||
PostViewer,
|
PostViewer,
|
||||||
PostCreatorModal,
|
PostCreator,
|
||||||
} from "components"
|
} from "components"
|
||||||
import { DOMWindow } from "components/RenderWindow"
|
import { DOMWindow } from "components/RenderWindow"
|
||||||
|
|
||||||
@ -222,7 +221,7 @@ class ComtyApp extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return window.app.ModalController.open((props) => <Searcher renderResults {...props} />)
|
return app.layout.modal.open("searcher", () => <Searcher renderResults />)
|
||||||
},
|
},
|
||||||
openFullImageViewer: (src) => {
|
openFullImageViewer: (src) => {
|
||||||
const win = new DOMWindow({
|
const win = new DOMWindow({
|
||||||
@ -239,22 +238,10 @@ class ComtyApp extends React.Component {
|
|||||||
/>)
|
/>)
|
||||||
},
|
},
|
||||||
openPostViewer: (post) => {
|
openPostViewer: (post) => {
|
||||||
const win = new DOMWindow({
|
app.layout.modal.open("post_viewer", () => <PostViewer post={post} />)
|
||||||
id: "postViewer",
|
|
||||||
className: "postViewer",
|
|
||||||
})
|
|
||||||
|
|
||||||
win.render(<PostViewer post={post} />)
|
|
||||||
},
|
},
|
||||||
openPostCreator: () => {
|
openPostCreator: () => {
|
||||||
const win = new DOMWindow({
|
app.layout.modal.open("post_creator", () => <PostCreator />)
|
||||||
id: "postCreator",
|
|
||||||
className: "postCreator",
|
|
||||||
})
|
|
||||||
|
|
||||||
win.render(<PostCreatorModal
|
|
||||||
onClose={() => win.destroy()}
|
|
||||||
/>)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
navigation: {
|
navigation: {
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
import React from "react"
|
|
||||||
import classnames from "classnames"
|
|
||||||
|
|
||||||
import PostCreator from "components/PostCreator"
|
|
||||||
|
|
||||||
import "./index.less"
|
|
||||||
|
|
||||||
export default (props) => {
|
|
||||||
const [visible, setVisible] = React.useState(false)
|
|
||||||
|
|
||||||
let escTimeout = null
|
|
||||||
|
|
||||||
const close = () => {
|
|
||||||
setVisible(false)
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
if (typeof props.onClose === "function") {
|
|
||||||
props.onClose()
|
|
||||||
}
|
|
||||||
}, 150)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleEsc = (e) => {
|
|
||||||
if (e.key === "Escape") {
|
|
||||||
if (escTimeout !== null) {
|
|
||||||
clearTimeout(escTimeout)
|
|
||||||
return close()
|
|
||||||
}
|
|
||||||
|
|
||||||
escTimeout = setTimeout(() => {
|
|
||||||
escTimeout = null
|
|
||||||
}, 250)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleClickOutside = (e) => {
|
|
||||||
if (e.target === e.currentTarget) {
|
|
||||||
close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
setTimeout(() => {
|
|
||||||
setVisible(true)
|
|
||||||
}, 10)
|
|
||||||
|
|
||||||
document.addEventListener("keydown", handleEsc, false)
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener("keydown", handleEsc, false)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return <div
|
|
||||||
className={classnames(
|
|
||||||
"post_creator_modal",
|
|
||||||
{
|
|
||||||
["active"]: visible
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
onClick={handleClickOutside}
|
|
||||||
>
|
|
||||||
<PostCreator
|
|
||||||
onPost={close}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
@import "theme/vars.less";
|
|
||||||
|
|
||||||
@modal_background_blur: 10px;
|
|
||||||
|
|
||||||
.post_creator_modal {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
|
|
||||||
transition: all 150ms ease-in-out;
|
|
||||||
|
|
||||||
&.active {
|
|
||||||
background-color: rgba(var(--bg_color_6), 0.5);
|
|
||||||
|
|
||||||
backdrop-filter: blur(@modal_background_blur);
|
|
||||||
-webkit-backdrop-filter: blur(@modal_background_blur);
|
|
||||||
|
|
||||||
.postCreator {
|
|
||||||
opacity: 1;
|
|
||||||
transform: translateY(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.postCreator {
|
|
||||||
transition: all 150ms ease-in-out;
|
|
||||||
|
|
||||||
opacity: 0;
|
|
||||||
transform: translateY(100px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.postCreator {
|
|
||||||
box-shadow: @card-shadow;
|
|
||||||
-webkit-box-shadow: @card-shadow;
|
|
||||||
-moz-box-shadow: @card-shadow;
|
|
||||||
}
|
|
||||||
}
|
|
@ -227,5 +227,5 @@ const UserSelector = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const openModal = (props) => {
|
export const openModal = (props) => {
|
||||||
return app.ModalController.open(() => <UserSelector {...props} />)
|
return app.layout.modal.open("user_selector", () => <UserSelector {...props} />)
|
||||||
}
|
}
|
@ -4,6 +4,12 @@
|
|||||||
|
|
||||||
gap: 20px;
|
gap: 20px;
|
||||||
|
|
||||||
|
padding: 20px;
|
||||||
|
|
||||||
|
background-color: var(--background-color-accent);
|
||||||
|
|
||||||
|
border-radius: 12px;
|
||||||
|
|
||||||
.user-selector_actions {
|
.user-selector_actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
@ -96,5 +96,5 @@ export const WidgetBrowser = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const openModal = () => {
|
export const openModal = () => {
|
||||||
app.ModalController.open(() => <WidgetBrowser />)
|
app.layout.modal.open("widgets_browser", () => <WidgetBrowser />)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
.widgets_browser {
|
.widgets_browser {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
gap: 20px;
|
gap: 20px;
|
||||||
|
|
||||||
|
padding: 30px;
|
||||||
|
|
||||||
|
background-color: var(--background-color-accent);
|
||||||
|
|
||||||
|
border-radius: 12px;
|
||||||
}
|
}
|
@ -40,7 +40,6 @@ export { default as PostsList } from "./PostsList"
|
|||||||
export { default as PostCard } from "./PostCard"
|
export { default as PostCard } from "./PostCard"
|
||||||
export { default as PostViewer } from "./PostViewer"
|
export { default as PostViewer } from "./PostViewer"
|
||||||
export { default as PostCreator } from "./PostCreator"
|
export { default as PostCreator } from "./PostCreator"
|
||||||
export { default as PostCreatorModal } from "./PostCreatorModal"
|
|
||||||
|
|
||||||
// COMMENTS
|
// COMMENTS
|
||||||
export { default as CommentsCard } from "./CommentsCard"
|
export { default as CommentsCard } from "./CommentsCard"
|
||||||
|
123
packages/app/src/layouts/components/modals/index.jsx
Normal file
123
packages/app/src/layouts/components/modals/index.jsx
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
import React from "react"
|
||||||
|
import classnames from "classnames"
|
||||||
|
import useLayoutInterface from "hooks/useLayoutInterface"
|
||||||
|
import { DOMWindow } from "components/RenderWindow"
|
||||||
|
|
||||||
|
import "./index.less"
|
||||||
|
|
||||||
|
class Modal extends React.Component {
|
||||||
|
state = {
|
||||||
|
visible: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
escTimeout = null
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.setState({
|
||||||
|
visible: true,
|
||||||
|
})
|
||||||
|
}, 10)
|
||||||
|
|
||||||
|
document.addEventListener("keydown", this.handleEsc, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
document.removeEventListener("keydown", this.handleEsc, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
close = () => {
|
||||||
|
this.setState({
|
||||||
|
visible: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (typeof this.props.onClose === "function") {
|
||||||
|
this.props.onClose()
|
||||||
|
}
|
||||||
|
}, 250)
|
||||||
|
}
|
||||||
|
|
||||||
|
handleEsc = (e) => {
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
if (this.escTimeout !== null) {
|
||||||
|
clearTimeout(this.escTimeout)
|
||||||
|
return this.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.escTimeout = setTimeout(() => {
|
||||||
|
this.escTimeout = null
|
||||||
|
}, 250)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClickOutside = (e) => {
|
||||||
|
if (e.target === e.currentTarget) {
|
||||||
|
this.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <div
|
||||||
|
className={classnames(
|
||||||
|
"app_modal_wrapper",
|
||||||
|
{
|
||||||
|
["active"]: this.state.visible
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
onClick={this.handleClickOutside}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="app_modal_content"
|
||||||
|
onClick={this.handleClickOutside}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
React.cloneElement(this.props.children, {
|
||||||
|
close: this.close
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const modalRef = React.useRef()
|
||||||
|
|
||||||
|
function openModal(
|
||||||
|
id,
|
||||||
|
render,
|
||||||
|
{
|
||||||
|
className,
|
||||||
|
props,
|
||||||
|
} = {}
|
||||||
|
) {
|
||||||
|
const win = new DOMWindow({
|
||||||
|
id: id,
|
||||||
|
className: className,
|
||||||
|
})
|
||||||
|
|
||||||
|
win.render(<Modal
|
||||||
|
ref={modalRef}
|
||||||
|
win={win}
|
||||||
|
onClose={() => {
|
||||||
|
win.destroy()
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
React.createElement(render, props)
|
||||||
|
}
|
||||||
|
</Modal>)
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeModal() {
|
||||||
|
modalRef.current.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
useLayoutInterface("modal", {
|
||||||
|
open: openModal,
|
||||||
|
close: closeModal,
|
||||||
|
})
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
@ -2,13 +2,16 @@ import React from "react"
|
|||||||
import classnames from "classnames"
|
import classnames from "classnames"
|
||||||
import { Layout } from "antd"
|
import { Layout } from "antd"
|
||||||
|
|
||||||
import { Sidebar, Drawer, Sidedrawer, Modal, BottomBar, TopBar, ToolsBar } from "components/Layout"
|
import { Sidebar, Drawer, Sidedrawer, BottomBar, TopBar, ToolsBar } from "components/Layout"
|
||||||
|
|
||||||
import BackgroundDecorator from "components/BackgroundDecorator"
|
import BackgroundDecorator from "components/BackgroundDecorator"
|
||||||
|
|
||||||
import { createWithDom as FloatingStack } from "../components/floatingStack"
|
import { createWithDom as FloatingStack } from "../components/floatingStack"
|
||||||
|
import InitializeModalsController from "../components/modals"
|
||||||
|
|
||||||
const DesktopLayout = (props) => {
|
const DesktopLayout = (props) => {
|
||||||
|
InitializeModalsController()
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const floatingStack = FloatingStack()
|
const floatingStack = FloatingStack()
|
||||||
|
|
||||||
@ -21,7 +24,6 @@ const DesktopLayout = (props) => {
|
|||||||
<BackgroundDecorator />
|
<BackgroundDecorator />
|
||||||
|
|
||||||
<Layout id="app_layout" className="app_layout">
|
<Layout id="app_layout" className="app_layout">
|
||||||
<Modal />
|
|
||||||
<Drawer />
|
<Drawer />
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
<Sidedrawer />
|
<Sidedrawer />
|
||||||
@ -47,8 +49,6 @@ const DesktopLayout = (props) => {
|
|||||||
|
|
||||||
const MobileLayout = (props) => {
|
const MobileLayout = (props) => {
|
||||||
return <Layout id="app_layout" className="app_layout">
|
return <Layout id="app_layout" className="app_layout">
|
||||||
<Modal />
|
|
||||||
|
|
||||||
<TopBar />
|
<TopBar />
|
||||||
|
|
||||||
<Layout.Content
|
<Layout.Content
|
||||||
|
@ -405,3 +405,60 @@ html {
|
|||||||
background-color: transparent !important;
|
background-color: transparent !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.app_modal_wrapper {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
transition: all 150ms ease-in-out;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background-color: rgba(var(--bg_color_6), 0.5);
|
||||||
|
|
||||||
|
backdrop-filter: blur(@modal_background_blur);
|
||||||
|
-webkit-backdrop-filter: blur(@modal_background_blur);
|
||||||
|
|
||||||
|
.app_modal_content {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.app_modal_content {
|
||||||
|
transition: all 150ms ease-in-out;
|
||||||
|
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(100px);
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
// fixments
|
||||||
|
.postCreator {
|
||||||
|
box-shadow: @card-shadow;
|
||||||
|
-webkit-box-shadow: @card-shadow;
|
||||||
|
-moz-box-shadow: @card-shadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
.searcher {
|
||||||
|
width: 50vw;
|
||||||
|
height: 80vh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,3 +16,5 @@
|
|||||||
|
|
||||||
@bottomBar_iconSize: 45px;
|
@bottomBar_iconSize: 45px;
|
||||||
@topBar_height: 52px;
|
@topBar_height: 52px;
|
||||||
|
|
||||||
|
@modal_background_blur: 10px;
|
Loading…
x
Reference in New Issue
Block a user