Skip to content

Commit

Permalink
Revert design change on TX, XC button logic, force proper states on T…
Browse files Browse the repository at this point in the history
…X, XC, force transceiver count on station view
  • Loading branch information
pierr3 committed May 2, 2024
1 parent 7caa014 commit d27bed7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 31 deletions.
59 changes: 37 additions & 22 deletions src/app/components/radio/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {

const isATC = useSessionStore((state) => state.isAtc);

const clickRadioHeader = () => {
selectRadio(radio.frequency);
if (radio.transceiverCount === 0 && radio.callsign !== "MANUAL") {
void window.api.RefreshStation(radio.callsign);
}
}

const clickRx = () => {
const newState = !radio.rx;

Expand All @@ -40,7 +47,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
newState ? radio.tx : false,
newState ? radio.xc : false,
radio.onSpeaker,
newState ? radio.crossCoupleAcross : false,
newState ? radio.crossCoupleAcross : false
)
.then((ret) => {
if (!ret) {
Expand All @@ -53,7 +60,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
setXc(radio.frequency, newState ? radio.xc : false);
setCrossCoupleAcross(
radio.frequency,
newState ? radio.crossCoupleAcross : false,
newState ? radio.crossCoupleAcross : false
);
})
.catch((err: unknown) => {
Expand All @@ -67,18 +74,24 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
window.api
.setFrequencyState(
radio.frequency,
radio.rx,
newState ? true : radio.rx, // If tx is true, rx must be true
newState,
!newState ? false : radio.xc,
!newState ? false : radio.xc, // If tx is false, xc must be false
radio.onSpeaker,
!newState ? false : radio.crossCoupleAcross,
!newState ? false : radio.crossCoupleAcross // If tx is false, crossCoupleAcross must be false
)
.then((ret) => {
if (!ret) {
postError("Invalid action on invalid radio: TX.");
return;
}
setTx(radio.frequency, newState);
setRx(radio.frequency, newState ? true : radio.rx);
setXc(radio.frequency, !newState ? false : radio.xc);
setCrossCoupleAcross(
radio.frequency,
!newState ? false : radio.crossCoupleAcross
);
})
.catch((err: unknown) => {
console.error(err);
Expand All @@ -90,17 +103,19 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
window.api
.setFrequencyState(
radio.frequency,
radio.rx,
radio.tx,
newState ? true : radio.rx, // If xc is true, rx must be true
newState ? true : radio.tx, // If xc is true, tx must be true
newState,
radio.onSpeaker,
false,
false // If xc is true, crossCoupleAcross must be false
)
.then((ret) => {
if (!ret) {
postError("Invalid action on invalid radio: XC.");
return;
}
setRx(radio.frequency, newState ? true : radio.rx);
setTx(radio.frequency, newState ? true : radio.tx);
setXc(radio.frequency, newState);
setCrossCoupleAcross(radio.frequency, false);
})
Expand All @@ -114,17 +129,19 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
window.api
.setFrequencyState(
radio.frequency,
radio.rx,
radio.tx,
false,
newState ? true : radio.rx, // If crossCoupleAcross is true, rx must be true
newState ? true : radio.tx, // If crossCoupleAcross is true, tx must be true
false, // If crossCoupleAcross is true, xc must be false
radio.onSpeaker,
newState,
newState
)
.then((ret) => {
if (!ret) {
postError("Invalid action on invalid radio: XC across.");
return;
}
setRx(radio.frequency, newState ? true : radio.rx);
setTx(radio.frequency, newState ? true : radio.tx);
setXc(radio.frequency, false);
setCrossCoupleAcross(radio.frequency, newState);
})
Expand All @@ -142,7 +159,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
radio.tx,
radio.xc,
newState,
radio.crossCoupleAcross,
radio.crossCoupleAcross
)
.then((ret) => {
if (!ret) {
Expand All @@ -164,9 +181,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
<button
className="btn btn-no-interact"
style={{ height: "100%", marginBottom: "4%" }}
onClick={() => {
selectRadio(radio.frequency);
}}
onClick={clickRadioHeader}
>
{RadioHelper.convertHzToMhzString(radio.frequency)}
<br />
Expand All @@ -177,20 +192,20 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
"btn",
!radio.xc && !radio.crossCoupleAcross && "btn-primary",
radio.xc && "btn-success",
radio.crossCoupleAcross && "btn-warning",
radio.crossCoupleAcross && "btn-warning"
)}
style={{ width: "45%", height: "100%", marginTop: "4%" }}
onClick={clickXc}
onContextMenu={clickCrossCoupleAcross}
disabled={!isATC || !radio.rx}
disabled={!isATC}
>
{radio.crossCoupleAcross ? "XCA" : "XC"}
</button>
<button
className={clsx(
"btn",
!radio.onSpeaker && "btn-primary",
radio.onSpeaker && "btn-success",
radio.onSpeaker && "btn-success"
)}
style={{
width: "45%",
Expand All @@ -216,7 +231,7 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
"btn",
!radio.rx && "btn-primary",
radio.rx && radio.currentlyRx && "btn-warning",
radio.rx && !radio.currentlyRx && "btn-success",
radio.rx && !radio.currentlyRx && "btn-success"
)}
style={{ width: "100%", height: "100%" }}
onClick={clickRx}
Expand All @@ -228,11 +243,11 @@ const Radio: React.FC<RadioProps> = ({ radio }) => {
"btn",
!radio.tx && "btn-primary",
radio.tx && radio.currentlyTx && "btn-warning",
radio.tx && !radio.currentlyTx && "btn-success",
radio.tx && !radio.currentlyTx && "btn-success"
)}
style={{ width: "100%", height: "100%", marginTop: "8%" }}
onClick={clickTx}
disabled={!isATC || !radio.rx}
disabled={!isATC}
>
TX
</button>
Expand Down
20 changes: 12 additions & 8 deletions src/app/components/settings-modal/settings-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React, { useEffect, useState } from "react";
import AudioApis from "./audio-apis";
import AudioInput from "./audio-input";
import AudioOutputs from "./audio-outputs";
import useUtilStore from "../../store/utilStore";
import clsx from "clsx";
import useSessionStore from "../../store/sessionStore";
import { useDebouncedCallback } from "use-debounce";
import { Configuration } from "../../../config.d";
import useSessionStore from "../../store/sessionStore";
import { getKeyFromNumber } from "../../../helper";
import useUtilStore from "../../store/utilStore";
import clsx from "clsx";
import { AudioApi, AudioDevice } from "trackaudio-afv";

export interface SettingsModalProps {
Expand All @@ -24,10 +24,10 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
const [changesSaved, setChangesSaved] = useState(SaveStatus.NoChanges);
const [audioApis, setAudioApis] = useState(Array<AudioApi>);
const [audioOutputDevices, setAudioOutputDevices] = useState(
Array<AudioDevice>,
Array<AudioDevice>
);
const [audioInputDevices, setAudioInputDevices] = useState(
Array<AudioDevice>,
Array<AudioDevice>
);
const [hardwareType, setHardwareType] = useState(0);
const [config, setConfig] = useState({} as Configuration);
Expand All @@ -42,7 +42,11 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
const [cid, setCid] = useState("");
const [password, setPassword] = useState("");

const [vu, vuPeak, updateVu] = useUtilStore((state) => [state.vu, state.peakVu, state.updateVu]);
const [vu, vuPeak, updateVu] = useUtilStore((state) => [
state.vu,
state.peakVu,
state.updateVu,
]);
const [isMicTesting, setIsMicTesting] = useState(false);

useEffect(() => {
Expand Down Expand Up @@ -180,7 +184,7 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
};

const handleHardwareTypeChange = (
e: React.ChangeEvent<HTMLSelectElement>,
e: React.ChangeEvent<HTMLSelectElement>
) => {
setChangesSaved(SaveStatus.Saving);
const hardwareType = parseInt(e.target.value);
Expand Down Expand Up @@ -299,7 +303,7 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
className={clsx(
"btn mt-3 w-100",
!isMicTesting && "btn-info",
isMicTesting && "btn-warning",
isMicTesting && "btn-warning"
)}
onClick={handleMicTest}
disabled={
Expand Down
3 changes: 3 additions & 0 deletions src/app/components/sidebar/radio-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const RadioStatus: React.FC = () => {
if (!selectedRadio) {
return;
}
if (selectedRadio.callsign === "MANUAL") {
return;
}
void window.api.RefreshStation(selectedRadio.callsign);
};

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const createWindow = (): void => {
mainWindow = new BrowserWindow({
height: 660,
width: 800,
minWidth: 200,
minWidth: 210,
minHeight: 120,
webPreferences: {
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
Expand Down

0 comments on commit d27bed7

Please sign in to comment.