Skip to content

Commit

Permalink
chore: diminish duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrokohler committed Nov 25, 2024
1 parent f426dd1 commit b0405f8
Showing 1 changed file with 23 additions and 36 deletions.
59 changes: 23 additions & 36 deletions src/components/ColorSettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ ColorSettingsMenuState
}
})
})
this.setState({
currentStyle: {
opacity: value,
color: this.state.currentStyle.color,
contourOnly: this.state.currentStyle.contourOnly
}
})
this.updateCurrentStyle({ opacity: value })
}
}

Expand All @@ -71,13 +65,7 @@ ColorSettingsMenuState
this.state.currentStyle.color[1],
this.state.currentStyle.color[2]
]
this.setState((state) => ({
currentStyle: {
color: color,
opacity: state.currentStyle.opacity,
contourOnly: state.currentStyle.contourOnly
}
}))
this.updateCurrentStyle({ color })
this.props.annotationGroupsUIDs.forEach((uid) => {
this.props.onStyleChange({
uid,
Expand All @@ -98,13 +86,7 @@ ColorSettingsMenuState
Array.isArray(value) ? value[0] : value,
this.state.currentStyle.color[2]
]
this.setState((state) => ({
currentStyle: {
color: color,
opacity: state.currentStyle.opacity,
contourOnly: state.currentStyle.contourOnly
}
}))
this.updateCurrentStyle({ color })
this.props.annotationGroupsUIDs.forEach((uid) => {
this.props.onStyleChange({
uid,
Expand All @@ -125,14 +107,7 @@ ColorSettingsMenuState
this.state.currentStyle.color[1],
Array.isArray(value) ? value[0] : value
]
this.setState((state) => ({
currentStyle: {
color: color,
opacity: state.currentStyle.opacity,
contourOnly: state.currentStyle.contourOnly
}
}))

this.updateCurrentStyle({ color })
this.props.annotationGroupsUIDs.forEach((uid) => {
this.props.onStyleChange({
uid,
Expand All @@ -147,13 +122,7 @@ ColorSettingsMenuState
}

handleShowOutlineOnly (value: boolean): void {
this.setState({
currentStyle: {
opacity: this.state.currentStyle.opacity,
color: this.state.currentStyle.color,
contourOnly: value
}
})
this.updateCurrentStyle({ contourOnly: value })

this.props.annotationGroupsUIDs.forEach((uid) => {
this.props.onStyleChange({
Expand Down Expand Up @@ -182,6 +151,24 @@ ColorSettingsMenuState
}
}

updateCurrentStyle ({
color,
opacity,
contourOnly
}: {
color?: number[]
opacity?: number
contourOnly?: boolean
}): void {
this.setState((state) => ({
currentStyle: {
opacity: opacity ?? state.currentStyle.opacity,
color: color ?? state.currentStyle.color,
contourOnly: contourOnly ?? state.currentStyle.contourOnly
}
}))
}

render (): React.ReactNode {
let colorSettings
if (this.state.currentStyle.color != null) {
Expand Down

0 comments on commit b0405f8

Please sign in to comment.