commit 3a6ab29f053d00197a7aca4f06ca2acbb34c2f08
parent c5be4968fa9ae8d6317ffeecce1bcca29518a9b2
Author: ashermorgan <59518073+ashermorgan@users.noreply.github.com>
Date: Fri, 5 Jan 2024 12:38:45 -0800
Sort targets in split calculator and target editor
Diffstat:
3 files changed, 17 insertions(+), 34 deletions(-)
diff --git a/src/components/TargetSetSelector.vue b/src/components/TargetSetSelector.vue
@@ -7,7 +7,7 @@
<option value="_new">[ Create New Target Set ]</option>
</select>
- <button class="icon" title="Edit target set" @click="$refs.dialog.showModal()">
+ <button class="icon" title="Edit target set" @click="sortTargetSet(); $refs.dialog.showModal()">
<vue-feather type="edit" aria-hidden="true"/>
</button>
@@ -56,11 +56,6 @@ export default {
* The target sets
*/
targetSets: storage.get('target-sets', targetUtils.defaultTargetSets),
-
- /**
- * Whether the target set is being edited
- */
- editingTargetSets: false,
};
},
@@ -103,16 +98,6 @@ export default {
this.$emit('targets-updated');
},
},
-
- /**
- * Sort target set
- */
- editingTargetSets(newValue) {
- if (!newValue) {
- this.targetSets[this.internalValue].targets =
- targetUtils.sort(this.targetSets[this.internalValue].targets);
- }
- },
},
methods: {
@@ -124,6 +109,7 @@ export default {
// Revert default set
this.targetSets[this.internalValue] =
JSON.parse(JSON.stringify(targetUtils.defaultTargetSets[this.internalValue]));
+ this.sortTargetSet();
} else {
// Remove custom set
delete this.targetSets[this.internalValue];
@@ -131,6 +117,14 @@ export default {
if (this.$refs.dialog.close) this.$refs.dialog.close();
}
},
+
+ /**
+ * Sort the current target set
+ */
+ sortTargetSet() {
+ this.targetSets[this.internalValue].targets =
+ targetUtils.sort(this.targetSets[this.internalValue].targets);
+ },
},
activated() {
diff --git a/src/views/SplitCalculator.vue b/src/views/SplitCalculator.vue
@@ -140,8 +140,8 @@ export default {
// Check for missing target set
if (!this.targetSets[this.selectedTargetSet]) return [];
- let targets = this.targetSets[this.selectedTargetSet].targets.filter(x => x.result ===
- 'time');
+ let targets = targetUtils.sort(this.targetSets[this.selectedTargetSet].targets.filter(x =>
+ x.result === 'time'));
for (let i = 0; i < targets.length; i += 1) {
// Calculate split and total times
diff --git a/tests/unit/components/TargetSetSelector.spec.js b/tests/unit/components/TargetSetSelector.spec.js
@@ -111,7 +111,7 @@ test('revertTargetSet method should correctly reset target sets', async () => {
expect(wrapper.vm.internalValue).to.equal('_split_targets');
});
-test('Target sets should be correctly sorted', async () => {
+test('sortTargetSet method should correctly sort target sets', async () => {
// Initialize component
const wrapper = mount(TargetSetSelector, {
data() {
@@ -122,9 +122,11 @@ test('Target sets should be correctly sorted', async () => {
'_split_targets': {
name: '5K Mile Splits',
targets: [
+ { result: 'distance', timeValue: 60 },
{ result: 'time', distanceValue: 1, distanceUnit: 'miles' },
{ result: 'time', distanceValue: 2, distanceUnit: 'miles' },
{ result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
+ { result: 'time', distanceValue: 3, distanceUnit: 'miles' },
],
},
},
@@ -132,21 +134,8 @@ test('Target sets should be correctly sorted', async () => {
},
});
- // Edit target set
- wrapper.vm.editingTargetSets = true;
- await wrapper.vm.$nextTick();
- wrapper.vm.targetSets['_split_targets'] = {
- name: '5K Mile Splits',
- targets: [
- { result: 'distance', timeValue: 60 },
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 3, distanceUnit: 'miles' },
- ],
- };
- wrapper.vm.editingTargetSets = false;
- await wrapper.vm.$nextTick();
+ // Sort target set
+ await wrapper.vm.sortTargetSet();
// Assert target set was sorted
expect(wrapper.vm.targetSets).to.deep.equal({