feat: deferred loadImage
This commit is contained in:
parent
dee40ebdb6
commit
44bc27b567
@ -1,6 +1,22 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { baseUrl } from "./api";
|
import { baseUrl } from "./api";
|
||||||
|
|
||||||
|
//const debounce = <T extends (...args: any[]) => void>(
|
||||||
|
// func: T,
|
||||||
|
// delay: number
|
||||||
|
//): ((...args: Parameters<T>) => void) => {
|
||||||
|
// let timeoutId: number | null = null;
|
||||||
|
// return (...args: Parameters<T>) => {
|
||||||
|
// if (timeoutId !== null) {
|
||||||
|
// clearTimeout(timeoutId);
|
||||||
|
// }
|
||||||
|
// console.log(timeoutId);
|
||||||
|
// timeoutId = setTimeout(() => {
|
||||||
|
// func(...args);
|
||||||
|
// }, delay);
|
||||||
|
// };
|
||||||
|
//};
|
||||||
|
//
|
||||||
interface Prop {
|
interface Prop {
|
||||||
name: string;
|
name: string;
|
||||||
min: string;
|
min: string;
|
||||||
@ -19,6 +35,13 @@ interface Params {
|
|||||||
popularity: boolean;
|
popularity: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DeferredProps {
|
||||||
|
timeout: number;
|
||||||
|
func: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let timeoutID: number | null = null;
|
||||||
export default function Analysis() {
|
export default function Analysis() {
|
||||||
const [image, setImage] = useState("");
|
const [image, setImage] = useState("");
|
||||||
const [params, setParams] = useState<Params>({
|
const [params, setParams] = useState<Params>({
|
||||||
@ -50,8 +73,15 @@ export default function Analysis() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (timeoutID) {
|
||||||
|
console.log(timeoutID);
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
}
|
||||||
|
timeoutID = setTimeout(() => {
|
||||||
|
console.log("fire");
|
||||||
loadImage();
|
loadImage();
|
||||||
}, []);
|
}, 1500);
|
||||||
|
}, [params]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="stack column dropdown">
|
<div className="stack column dropdown">
|
||||||
@ -62,21 +92,21 @@ export default function Analysis() {
|
|||||||
|
|
||||||
<div className="control">
|
<div className="control">
|
||||||
<div className="checkBox">
|
<div className="checkBox">
|
||||||
<label>weighting</label>
|
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={params.weighting}
|
checked={params.weighting}
|
||||||
onChange={(evt) => setParams({ ...params, weighting: evt.target.checked })}
|
onChange={(evt) => setParams({ ...params, weighting: evt.target.checked })}
|
||||||
onMouseUp={() => loadImage()}
|
/>
|
||||||
/></div>
|
<label>weighting</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="checkBox">
|
<div className="checkBox">
|
||||||
<label>popularity</label>
|
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={params.popularity}
|
checked={params.popularity}
|
||||||
onChange={(evt) => { setParams({ ...params, popularity: evt.target.checked }); loadImage() }}
|
onChange={(evt) => setParams({ ...params, popularity: evt.target.checked })}
|
||||||
/>
|
/>
|
||||||
|
<label>popularity</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -89,7 +119,6 @@ export default function Analysis() {
|
|||||||
step="0.05"
|
step="0.05"
|
||||||
value={params.distance}
|
value={params.distance}
|
||||||
onChange={(evt) => setParams({ ...params, distance: Number(evt.target.value) })}
|
onChange={(evt) => setParams({ ...params, distance: Number(evt.target.value) })}
|
||||||
onMouseUp={() => loadImage()}
|
|
||||||
/>
|
/>
|
||||||
<span>{params.distance}</span></div>
|
<span>{params.distance}</span></div>
|
||||||
|
|
||||||
@ -101,7 +130,6 @@ export default function Analysis() {
|
|||||||
max="3000"
|
max="3000"
|
||||||
value={params.nodeSize}
|
value={params.nodeSize}
|
||||||
onChange={(evt) => setParams({ ...params, nodeSize: Number(evt.target.value) })}
|
onChange={(evt) => setParams({ ...params, nodeSize: Number(evt.target.value) })}
|
||||||
onMouseUp={() => loadImage()}
|
|
||||||
/>
|
/>
|
||||||
<span>{params.nodeSize}</span>
|
<span>{params.nodeSize}</span>
|
||||||
</div>
|
</div>
|
||||||
@ -114,7 +142,6 @@ export default function Analysis() {
|
|||||||
max="24"
|
max="24"
|
||||||
value={params.fontSize}
|
value={params.fontSize}
|
||||||
onChange={(evt) => setParams({ ...params, fontSize: Number(evt.target.value) })}
|
onChange={(evt) => setParams({ ...params, fontSize: Number(evt.target.value) })}
|
||||||
onMouseUp={() => loadImage()}
|
|
||||||
/>
|
/>
|
||||||
<span>{params.fontSize}</span>
|
<span>{params.fontSize}</span>
|
||||||
</div>
|
</div>
|
||||||
@ -128,7 +155,6 @@ export default function Analysis() {
|
|||||||
step="0.1"
|
step="0.1"
|
||||||
value={params.edgeWidth}
|
value={params.edgeWidth}
|
||||||
onChange={(evt) => setParams({ ...params, edgeWidth: Number(evt.target.value) })}
|
onChange={(evt) => setParams({ ...params, edgeWidth: Number(evt.target.value) })}
|
||||||
onMouseUp={() => loadImage()}
|
|
||||||
/>
|
/>
|
||||||
<span>{params.edgeWidth}</span>
|
<span>{params.edgeWidth}</span>
|
||||||
</div>
|
</div>
|
||||||
@ -141,7 +167,6 @@ export default function Analysis() {
|
|||||||
max="50"
|
max="50"
|
||||||
value={params.arrowSize}
|
value={params.arrowSize}
|
||||||
onChange={(evt) => setParams({ ...params, arrowSize: Number(evt.target.value) })}
|
onChange={(evt) => setParams({ ...params, arrowSize: Number(evt.target.value) })}
|
||||||
onMouseUp={() => loadImage()}
|
|
||||||
/>
|
/>
|
||||||
<span>{params.arrowSize}</span>
|
<span>{params.arrowSize}</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -148,7 +148,7 @@ button {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
border: 2px solid #404040;
|
border: 2px solid #404040;
|
||||||
padding: 8px;
|
padding: 8px 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 1000px) {
|
@media only screen and (max-width: 1000px) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user