Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logic for tracking the currently selected pilot
- Loading branch information
1 parent
02dcc9e
commit 593e570
Showing
5 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {PILOT_SELECT} from "./pilotsConstants"; | ||
|
||
export function selectPilot(pilotID) { | ||
return { | ||
type : PILOT_SELECT, | ||
payload : {currentPilot : pilotID}, | ||
}; | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const PILOT_SELECT = "PILOT_SELECT"; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {createReducer} from "common/utils/reducerUtils"; | ||
|
||
import {PILOT_SELECT} from "./pilotsConstants"; | ||
|
||
const initialState = { | ||
currentPilot : null | ||
}; | ||
|
||
export function selectPilot(state, payload) { | ||
const prevSelectedPilot = state.currentPilot; | ||
const newSelectedPilot = payload.currentPilot; | ||
|
||
const isSamePilot = prevSelectedPilot === newSelectedPilot; | ||
|
||
return { | ||
// Deselect entirely if it's a second click on the same pilot, | ||
// otherwise go ahead and select the one that was clicked | ||
currentPilot : isSamePilot ? null : newSelectedPilot, | ||
}; | ||
} | ||
|
||
|
||
export default createReducer(initialState, { | ||
[PILOT_SELECT] : selectPilot, | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {createSelector} from "reselect"; | ||
|
||
export const selectPilots = state => state.pilots; | ||
|
||
export const selectCurrentPilot = createSelector( | ||
selectPilots, | ||
pilots => pilots.currentPilot, | ||
); |