ui: fix problem page react unmount

pull/420/head
undefined 2 years ago
parent e2415a75c3
commit 35b0463173

@ -1,3 +0,0 @@
const fs = require('fs-extra');
fs.removeSync('node_modules/@types/express/node_modules');

@ -24,7 +24,7 @@
"debug": "node --trace-warnings --async-stack-traces --trace-deprecation node_modules/hydrooj/bin/hydrooj --debug --template", "debug": "node --trace-warnings --async-stack-traces --trace-deprecation node_modules/hydrooj/bin/hydrooj --debug --template",
"start:all": "node build/start", "start:all": "node build/start",
"start": "node_modules/.bin/hydrooj", "start": "node_modules/.bin/hydrooj",
"postinstall": "node build/hack && node build/prepare.js" "postinstall": "node build/prepare.js"
}, },
"version": "1.0.0", "version": "1.0.0",
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
@ -61,6 +61,6 @@
"ora": "^6.1.2", "ora": "^6.1.2",
"semver": "^7.3.7", "semver": "^7.3.7",
"supertest": "^6.2.4", "supertest": "^6.2.4",
"typescript": "4.8.2" "typescript": "4.7.4"
} }
} }

@ -24,6 +24,7 @@ export default class AutoComplete extends DOMAttachedObject {
ref = null; ref = null;
container = document.createElement('div'); container = document.createElement('div');
options: AutoCompleteOptions; options: AutoCompleteOptions;
component = ReactDOM.createRoot(this.container);
changeListener = [ changeListener = [
(val) => this.$dom.val(val), (val) => this.$dom.val(val),
]; ];
@ -64,7 +65,7 @@ export default class AutoComplete extends DOMAttachedObject {
attach() { attach() {
const value = this.$dom.val(); const value = this.$dom.val();
ReactDOM.createRoot(this.container).render( this.component.render(
<AutoCompleteFC <AutoCompleteFC
ref={(ref) => { this.ref = ref; }} ref={(ref) => { this.ref = ref; }}
height="34px" height="34px"
@ -97,7 +98,7 @@ export default class AutoComplete extends DOMAttachedObject {
detach() { detach() {
if (this.detached) return; if (this.detached) return;
super.detach(); super.detach();
ReactDOM.unmountComponentAtNode(this.container); this.component.unmount();
this.$dom.removeClass('autocomplete-dummy'); this.$dom.removeClass('autocomplete-dummy');
this.container.parentNode.removeChild(this.container); this.container.parentNode.removeChild(this.container);
} }

@ -2,15 +2,10 @@ import $ from 'jquery';
import { omit } from 'lodash'; import { omit } from 'lodash';
import React from 'react'; import React from 'react';
const tempDoms = {}; export default function DomComponent(props: React.HTMLAttributes<HTMLDivElement> & { childDom: HTMLElement }) {
export default function DomComponent(props: React.HTMLAttributes<HTMLDivElement> & { id?: string, childDom: HTMLElement }) {
const ref = React.useRef<HTMLDivElement>(); const ref = React.useRef<HTMLDivElement>();
React.useEffect(() => { React.useEffect(() => {
let dom = props.childDom; ref.current.appendChild(props.childDom);
if (props.id && dom) tempDoms[props.id] = dom;
else if (props.id && !dom && tempDoms[props.id]) dom = tempDoms[props.id];
ref.current.appendChild(dom);
return () => { return () => {
$(ref.current).empty(); $(ref.current).empty();
}; };

@ -35,7 +35,7 @@ function buildNestedPane([a, ...panes], mode = 'horizontal') {
const pages = { const pages = {
problem: { problem: {
icon: () => <ProblemIcon />, icon: () => <ProblemIcon />,
component: () => <Dom childDom={$('.problem-content').get(0)} id="problem-content" />, component: () => <Dom childDom={$('.problem-content').get(0)} />,
}, },
}; };

@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.39.13", "version": "4.39.14",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",

Loading…
Cancel
Save