-
Notifications
You must be signed in to change notification settings - Fork 29
Refactored several React class components as functional components #8750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
02ceb7f
Refactored several React class components as functional components
hotzenklotz e880401
apply coderabbit feedback
hotzenklotz 578e0cd
Update frontend/javascripts/components/fixed_expandable_table.tsx
hotzenklotz c450bc3
Update frontend/javascripts/components/fixed_expandable_table.tsx
hotzenklotz f583e5a
apply PR feedback
hotzenklotz 5edbe73
Merge branch 'master' of github.com:scalableminds/webknossos into rea…
hotzenklotz 9826776
replace useFetch with useQuery
hotzenklotz d20c088
appled CodeRabbit PR feedback
hotzenklotz db72024
Merge branch 'master' into reafactor_components
hotzenklotz 0fd0b7a
Merge branch 'master' into reafactor_components
hotzenklotz eb773a6
Merge branch 'master' into reafactor_components
hotzenklotz 58d1ba5
Merge branch 'master' into reafactor_components
hotzenklotz c17beae
Merge branch 'master' into reafactor_components
hotzenklotz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
import window from "libs/window"; | ||
import React from "react"; | ||
import type { EmptyObject } from "types/globals"; | ||
export default class DisableGenericDnd extends React.Component<EmptyObject> { | ||
componentDidMount() { | ||
window.addEventListener("dragover", this.preventDefault, false); | ||
window.addEventListener("drop", this.preventDefault, false); | ||
} | ||
|
||
componentWillUnmount() { | ||
window.removeEventListener("dragover", this.preventDefault); | ||
window.removeEventListener("drop", this.preventDefault); | ||
} | ||
const preventDefault = (e: Event) => { | ||
e.preventDefault(); | ||
}; | ||
|
||
preventDefault = (e: Event) => { | ||
e.preventDefault(); | ||
}; | ||
export default function DisableGenericDnd() { | ||
React.useEffect(() => { | ||
window.addEventListener("dragover", preventDefault, false); | ||
window.addEventListener("drop", preventDefault, false); | ||
|
||
render() { | ||
return null; | ||
} | ||
return () => { | ||
window.removeEventListener("dragover", preventDefault); | ||
window.removeEventListener("drop", preventDefault); | ||
}; | ||
}, []); | ||
|
||
return null; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,28 @@ | ||
import * as React from "react"; | ||
import type React from "react"; | ||
import { useState } from "react"; | ||
|
||
type Props = { | ||
shouldHighlight: boolean; | ||
children: React.ReactNode; | ||
style?: Record<string, any>; | ||
}; | ||
type State = { | ||
persistedShouldHighlight: boolean; | ||
}; // This component is able to highlight a newly rendered row. | ||
|
||
// This component is able to highlight a newly rendered row. | ||
// Internally, it persists the initially passed props, since that | ||
// prop can change faster than the animation is executed. Not saving | ||
// the initial prop, would abort the animation too early. | ||
export default function HighlightableRow({ shouldHighlight, style, ...restProps }: Props) { | ||
const [persistedShouldHighlight] = useState(shouldHighlight); | ||
|
||
export default class HighlightableRow extends React.PureComponent<Props, State> { | ||
state: State = { | ||
persistedShouldHighlight: this.props.shouldHighlight, | ||
}; | ||
|
||
render() { | ||
const { shouldHighlight, style, ...restProps } = this.props; | ||
return ( | ||
<tr | ||
{...restProps} | ||
style={{ | ||
...style, | ||
animation: this.state.persistedShouldHighlight ? "highlight-background 2.0s ease" : "", | ||
}} | ||
> | ||
{this.props.children} | ||
</tr> | ||
); | ||
} | ||
return ( | ||
<tr | ||
{...restProps} | ||
style={{ | ||
...style, | ||
animation: persistedShouldHighlight ? "highlight-background 2.0s ease" : "", | ||
}} | ||
> | ||
{restProps.children} | ||
</tr> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,19 @@ | ||
import window from "libs/window"; | ||
import { Component } from "react"; | ||
import type { EmptyObject } from "types/globals"; | ||
import { useEffect } from "react"; | ||
|
||
type LoopProps = { | ||
interval: number; | ||
onTick: (...args: Array<any>) => any; | ||
}; | ||
|
||
class Loop extends Component<LoopProps, EmptyObject> { | ||
intervalId: number | null | undefined = null; | ||
|
||
componentDidMount() { | ||
this.intervalId = window.setInterval(this.props.onTick, this.props.interval); | ||
} | ||
export default function Loop({ interval, onTick }: LoopProps) { | ||
useEffect(() => { | ||
const intervalId = window.setInterval(onTick, interval); | ||
|
||
componentWillUnmount() { | ||
if (this.intervalId != null) { | ||
window.clearInterval(this.intervalId); | ||
this.intervalId = null; | ||
} | ||
} | ||
return () => { | ||
window.clearInterval(intervalId); | ||
}; | ||
}, [interval, onTick]); | ||
|
||
render() { | ||
return null; | ||
} | ||
return null; | ||
} | ||
|
||
export default Loop; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.