commit 7d2e81f3445e849cd183eda85394973789363413
parent edcfdfbc9fa27f940f1b3accde172f5e96b490b7
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date: Mon, 7 Jul 2025 14:08:09 -0700
Replace TargetSetTypes with the Calculator enum
All logic that determines target set format, advanced option
availability, etc. now use the Calculator enum.
Diffstat:
5 files changed, 22 insertions(+), 29 deletions(-)
diff --git a/src/components/AdvancedOptionsInput.vue b/src/components/AdvancedOptionsInput.vue
@@ -9,10 +9,8 @@
<div>
Target Set:
- <target-set-selector :setType="props.type === Calculators.Workout ? TargetSetTypes.Workout :
- (props.type === Calculators.Split ? TargetSetTypes.Split : TargetSetTypes.Standard)"
- v-model:selected-target-set="options.selectedTargetSet"
- v-model:target-sets="targetSets" :default-unit-system="defaultUnitSystem"
+ <target-set-selector :setType="props.type" :default-unit-system="defaultUnitSystem"
+ v-model:selected-target-set="options.selectedTargetSet" v-model:target-sets="targetSets"
:customWorkoutNames="props.type === Calculators.Workout ?
(options as WorkoutOptions).customTargetNames : false"/>
</div>
@@ -48,7 +46,6 @@
<script setup lang="ts">
import { Calculators } from '@/utils/calculators';
import type { CalculatorOptions, RaceOptions, WorkoutOptions } from '@/utils/calculators';
-import { TargetSetTypes } from '@/utils/targets';
import type { TargetSets } from '@/utils/targets';
import { UnitSystems } from '@/utils/units';
diff --git a/src/components/TargetEditor.vue b/src/components/TargetEditor.vue
@@ -23,12 +23,12 @@
<tbody>
<tr v-for="(item, index) in model.targets" :key="index">
<td>
- <span v-if="setType === 'workout' && customWorkoutNames">
+ <span v-if="setType === Calculators.Workout && customWorkoutNames">
<input v-model="(item as WorkoutTarget).customName" aria-label="Custom target name"
:placeholder="workoutTargetToString(item as WorkoutTarget)"/>:
</span>
- <span v-if="setType === 'workout'">
+ <span v-if="setType === Calculators.Workout">
<decimal-input v-model="(item as WorkoutTarget).splitValue"
aria-label="Split distance value" :min="0" :digits="2"/>
<select v-model="(item as WorkoutTarget).splitUnit" aria-label="Split distance unit">
@@ -38,7 +38,7 @@
</select>
</span>
- <span v-if="setType === 'workout'">
+ <span v-if="setType === Calculators.Workout">
@
</span>
@@ -77,7 +77,8 @@
<button title="Add distance target" @click="addDistanceTarget">
Add distance target
</button>
- <button title="Add time target" @click="addTimeTarget" v-if="setType !== 'split'">
+ <button title="Add time target" @click="addTimeTarget"
+ v-if="setType !== Calculators.Split">
Add time target
</button>
</td>
@@ -89,7 +90,8 @@
<script setup lang="ts">
import VueFeather from 'vue-feather';
-import { TargetTypes, TargetSetTypes, workoutTargetToString } from '@/utils/targets';
+import { Calculators } from '@/utils/calculators';
+import { TargetTypes, workoutTargetToString } from '@/utils/targets';
import type { StandardTargetSet, TargetSet, WorkoutTarget, WorkoutTargetSet } from '@/utils/targets';
import { DistanceUnitData, UnitSystems, getDefaultDistanceUnit } from '@/utils/units';
@@ -118,16 +120,16 @@ interface Props {
modelValue: TargetSet,
/**
- * The target set type (Standard, Split, or Workout, defaults to Standard)
+ * The target set type (defaults to pace calculator target sets)
*/
- setType?: TargetSetTypes,
+ setType?: Calculators,
}
const props = withDefaults(defineProps<Props>(), {
customWorkoutNames: false,
defaultUnitSystem: UnitSystems.Metric,
isCustomSet: false,
- setType: TargetSetTypes.Standard,
+ setType: Calculators.Pace,
});
// Declare emitted events
@@ -140,7 +142,7 @@ const model = useObjectModel<TargetSet>(() => props.modelValue, (x) => emit('upd
* Add a new distance based target
*/
function addDistanceTarget() {
- if (props.setType === TargetSetTypes.Workout) {
+ if (props.setType === Calculators.Workout) {
(model.value as WorkoutTargetSet).targets.push({
type: TargetTypes.Distance,
distanceValue: 1,
@@ -161,7 +163,7 @@ function addDistanceTarget() {
* Add a new time based target
*/
function addTimeTarget() {
- if (props.setType === TargetSetTypes.Workout) {
+ if (props.setType === Calculators.Workout) {
(model.value as WorkoutTargetSet).targets.push({
type: TargetTypes.Time,
time: 600,
diff --git a/src/components/TargetSetSelector.vue b/src/components/TargetSetSelector.vue
@@ -25,8 +25,9 @@ import { computed, nextTick, ref } from 'vue';
import VueFeather from 'vue-feather';
+import { Calculators } from '@/utils/calculators';
import { deepCopy } from '@/utils/misc';
-import { TargetSetTypes, sort, defaultTargetSets } from '@/utils/targets';
+import { sort, defaultTargetSets } from '@/utils/targets';
import type { TargetSet, TargetSets } from '@/utils/targets';
import { UnitSystems } from '@/utils/units';
@@ -53,9 +54,9 @@ interface Props {
defaultUnitSystem?: UnitSystems,
/**
- * The target set type (Standard, Split, or Workout, defaults to Standard)
+ * The target set type (defaults to pace calculator target sets)
*/
- setType?: TargetSetTypes,
+ setType?: Calculators,
/**
* The target sets
@@ -67,7 +68,7 @@ interface Props {
const props = withDefaults(defineProps<Props>(), {
customWorkoutNames: false,
defaultUnitSystem: UnitSystems.Metric,
- setType: TargetSetTypes.Standard,
+ setType: Calculators.Pace,
});
// Generate internal ref tied to modelValue prop
diff --git a/src/utils/calculators.ts b/src/utils/calculators.ts
@@ -9,6 +9,8 @@ import type { DistanceTime } from '@/utils/units';
/*
* The four main calculators (batch and unit calculators not included)
+ *
+ * Used to determine available options and target set format
*/
export enum Calculators {
Pace = 'pace',
diff --git a/src/utils/targets.ts b/src/utils/targets.ts
@@ -10,7 +10,7 @@ export enum TargetTypes {
};
/*
- * The types for basic standard targets and target sets
+ * The types for basic standard targets and target sets used by the pace and race calculators
*/
interface DistanceTarget {
type: TargetTypes.Distance,
@@ -61,15 +61,6 @@ export interface WorkoutTargetSets {
};
/*
- * The three types of targets sets: standard (pace & race), split, and workout
- */
-export enum TargetSetTypes {
- Standard = 'standard',
- Split = 'split',
- Workout = 'workout',
-};
-
-/*
* The types for generic targets and target sets
*/
export type Target = StandardTarget | SplitTarget | WorkoutTarget;