Skip to content

Commit

Permalink
chore: Refactor ConfirmDialog component in theme.script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ohitstom committed Jul 4, 2024
1 parent 0c016e8 commit d877e70
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Comfy/theme.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,30 @@ todo:
const Dialog = Spicetify.React.memo(props => {
const [state, setState] = Spicetify.React.useState(true);
const self = document.querySelector(".ReactModalPortal:last-of-type");

Spicetify.React.useEffect(() => {
if (state) {
props.onOpen?.();
}
}, [state]);

return Spicetify.ReactComponent.ConfirmDialog({
const ConfirmDialog = Spicetify.ReactComponent.ConfirmDialog;
const isForwardRef = typeof ConfirmDialog === "function";
const commonProps = {
...props,
isOpen: state,
onClose: () => {
setState(false);
props.onClose();
props.onClose?.();
self.remove();
},
onConfirm: () => {
setState(false);
props.onConfirm();
props.onConfirm?.();
self.remove();
}
});
};

Spicetify.React.useEffect(() => {
if (state) {
props.onOpen?.();
}
}, [state]);

return isForwardRef ? ConfirmDialog(commonProps) : Spicetify.React.createElement(ConfirmDialog, commonProps);
});

const Section = ({ name, children, condition = true, filter }) => {
Expand Down

0 comments on commit d877e70

Please sign in to comment.