mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
Cancel update call is component will be unmounted
This commit is contained in:
@@ -25,6 +25,10 @@ type Props = WithTranslation & {
|
|||||||
match: any;
|
match: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type State = {
|
||||||
|
stoppableUpdateHandler?: number;
|
||||||
|
}
|
||||||
|
|
||||||
const FixedWidthTh = styled.th`
|
const FixedWidthTh = styled.th`
|
||||||
width: 16px;
|
width: 16px;
|
||||||
`;
|
`;
|
||||||
@@ -41,11 +45,26 @@ export function findParent(path: string) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
class FileTree extends React.Component<Props> {
|
class FileTree extends React.Component<Props, State> {
|
||||||
componentDidUpdate(prevProps: Readonly<Props>, prevState: Readonly<{}>, snapshot?: any): void {
|
|
||||||
const { tree, updateSources } = this.props;
|
constructor(props: Props) {
|
||||||
if (tree?._embedded?.children && tree._embedded.children.find(c => c.partialResult)) {
|
super(props);
|
||||||
setTimeout(updateSources, 3000);
|
this.state = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps: Readonly<Props>, prevState: Readonly<State>): void {
|
||||||
|
if (prevState.stoppableUpdateHandler === this.state.stoppableUpdateHandler) {
|
||||||
|
const {tree, updateSources} = this.props;
|
||||||
|
if (tree?._embedded?.children && tree._embedded.children.find(c => c.partialResult)) {
|
||||||
|
const stoppableUpdateHandler = setTimeout(updateSources, 3000);
|
||||||
|
this.setState({stoppableUpdateHandler: stoppableUpdateHandler});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount(): void {
|
||||||
|
if (this.state.stoppableUpdateHandler) {
|
||||||
|
clearTimeout(this.state.stoppableUpdateHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user