Skip to content

Commit 7b0e09a

Browse files
committed
feat: Add extra space to settings tab
1 parent f371ab0 commit 7b0e09a

7 files changed

+44
-2
lines changed

bun.lockb

0 Bytes
Binary file not shown.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
],
77
"scripts": {
88
"dev": "bun --cwd web dev",
9+
"build": "bun --cwd npm build",
910
"check": "bun --cwd npm check && bun --cwd web check",
1011
"prepare": "simple-git-hooks"
1112
},

web/components/SettingsTab.vue

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
<script lang="ts" setup>
2+
import { Distance } from '@aklinker1/cutlist';
3+
24
const optimize = useOptimizeForSetting();
35
const bladeWidth = useBladeWidthSetting();
46
const distanceUnit = useDistanceUnit();
57
const showPartNumbers = useShowPartNumbers();
8+
const extraSpace = useExtraSpaceSetting();
9+
10+
// Convert values when units change
11+
watch(distanceUnit, (newUnit, oldUnit) => {
12+
if (!newUnit || !oldUnit) return;
13+
14+
console.log(newUnit, oldUnit);
15+
const convertValue = (value: Ref<string | number>) => {
16+
const dist = new Distance(value.value + oldUnit);
17+
value.value = dist[newUnit];
18+
};
19+
convertValue(bladeWidth);
20+
convertValue(extraSpace);
21+
});
622
</script>
723

824
<template>
@@ -11,10 +27,14 @@ const showPartNumbers = useShowPartNumbers();
1127
<USelect v-model="distanceUnit" :options="['in', 'm', 'mm']" />
1228
</UFormGroup>
1329

14-
<UFormGroup label="Blade width (in):">
30+
<UFormGroup :label="`Blade width (${distanceUnit}):`">
1531
<UInput v-model="bladeWidth" type="number" />
1632
</UFormGroup>
1733

34+
<UFormGroup :label="`Extra space (${distanceUnit}):`">
35+
<UInput v-model="extraSpace" type="number" />
36+
</UFormGroup>
37+
1838
<UFormGroup label="Optimize for:">
1939
<USelect v-model="optimize" :options="['Cuts', 'Space']" />
2040
</UFormGroup>

web/composables/useBladeWidth.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import { Distance } from '@aklinker1/cutlist';
55
*/
66
export default function () {
77
const bladeWidth = useBladeWidthSetting();
8-
return computed(() => new Distance(bladeWidth.value + 'in').m);
8+
const unit = useDistanceUnit();
9+
return computed(() => new Distance(bladeWidth.value + unit.value).m);
910
}

web/composables/useCutlistConfig.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import type { Config } from '@aklinker1/cutlist';
33
export default createSharedComposable(() => {
44
const bladeWidth = useBladeWidth();
55
const optimize = useOptimizeFor();
6+
const extraSpace = useExtraSpace();
67

78
return computed<Config>(() => ({
89
bladeWidth: bladeWidth.value,
910
optimize: optimize.value,
11+
extraSpace: extraSpace.value,
1012
}));
1113
});

web/composables/useExtraSpace.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Distance } from '@aklinker1/cutlist';
2+
3+
/**
4+
* Returns the extra space in standard units based off the settings.
5+
*/
6+
export default function () {
7+
const extraSpace = useExtraSpaceSetting();
8+
const unit = useDistanceUnit();
9+
return computed(() => new Distance(extraSpace.value + unit.value).m);
10+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Stores the preference from the settings page directly. Unless you're on the
3+
* settings page, you should probably use `useExtraSpace` instead for the
4+
* standardized value.
5+
*/
6+
export default createGlobalState(() =>
7+
useLocalStorage('@cutlist/extra-space', '0'),
8+
);

0 commit comments

Comments
 (0)