Skip to content

Commit

Permalink
refactor: ♻️ refactor all toast types to an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Aug 15, 2024
1 parent 0203cbb commit 49b65cd
Show file tree
Hide file tree
Showing 35 changed files with 185 additions and 176 deletions.
9 changes: 8 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,14 @@ export type SatPassTimes = {
time: Date;
};

export type ToastMsgType = 'standby' | 'normal' | 'caution' | 'serious' | 'critical' | 'error';
export enum ToastMsgType {
standby = 'standby',
normal = 'normal',
caution = 'caution',
serious = 'serious',
critical = 'critical',
error = 'error',
}

export type GeolocationPosition = {
coords: {
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/analysis/analysis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KeepTrackApiEvents, lookanglesRow } from '@app/interfaces';
import { KeepTrackApiEvents, lookanglesRow, ToastMsgType } from '@app/interfaces';
import { keepTrackApi } from '@app/keepTrackApi';
import { clickAndDragWidth } from '@app/lib/click-and-drag';
import { getEl } from '@app/lib/get-el';
Expand Down Expand Up @@ -419,7 +419,7 @@ export class AnalysisMenu extends KeepTrackPlugin {

// Check if there is a sensor
if (sensors.length <= 0 || !sensors[0] || typeof sensors[0].minAz === 'undefined') {
keepTrackApi.getUiManager().toast('Sensor\'s format incorrect. Did you select a sensor first?', 'critical');
keepTrackApi.getUiManager().toast('Sensor\'s format incorrect. Did you select a sensor first?', ToastMsgType.critical);

return [];
}
Expand Down Expand Up @@ -664,7 +664,7 @@ export class AnalysisMenu extends KeepTrackPlugin {
const sensorManagerInstance = keepTrackApi.getSensorManager();

if (!sensorManagerInstance.isSensorSelected()) {
keepTrackApi.getUiManager().toast('You must select a sensor first!', 'critical');
keepTrackApi.getUiManager().toast('You must select a sensor first!', ToastMsgType.critical);
} else {
AnalysisMenu.findBestPasses(sats, sensorManagerInstance.getSensor());
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/dops/dops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getEl } from '@app/lib/get-el';
import { showLoading } from '@app/lib/showLoading';
import gpsPng from '@public/img/icons/gps.png';

import { KeepTrackApiEvents } from '@app/interfaces';
import { KeepTrackApiEvents, ToastMsgType } from '@app/interfaces';
import type { CatalogManager } from '@app/singletons/catalog-manager';
import type { GroupsManager } from '@app/singletons/groups-manager';
import { GroupType } from '@app/singletons/object-group';
Expand Down Expand Up @@ -112,7 +112,7 @@ export class DopsPlugin extends KeepTrackPlugin {

keepTrackApi
.getUiManager()
.toast(`HDOP: ${gpsDOP.hdop}<br/>VDOP: ${gpsDOP.vdop}<br/>PDOP: ${gpsDOP.pdop}<br/>GDOP: ${gpsDOP.gdop}<br/>TDOP: ${gpsDOP.tdop}`, 'normal', true);
.toast(`HDOP: ${gpsDOP.hdop}<br/>VDOP: ${gpsDOP.vdop}<br/>PDOP: ${gpsDOP.pdop}<br/>GDOP: ${gpsDOP.gdop}<br/>TDOP: ${gpsDOP.tdop}`, ToastMsgType.normal, true);
}
break;
}
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/edit-sat/edit-sat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetSatType, KeepTrackApiEvents } from '@app/interfaces';
import { GetSatType, KeepTrackApiEvents, ToastMsgType } from '@app/interfaces';
import { keepTrackApi } from '@app/keepTrackApi';
import { getEl } from '@app/lib/get-el';
import { showLoading } from '@app/lib/showLoading';
Expand Down Expand Up @@ -308,7 +308,7 @@ export class EditSat extends KeepTrackPlugin {
orbitManagerInstance.changeOrbitBufferData(sat.id, object.tle1, object.tle2);
sat.active = true;
} else {
uiManagerInstance.toast('Failed to propagate satellite. Try different parameters or if you are confident they are correct report this issue.', 'caution', true);
uiManagerInstance.toast('Failed to propagate satellite. Try different parameters or if you are confident they are correct report this issue.', ToastMsgType.caution, true);
}
}

Expand Down Expand Up @@ -370,7 +370,7 @@ export class EditSat extends KeepTrackPlugin {
const upOrDown = SatMath.getDirection(mainsat, timeManagerInstance.simulationTimeObj);

if (upOrDown === 'Error') {
uiManagerInstance.toast('Cannot calculate direction of satellite. Try again later.', 'caution');
uiManagerInstance.toast('Cannot calculate direction of satellite. Try again later.', ToastMsgType.caution);
}

const simulationTimeObj = timeManagerInstance.simulationTimeObj;
Expand All @@ -394,7 +394,7 @@ export class EditSat extends KeepTrackPlugin {
const tle2 = TLEs[1];

if (tle1 === 'Error') {
uiManagerInstance.toast(`${tle2}`, 'critical', true);
uiManagerInstance.toast(`${tle2}`, ToastMsgType.critical, true);

return;
}
Expand All @@ -409,9 +409,9 @@ export class EditSat extends KeepTrackPlugin {

orbitManagerInstance.changeOrbitBufferData(id, tle1, tle2);
/*
*
*
* Reload Menu with new TLE
*
*
*/
const obj2 = this.selectSatManager_.getSelectedSat(GetSatType.EXTRA_ONLY);

Expand Down Expand Up @@ -503,7 +503,7 @@ export class EditSat extends KeepTrackPlugin {
sat.editTle(tle1, tle2);
keepTrackApi.getMainCamera().zoomTarget = ZoomValue.GEO;
} else {
keepTrackApi.getUiManager().toast('Failed to propagate satellite. Try different parameters or if you are confident they are correct report this issue.', 'caution', true);
keepTrackApi.getUiManager().toast('Failed to propagate satellite. Try different parameters or if you are confident they are correct report this issue.', ToastMsgType.caution, true);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/find-sat/find-sat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable prefer-const */
/* eslint-disable complexity */
import { GetSatType, KeepTrackApiEvents } from '@app/interfaces';
import { GetSatType, KeepTrackApiEvents, ToastMsgType } from '@app/interfaces';
import { getEl } from '@app/lib/get-el';
import { getUnique } from '@app/lib/get-unique';
import { hideLoading, showLoading } from '@app/lib/showLoading';
Expand Down Expand Up @@ -111,7 +111,7 @@ export class FindSatPlugin extends KeepTrackPlugin {
const uiManagerInstance = keepTrackApi.getUiManager();

if (possibles.length >= limit) {
uiManagerInstance.toast(`Too many results, limited to ${limit}`, 'serious');
uiManagerInstance.toast(`Too many results, limited to ${limit}`, ToastMsgType.serious);
}
possibles = possibles.slice(0, limit);

Expand Down Expand Up @@ -462,11 +462,11 @@ The search will then find all satellites within those inclinations and display t

this.lastResults = FindSatPlugin.searchSats(searchParams as SearchSatParams);
if (this.lastResults.length === 0) {
uiManagerInstance.toast('No Satellites Found', 'critical');
uiManagerInstance.toast('No Satellites Found', ToastMsgType.critical);
}
} catch (e) {
if (e.message === 'No Search Criteria Entered') {
uiManagerInstance.toast('No Search Criteria Entered', 'critical');
uiManagerInstance.toast('No Search Criteria Entered', ToastMsgType.critical);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/gamepad/gamepad.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable class-methods-use-this */
import { KeepTrackApiEvents } from '@app/interfaces';
import { KeepTrackApiEvents, ToastMsgType } from '@app/interfaces';
import { keepTrackApi } from '@app/keepTrackApi';
import { CameraType } from '@app/singletons/camera';
import { Radians } from 'ootk';
Expand All @@ -25,13 +25,13 @@ export class GamepadPlugin {
}
});
window.addEventListener('gamepaddisconnected', () => {
keepTrackApi.getUiManager().toast('Gamepad disconnected', 'critical');
keepTrackApi.getUiManager().toast('Gamepad disconnected', ToastMsgType.critical);
this.currentController = null;
});
}

initializeGamepad(gamepad: Gamepad): void {
keepTrackApi.getUiManager().toast('Gamepad connected', 'normal');
keepTrackApi.getUiManager().toast('Gamepad connected', ToastMsgType.normal);

// Only initialize once
if (!this.currentController) {
Expand Down
23 changes: 12 additions & 11 deletions src/plugins/missile/missile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable complexity */
/* eslint-disable max-statements */
/* eslint-disable max-lines-per-function */
import { ToastMsgType } from '@app/interfaces';
import { keepTrackApi } from '@app/keepTrackApi';
import { RADIUS_OF_EARTH } from '@app/lib/constants';
import { MissileObject } from '@app/singletons/catalog-manager/MissileObject';
Expand Down Expand Up @@ -501,7 +502,7 @@ export class Missile {
BurnRate,
WarheadMass,
)) /
GoalDistance,
GoalDistance,
) * 100;
if (
Missile.testTrajectory_(
Expand Down Expand Up @@ -761,11 +762,11 @@ export class Missile {
ThrustAngle =
(90 -
AngleCoefficient *
(1.5336118956 +
0.00443173537387 * Altitude -
9.30373890848 * 10 ** -8 * Altitude ** 2 +
8.37838197732 * 10 ** -13 * Altitude ** 3 -
2.71228576626 * 10 ** -18 * Altitude ** 4)) *
(1.5336118956 +
0.00443173537387 * Altitude -
9.30373890848 * 10 ** -8 * Altitude ** 2 +
8.37838197732 * 10 ** -13 * Altitude ** 3 -
2.71228576626 * 10 ** -18 * Altitude ** 4)) *
0.0174533;
// (Degrees)
} else {
Expand Down Expand Up @@ -931,13 +932,13 @@ export class Missile {
return null;
}
if (TargetLatitude > 90 || TargetLatitude < -90) {
missileManager.lastMissileErrorType = 'critical';
missileManager.lastMissileErrorType = ToastMsgType.critical;
missileManager.lastMissileError = 'Error: Target Latitude must be<br>between 90 and -90 degrees';

return null;
}
if (TargetLongitude > 180 || TargetLongitude < -180) {
missileManager.lastMissileErrorType = 'critical';
missileManager.lastMissileErrorType = ToastMsgType.critical;
missileManager.lastMissileError = 'Error: Target Longitude must be<br>between 90 and -90 degrees';

return null;
Expand All @@ -960,14 +961,14 @@ export class Missile {
const [EstLatList, EstLongList, , ArcLength, EstDistanceList, GoalDistance] = Missile.calcCoordinates_(CurrentLatitude, CurrentLongitude, TargetLatitude, TargetLongitude);

if (ArcLength < 320000) {
missileManager.lastMissileErrorType = 'critical';
missileManager.lastMissileErrorType = ToastMsgType.critical;
missileManager.lastMissileError = 'Error: This missile has a minimum distance of 320 km.';

return null;
}

if (ArcLength > MaxMissileRange * 1000) {
missileManager.lastMissileErrorType = 'critical';
missileManager.lastMissileErrorType = ToastMsgType.critical;
missileManager.lastMissileError = `Error: This missile has a maximum distance of ${MaxMissileRange} km.`;

return null;
Expand Down Expand Up @@ -1241,7 +1242,7 @@ export class Missile {
}

if (minAltitudeTrue === (minAltitude * 3) / 2) {
missileManager.lastMissileErrorType = 'critical';
missileManager.lastMissileErrorType = ToastMsgType.critical;
missileManager.lastMissileError = 'Error: This distance is too close for the selected missile.';

return null;
Expand Down
45 changes: 23 additions & 22 deletions src/plugins/missile/missileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { MissileObject } from '@app/singletons/catalog-manager/MissileObject';
import { CruncerMessageTypes } from '@app/webworker/positionCruncher';
import { DEG2RAD, EciVec3, Kilometers, MILLISECONDS_TO_DAYS, RAD2DEG, Sensor, Sgp4, SpaceObjectType, ecfRad2rae, eci2ecf, eci2lla } from 'ootk';
import { SatInfoBox } from '../select-sat-manager/sat-info-box';
import { SettingsMenuPlugin } from '../settings-menu/settings-menu';

let BurnRate: number, EarthMass: number, EarthRadius: number, FuelDensity: number, G: number, R: number, WarheadMass: number, h: number;
const missileArray: any[] = [];
Expand Down Expand Up @@ -197,13 +198,13 @@ export const Missile = (
return 0;
}
if (TargetLatitude > 90 || TargetLatitude < -90) {
missileManager.lastMissileErrorType = 'critical';
missileManager.lastMissileErrorType = ToastMsgType.critical;
missileManager.lastMissileError = 'Error: Target Latitude must be<br>between 90 and -90 degrees';

return 0;
}
if (TargetLongitude > 180 || TargetLongitude < -180) {
missileManager.lastMissileErrorType = 'critical';
missileManager.lastMissileErrorType = ToastMsgType.critical;
missileManager.lastMissileError = 'Error: Target Longitude must be<br>between 90 and -90 degrees';

return 0;
Expand Down Expand Up @@ -231,14 +232,14 @@ export const Missile = (
const [EstLatList, EstLongList, , ArcLength, EstDistanceList, GoalDistance] = calculateCoordinates_(CurrentLatitude, CurrentLongitude, TargetLatitude, TargetLongitude);

if (ArcLength < 320000) {
missileManager.lastMissileErrorType = 'critical';
missileManager.lastMissileErrorType = ToastMsgType.critical;
missileManager.lastMissileError = 'Error: This missile has a minimum distance of 320 km.';

return 0;
}

if (ArcLength > MaxMissileRange * 1000) {
missileManager.lastMissileErrorType = 'critical';
missileManager.lastMissileErrorType = ToastMsgType.critical;
missileManager.lastMissileError = `Error: This missile has a maximum distance of ${MaxMissileRange} km.`;

return 0;
Expand Down Expand Up @@ -499,7 +500,7 @@ export const Missile = (
}

if (minAltitudeTrue === (minAltitude * 3) / 2) {
missileManager.lastMissileErrorType = 'critical';
missileManager.lastMissileErrorType = ToastMsgType.critical;
missileManager.lastMissileError = 'Error: This distance is too close for the selected missile.';

return 0;
Expand Down Expand Up @@ -548,7 +549,7 @@ export const Missile = (
missileManager.missileArray = missileArray;
}
missileManager.missilesInUse++;
missileManager.lastMissileErrorType = 'normal';
missileManager.lastMissileErrorType = ToastMsgType.normal;
missileManager.lastMissileError = `Missile Named RV_${missileObj.id}<br>has been created.`;

return 1; // Successful Launch
Expand Down Expand Up @@ -674,17 +675,17 @@ export const getMissileTEARR = (missile: MissileObject, sensors?: Sensor[]) => {
}
} else if (
(currentTEARR.az >= sensor.minAz &&
currentTEARR.az <= sensor.maxAz &&
currentTEARR.el >= sensor.minEl &&
currentTEARR.el <= sensor.maxEl &&
currentTEARR.rng <= sensor.maxRng &&
currentTEARR.rng >= sensor.minRng) ||
(currentTEARR.az >= sensor.minAz2 &&
currentTEARR.az <= sensor.maxAz2 &&
currentTEARR.el >= sensor.minEl2 &&
currentTEARR.el <= sensor.maxEl2 &&
currentTEARR.rng <= sensor.maxRng2 &&
currentTEARR.rng >= sensor.minRng2)
currentTEARR.az <= sensor.maxAz &&
currentTEARR.el >= sensor.minEl &&
currentTEARR.el <= sensor.maxEl &&
currentTEARR.rng <= sensor.maxRng &&
currentTEARR.rng >= sensor.minRng) ||
(currentTEARR.az >= sensor.minAz2 &&
currentTEARR.az <= sensor.maxAz2 &&
currentTEARR.el >= sensor.minEl2 &&
currentTEARR.el <= sensor.maxEl2 &&
currentTEARR.rng <= sensor.maxRng2 &&
currentTEARR.rng >= sensor.minRng2)
) {
currentTEARR.inView = true;
} else {
Expand Down Expand Up @@ -1158,7 +1159,7 @@ export const getMissileTEARR = (missile: MissileObject, sensors?: Sensor[]) => {
* if (ArcLength > MaxMissileRange * 1000) {
* // console.debug('Error: This missile has a maximum distance of ' + MaxMissileRange + ' km.');
* // console.debug('Please choose different target coordinates.');
* missileManager.lastMissileErrorType = 'critical';
* missileManager.lastMissileErrorType = ToastMsgType.critical;
* missileManager.lastMissileError = 'Error: This missile has a maximum distance of ' + MaxMissileRange + ' km.';
* return 0;
* }
Expand Down Expand Up @@ -1498,7 +1499,7 @@ export const getMissileTEARR = (missile: MissileObject, sensors?: Sensor[]) => {
* console.log(AltitudeList);
* console.log(`Required Altitude ${minAltitude}`);
* if (MaxAltitude < minAltitude) {
* missileManager.lastMissileErrorType = 'critical';
* missileManager.lastMissileErrorType = ToastMsgType.critical;
* missileManager.lastMissileError = `Failed Min Altitude Check! Max Altitude ${MaxAltitude} km.`;
* return -1;
* }
Expand Down Expand Up @@ -1656,14 +1657,14 @@ export const getMissileTEARR = (missile: MissileObject, sensors?: Sensor[]) => {
* }
* if (TargetLatitude > 90 || TargetLatitude < -90) {
* // console.debug('Error: Target Latitude must be between 90 and -90 degrees');
* missileManager.lastMissileErrorType = 'critical';
* missileManager.lastMissileErrorType = ToastMsgType.critical;
* missileManager.lastMissileError = 'Error: Target Latitude must be<br>between 90 and -90 degrees';
* return 0;
* }
* if (TargetLongitude > 180 || TargetLongitude < -180) {
* // console.debug('Error: Target Longitude must be between 180 and -180 degrees');
* console.log(TargetLongitude);
* missileManager.lastMissileErrorType = 'critical';
* missileManager.lastMissileErrorType = ToastMsgType.critical;
* missileManager.lastMissileError = 'Error: Target Longitude must be<br>between 180 and -180 degrees';
* return 0;
* }
Expand Down Expand Up @@ -1712,7 +1713,7 @@ export const getMissileTEARR = (missile: MissileObject, sensors?: Sensor[]) => {
* if (ArcLength > MaxMissileRange * 1000) {
* // console.debug('Error: This missile has a maximum distance of ' + MaxMissileRange + ' km.');
* // console.debug('Please choose different target coordinates.');
* missileManager.lastMissileErrorType = 'critical';
* missileManager.lastMissileErrorType = ToastMsgType.critical;
* missileManager.lastMissileError = 'Error: This missile has a maximum distance of ' + MaxMissileRange + ' km.';
* return 0;
* }
Expand Down
Loading

0 comments on commit 49b65cd

Please sign in to comment.