-
Notifications
You must be signed in to change notification settings - Fork 12
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
7a66ac1
commit 13ea751
Showing
11 changed files
with
139 additions
and
83 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
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,63 @@ | ||
import React, { useRef, useState } from 'react'; | ||
import useSessionStore from '../../store/sessionStore'; | ||
|
||
export interface AddStationProps { | ||
className?: string; | ||
style?: React.CSSProperties; | ||
onAddStation?: () => void; | ||
} | ||
|
||
const AddStation: React.FC<AddStationProps> = ({ className, style, onAddStation }) => { | ||
const [readyToAdd, setReadyToAdd] = useState(false); | ||
const [isConnected] = useSessionStore((state) => [state.version, state.isConnected]); | ||
|
||
const stationInputRef = useRef<HTMLInputElement>(null); | ||
|
||
const addStation = () => { | ||
if (!readyToAdd || !isConnected) { | ||
return; | ||
} | ||
|
||
const callsign = stationInputRef.current?.value.toUpperCase(); | ||
if (!callsign?.match(/^[A-Z0-9_ -]+$/) || !stationInputRef.current) { | ||
return; | ||
} | ||
|
||
void window.api.GetStation(callsign); | ||
stationInputRef.current.value = ''; | ||
setReadyToAdd(false); | ||
|
||
if (onAddStation) { | ||
onAddStation(); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={`form-group ${className ? className : ''}`} style={style}> | ||
<h5>Add a Station</h5> | ||
<input | ||
type="text" | ||
className="form-control mt-2" | ||
id="stationInput" | ||
placeholder="XXXX_XXX" | ||
ref={stationInputRef} | ||
onChange={(e) => { | ||
e.target.value.length !== 0 ? setReadyToAdd(true) : setReadyToAdd(false); | ||
}} | ||
onKeyDown={(e) => { | ||
e.key === 'Enter' && addStation(); | ||
}} | ||
></input> | ||
|
||
<button | ||
className="btn btn-primary mt-2 w-100" | ||
disabled={!readyToAdd || !isConnected} | ||
onClick={addStation} | ||
> | ||
Add | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AddStation; |
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