-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f869a6
commit f3af3f5
Showing
9 changed files
with
183 additions
and
16 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
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,15 @@ | ||
type TextInputProps = { | ||
placeholder: string; | ||
onChange: (value: string) => void; | ||
}; | ||
|
||
const TextInput = ({ placeholder, onChange }: TextInputProps) => ( | ||
<input | ||
type="text" | ||
className="w-64 h-16 p-4 border-4 rounded-xl text-lg" | ||
placeholder={placeholder} | ||
onChange={(event) => onChange(event.target.value)} | ||
/> | ||
); | ||
|
||
export default TextInput; |
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,118 @@ | ||
import { useState } from 'react'; | ||
import Board, { getBoardName } from '../../../types/board'; | ||
import Phase from '../../../types/enums/phase'; | ||
import colours from '../../../utils/colours'; | ||
import { boardBorderWidth, boardSeparation, majorBoardWidth } from '../../../utils/constants'; | ||
import Map from './Map'; | ||
import TextInput from '../../user-interface/common/TextInput'; | ||
import Select from '../../user-interface/common/Select'; | ||
import { isInteger } from '../../../utils/numberUtils'; | ||
|
||
type LocationInputProps = { | ||
board: Board; | ||
onTimelineEntered: (value: string) => void; | ||
onYearEntered: (value: string) => void; | ||
onPhaseEntered: (value: Phase) => void; | ||
}; | ||
|
||
const LocationInput = ({ | ||
board, | ||
onTimelineEntered, | ||
onYearEntered, | ||
onPhaseEntered, | ||
}: LocationInputProps) => ( | ||
<div className="absolute -mt-20 flex flex-row gap-4 w-full justify-center"> | ||
<TextInput placeholder="Timeline" onChange={onTimelineEntered} /> | ||
<Select | ||
options={[ | ||
{ | ||
text: 'Spring', | ||
value: Phase.Spring, | ||
}, | ||
{ | ||
text: 'Fall', | ||
value: Phase.Fall, | ||
}, | ||
]} | ||
selectedValue={board.phase} | ||
setValue={onPhaseEntered} | ||
/> | ||
<TextInput placeholder="Year" onChange={onYearEntered} /> | ||
</div> | ||
); | ||
|
||
type BoardGhostProps = { | ||
initialTimeline: number; | ||
initialYear: number; | ||
initialPhase: Phase; | ||
}; | ||
|
||
const BoardGhost = ({ initialTimeline, initialYear, initialPhase }: BoardGhostProps) => { | ||
const [timeline, setTimeline] = useState(initialTimeline); | ||
const [year, setYear] = useState(initialYear); | ||
const [phase, setPhase] = useState(initialPhase); | ||
|
||
const board = { | ||
timeline, | ||
year, | ||
phase, | ||
childTimelines: [], | ||
centres: {}, | ||
units: {}, | ||
}; | ||
|
||
const onTimelineEntered = (value: string) => { | ||
if (!isInteger(value, false)) { | ||
setTimeline(initialTimeline); | ||
return; | ||
} | ||
|
||
const parsedValue = parseInt(value, 10); | ||
setTimeline(parsedValue); | ||
}; | ||
|
||
const onYearEntered = (value: string) => { | ||
if (!isInteger(value, false)) { | ||
setYear(initialYear); | ||
return; | ||
} | ||
|
||
const parsedValue = parseInt(value, 10); | ||
setYear(parsedValue); | ||
}; | ||
|
||
return ( | ||
<div | ||
className="flex-col content-center relative" | ||
style={{ | ||
minHeight: majorBoardWidth, | ||
height: majorBoardWidth, | ||
margin: boardSeparation / 2, | ||
}} | ||
> | ||
<LocationInput | ||
board={board} | ||
onTimelineEntered={onTimelineEntered} | ||
onYearEntered={onYearEntered} | ||
onPhaseEntered={setPhase} | ||
/> | ||
<div | ||
className="relative rounded-xl" | ||
style={{ | ||
backgroundColor: colours.boardBackground, | ||
minWidth: majorBoardWidth, | ||
width: majorBoardWidth, | ||
minHeight: majorBoardWidth, | ||
height: majorBoardWidth, | ||
borderWidth: boardBorderWidth, | ||
borderColor: colours.boardBorder, | ||
}} | ||
> | ||
<p className="text-md -mt-7">{getBoardName(board)}</p> | ||
<Map board={board} isActive={false} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BoardGhost; |
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
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,13 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
|
||
export const isInteger = (value: string, allowNegative: boolean = true) => { | ||
const parsedValue = parseInt(value, 10); | ||
|
||
// None of these cover every case (e.g. whitespace), so use all of them | ||
return ( | ||
parsedValue.toString() === value && | ||
!Number.isNaN(parsedValue) && | ||
Number.isInteger(parsedValue) && | ||
(allowNegative || parsedValue >= 0) | ||
); | ||
}; |