未验证 提交 d556a76f 编写于 作者: P Peter Pan 提交者: GitHub

fix: selected model missing when switch between pages (#922)

上级 23d63937
...@@ -22,11 +22,11 @@ const RunList: FunctionComponent<{count?: number}> = ({count}) => { ...@@ -22,11 +22,11 @@ const RunList: FunctionComponent<{count?: number}> = ({count}) => {
return ( return (
<ContentLoader viewBox={`0 0 220 ${(count ?? 2) * 36}`}> <ContentLoader viewBox={`0 0 220 ${(count ?? 2) * 36}`}>
{Array.from({length: count ?? 2}).map((_, i) => ( {Array.from({length: count ?? 2}).map((_, i) => (
<> <React.Fragment key={i}>
<rect x="0" y={`${11 * (i + 1) + 25 * i + 4.5}`} width="16" height="16" /> <rect x="0" y={`${11 * (i + 1) + 25 * i + 4.5}`} width="16" height="16" />
<circle cx="32" cy={`${11 * (i + 1) + 25 * i + 12.5}`} r="6" /> <circle cx="32" cy={`${11 * (i + 1) + 25 * i + 12.5}`} r="6" />
<rect x="46" y={`${11 * (i + 1) + 25 * i + 5.5}`} rx="3" ry="3" width="100" height="14" /> <rect x="46" y={`${11 * (i + 1) + 25 * i + 5.5}`} rx="3" ry="3" width="100" height="14" />
</> </React.Fragment>
))} ))}
</ContentLoader> </ContentLoader>
); );
......
...@@ -94,6 +94,13 @@ const Graph: FunctionComponent = () => { ...@@ -94,6 +94,13 @@ const Graph: FunctionComponent = () => {
const graph = useRef<GraphRef>(null); const graph = useRef<GraphRef>(null);
const file = useRef<HTMLInputElement>(null); const file = useRef<HTMLInputElement>(null);
const [files, setFiles] = useState<FileList | File[] | null>(storeModel); const [files, setFiles] = useState<FileList | File[] | null>(storeModel);
const setModelFile = useCallback(
(f: FileList | File[]) => {
storeDispatch(actions.graph.setModel(f));
setFiles(f);
},
[storeDispatch]
);
const onClickFile = useCallback(() => { const onClickFile = useCallback(() => {
if (file.current) { if (file.current) {
file.current.value = ''; file.current.value = '';
...@@ -104,11 +111,10 @@ const Graph: FunctionComponent = () => { ...@@ -104,11 +111,10 @@ const Graph: FunctionComponent = () => {
(e: React.ChangeEvent<HTMLInputElement>) => { (e: React.ChangeEvent<HTMLInputElement>) => {
const target = e.target; const target = e.target;
if (target && target.files && target.files.length) { if (target && target.files && target.files.length) {
storeDispatch(actions.graph.setModel(target.files)); setModelFile(target.files);
setFiles(target.files);
} }
}, },
[storeDispatch] [setModelFile]
); );
const {data, loading} = useRequest<BlobResponse>(files ? null : '/graph/graph'); const {data, loading} = useRequest<BlobResponse>(files ? null : '/graph/graph');
...@@ -280,7 +286,10 @@ const Graph: FunctionComponent = () => { ...@@ -280,7 +286,10 @@ const Graph: FunctionComponent = () => {
nodeDocumentation nodeDocumentation
]); ]);
const uploader = useMemo(() => <Uploader onClickUpload={onClickFile} onDropFiles={setFiles} />, [onClickFile]); const uploader = useMemo(() => <Uploader onClickUpload={onClickFile} onDropFiles={setModelFile} />, [
onClickFile,
setModelFile
]);
return ( return (
<> <>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册