Skip to content

Commit

Permalink
Make it possible to cancel "Approximate by ratios"
Browse files Browse the repository at this point in the history
ref #683
  • Loading branch information
frostburn committed Jun 13, 2024
1 parent bcb5875 commit e1b5cf9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/basic.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("Scale generation/modification", () => {
for (let i = 0; i < 5; ++i) {
cy.get("button").contains("Apply").click();
}
cy.get("button").contains("Close").click();
cy.get("button").contains("Done").click();
cy.get("#scale-data").should("contain.value", "8/7");
});
});
2 changes: 1 addition & 1 deletion src/components/ModifyScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function clickSubset() {
}
function clickApproximateByRatios() {
approx.initialize()
approx.initialize(scale.sourceText)
showApproximateByRatiosModal.value = true
}
Expand Down
10 changes: 8 additions & 2 deletions src/components/modals/modification/ApproximateByRatios.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,15 @@ function modify(expand = true) {
scale.computeScale()
emit('done')
}
function cancel() {
scale.sourceText = approx.originalSource
emit('done')
}
</script>

<template>
<Modal @confirm="modify(true)" @cancel="modify(false)">
<Modal @confirm="modify(true)" @cancel="cancel">
<template #header>
<h2>Approximate by ratios</h2>
</template>
Expand Down Expand Up @@ -233,8 +238,9 @@ function modify(expand = true) {
<template #footer>
<div class="btn-group">
<button @click="modifyAndAdvance">Apply</button>
<button @click="modify(true)">Close</button>
<button @click="modify(true)">Done</button>
<button @click="modify(false)">Raw</button>
<button @click="cancel">Cancel</button>
</div>
</template>
</Modal>
Expand Down
5 changes: 4 additions & 1 deletion src/stores/approximate-by-ratios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const useApproximateByRatiosStore = defineStore('approximate-by-ratios',
const oddLimit = ref(9)
const primeLimit = ref(7)
const maxExponent = ref(2)
const originalSource = ref('')

const safeOddLimit = computed(() => clamp(3, 101, 2 * Math.floor(oddLimit.value / 2) + 1))
const safePrimeLimit = computed(() => {
Expand Down Expand Up @@ -92,9 +93,10 @@ export const useApproximateByRatiosStore = defineStore('approximate-by-ratios',
return '>97-limit'
}

function initialize() {
function initialize(source: string) {
degree.value = 1
approximationIndex.value = 0
originalSource.value = source
}

return {
Expand All @@ -110,6 +112,7 @@ export const useApproximateByRatiosStore = defineStore('approximate-by-ratios',
safeOddLimit,
safePrimeLimit,
safeMaxExponent,
originalSource,
modifyPrimeLimit,
primeLimitString,
initialize
Expand Down

0 comments on commit e1b5cf9

Please sign in to comment.