Skip to content

Commit

Permalink
卸载修改为.unmount()
Browse files Browse the repository at this point in the history
  • Loading branch information
luoluoTH committed Dec 28, 2023
1 parent c50e4f3 commit 11ca99a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ export const showYakitDrawer = (props: ShowDrawerProps) => {
onVisibleSetter={(r) => {
setter = r
}}
// afterClose={() => {
// if (props.modalAfterClose) props.modalAfterClose()
// const unmountResult = ReactDOM.unmountComponentAtNode(div)
// if (unmountResult && div.parentNode) {
// div.parentNode.removeChild(div)
// }
// }}
>
<ErrorBoundary
FallbackComponent={({error, resetErrorBoundary}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ export const YakitModalConfirm = (props: YakitModalConfirmProps) => {
}}
afterClose={() => {
if (props.modalAfterClose) props.modalAfterClose()
const unmountResult = ReactDOM.unmountComponentAtNode(div)
if (unmountResult && div.parentNode) {
div.parentNode.removeChild(div)
}
setTimeout(() => {
if (yakitModalConfirmRootDiv) {
yakitModalConfirmRootDiv.unmount()
}
})
}}
title={null}
headerStyle={{paddingBottom: 0}}
Expand Down Expand Up @@ -221,10 +222,11 @@ export const showYakitModal = (props: ShowModalProps) => {
}}
afterClose={() => {
if (props.modalAfterClose) props.modalAfterClose()
const unmountResult = ReactDOM.unmountComponentAtNode(div)
if (unmountResult && div.parentNode) {
div.parentNode.removeChild(div)
}
setTimeout(() => {
if (yakitModalRootDiv) {
yakitModalRootDiv.unmount()
}
})
}}
>
<ErrorBoundary
Expand Down
16 changes: 10 additions & 6 deletions app/renderer/src/main/src/utils/showByCursor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ export const showByCursorMenu = (props: ByCursorMenuProp, x: number, y: number)
div.id = cursorMenuId
div.className = "popup"
document.body.appendChild(div)

let cursorMenuRootDiv
const destory = () => {
const unmountResult = ReactDOM.unmountComponentAtNode(div)
if (unmountResult && div.parentNode) {
div.parentNode.removeChild(div)
if (cursorMenuRootDiv) {
cursorMenuRootDiv.unmount()
}
}

Expand All @@ -98,8 +97,12 @@ export const showByCursorMenu = (props: ByCursorMenuProp, x: number, y: number)
destory()
document.removeEventListener("click", onClickOutsize)
})
if ((props.content || []).length > 0)
createRoot(div).render(
if ((props.content || []).length > 0) {
if (!cursorMenuRootDiv) {
cursorMenuRootDiv = createRoot(div)
}

cursorMenuRootDiv.render(
<Menu
className={"right-cursor-menu"}
onClick={(item: {key: string}) => {
Expand Down Expand Up @@ -147,6 +150,7 @@ export const showByCursorMenu = (props: ByCursorMenuProp, x: number, y: number)
})}
</Menu>
)
}
})
}
render()
Expand Down
18 changes: 10 additions & 8 deletions app/renderer/src/main/src/utils/showModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ export const showModal = (props: ShowModalProps) => {
}}
afterClose={() => {
if (props.modalAfterClose) props.modalAfterClose()
const unmountResult = ReactDOM.unmountComponentAtNode(div)
if (unmountResult && div.parentNode) {
div.parentNode.removeChild(div)
}
setTimeout(() => {
if (modalRootDiv) {
modalRootDiv.unmount()
}
})
}}
>
<ErrorBoundary
Expand Down Expand Up @@ -166,10 +167,11 @@ export const showDrawer = (props: ShowDrawerProps) => {
onDestroy = setter
}}
afterClose={() => {
const unmountResult = ReactDOM.unmountComponentAtNode(div)
if (unmountResult && div.parentNode) {
div.parentNode.removeChild(div)
}
setTimeout(() => {
if (drawerRootDiv) {
drawerRootDiv.unmount()
}
})
}}
>
{targetConfig.content}
Expand Down

0 comments on commit 11ca99a

Please sign in to comment.