Skip to content

Commit

Permalink
fix: use .some instead of includes on objects
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Jul 13, 2023
1 parent 2232442 commit 055c82c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
35 changes: 23 additions & 12 deletions client/src/components/ChannelRouteSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,27 @@ class ChannelRouteSettings extends React.PureComponent<
this.faderIndex = this.props.faderIndex
}

handleAssignChannel(mixerIndex: number, channel: number, event: any) {
handleAssignChannel(mixerIndex: number, channelIndex: number, event: any) {
console.log('Bind/Unbind Channel')
if (
window.confirm(
'Bind/Unbind Mixer ' +
String(mixerIndex + 1) +
' Channel ' +
String(channel + 1) +
String(channelIndex + 1) +
' from Fader ' +
String(this.faderIndex + 1)
)
) {
// Check if channel already is assigned to another fader and remove that binding prior to bind it to the new fader
if (event.target.checked) {
this.props.fader.forEach((fader: any, index: number) => {
if (fader.assignedChannels.includes({ mixerIndex: mixerIndex, channelIndex: channel })) {
this.props.fader.forEach((fader: IFader, index: number) => {
if (fader.assignedChannels.some((assignedChan) => {
return assignedChan.mixerIndex === mixerIndex && assignedChan.channelIndex === channelIndex
})) {
window.socketIoClient.emit(SOCKET_ASSIGN_CH_TO_FADER, {
mixerIndex: mixerIndex,
channel: channel,
channel: channelIndex,
faderIndex: index,
assigned: false
})
Expand All @@ -59,7 +61,7 @@ class ChannelRouteSettings extends React.PureComponent<

window.socketIoClient.emit(SOCKET_ASSIGN_CH_TO_FADER, {
mixerIndex: mixerIndex,
channel: channel,
channel: channelIndex,
faderIndex: this.faderIndex,
assigned: event.target.checked
})
Expand All @@ -74,13 +76,14 @@ class ChannelRouteSettings extends React.PureComponent<

handle1to1Routing() {
if (window.confirm('Reassign all Faders 1:1 to Channels????')) {
window.socketIoClient.emit(SOCKET_REMOVE_ALL_CH_ASSIGNMENTS)
this.props.fader.forEach((fader: any, index: number) => {
if (this.props.chMixerConnections[0].channel.length > index) {
window.socketIoClient.emit(SOCKET_ASSIGN_CH_TO_FADER, {
mixerIndex: 0,
channel: index,
faderIndex: index,
assign: true
assigned: true
})
}
})
Expand All @@ -91,8 +94,16 @@ class ChannelRouteSettings extends React.PureComponent<
this.props.dispatch(storeShowOptions(this.faderIndex))
}

isChannelAssignedToFader = (channel: IChannelReference) => {
return (this.props.fader[this.faderIndex].assignedChannels?.includes(channel))
getAssignedToFaderIndex = (channel: IChannelReference) => {
let isAssinged = -1
this.props.fader.forEach((fader: any, index: number) => {

if (fader.assignedChannels.some((assignedChan: IChannelReference) => {
return assignedChan.channelIndex === channel.channelIndex && assignedChan.mixerIndex === channel.mixerIndex
}))
isAssinged = index
})
return isAssinged
}


Expand All @@ -109,14 +120,14 @@ class ChannelRouteSettings extends React.PureComponent<
key={index}
className={ClassNames('channel-route-text', {
checked:
this.isChannelAssignedToFader({ mixerIndex: mixerIndex, channelIndex: index }),
this.getAssignedToFaderIndex({ mixerIndex: mixerIndex, channelIndex: index }) === this.faderIndex,
})}
>
{' Channel ' + (index + 1) + ' : '}
<input
type="checkbox"
checked={
channel.assignedFader === this.faderIndex
this.getAssignedToFaderIndex({ mixerIndex: mixerIndex, channelIndex: index }) === this.faderIndex
}
onChange={(event) =>
this.handleAssignChannel(
Expand All @@ -126,7 +137,7 @@ class ChannelRouteSettings extends React.PureComponent<
)
}
/>
{this.isChannelAssignedToFader({ mixerIndex: mixerIndex, channelIndex: index })
{this.getAssignedToFaderIndex({ mixerIndex: mixerIndex, channelIndex: index }) >= 0
? ' (Fader ' +
(channel.assignedFader + 1) +
')'
Expand Down
14 changes: 7 additions & 7 deletions shared/src/reducers/fadersReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ export const faders = (

if (action.assigned) {
if (
!newAssignments.includes({
mixerIndex: action.mixerIndex,
channelIndex: action.channelIndex,
!newAssignments.some((channel) => {
return !(channel.mixerIndex === action.mixerIndex &&
channel.channelIndex === action.channelIndex)
})
) {
newAssignments.push({
Expand All @@ -304,10 +304,10 @@ export const faders = (
)
}
} else {
newAssignments = newAssignments.filter((channel) => {
return (
channel.channelIndex !== action.channelIndex &&
channel.mixerIndex !== action.mixerIndex
newAssignments = newAssignments.filter((channel: IChannelReference) => {
return !(
channel.channelIndex === action.channelIndex &&
channel.mixerIndex === action.mixerIndex
)
})
}
Expand Down

0 comments on commit 055c82c

Please sign in to comment.