Skip to content

Commit

Permalink
feat: Add extra space to settings tab
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Apr 5, 2024
1 parent f371ab0 commit 7b0e09a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
],
"scripts": {
"dev": "bun --cwd web dev",
"build": "bun --cwd npm build",
"check": "bun --cwd npm check && bun --cwd web check",
"prepare": "simple-git-hooks"
},
Expand Down
22 changes: 21 additions & 1 deletion web/components/SettingsTab.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
<script lang="ts" setup>
import { Distance } from '@aklinker1/cutlist';
const optimize = useOptimizeForSetting();
const bladeWidth = useBladeWidthSetting();
const distanceUnit = useDistanceUnit();
const showPartNumbers = useShowPartNumbers();
const extraSpace = useExtraSpaceSetting();
// Convert values when units change
watch(distanceUnit, (newUnit, oldUnit) => {
if (!newUnit || !oldUnit) return;
console.log(newUnit, oldUnit);
const convertValue = (value: Ref<string | number>) => {
const dist = new Distance(value.value + oldUnit);
value.value = dist[newUnit];
};
convertValue(bladeWidth);
convertValue(extraSpace);
});
</script>

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

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

<UFormGroup :label="`Extra space (${distanceUnit}):`">
<UInput v-model="extraSpace" type="number" />
</UFormGroup>

<UFormGroup label="Optimize for:">
<USelect v-model="optimize" :options="['Cuts', 'Space']" />
</UFormGroup>
Expand Down
3 changes: 2 additions & 1 deletion web/composables/useBladeWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import { Distance } from '@aklinker1/cutlist';
*/
export default function () {
const bladeWidth = useBladeWidthSetting();
return computed(() => new Distance(bladeWidth.value + 'in').m);
const unit = useDistanceUnit();
return computed(() => new Distance(bladeWidth.value + unit.value).m);
}
2 changes: 2 additions & 0 deletions web/composables/useCutlistConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import type { Config } from '@aklinker1/cutlist';
export default createSharedComposable(() => {
const bladeWidth = useBladeWidth();
const optimize = useOptimizeFor();
const extraSpace = useExtraSpace();

return computed<Config>(() => ({
bladeWidth: bladeWidth.value,
optimize: optimize.value,
extraSpace: extraSpace.value,
}));
});
10 changes: 10 additions & 0 deletions web/composables/useExtraSpace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Distance } from '@aklinker1/cutlist';

/**
* Returns the extra space in standard units based off the settings.
*/
export default function () {
const extraSpace = useExtraSpaceSetting();
const unit = useDistanceUnit();
return computed(() => new Distance(extraSpace.value + unit.value).m);
}
8 changes: 8 additions & 0 deletions web/composables/useExtraSpaceSetting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Stores the preference from the settings page directly. Unless you're on the
* settings page, you should probably use `useExtraSpace` instead for the
* standardized value.
*/
export default createGlobalState(() =>
useLocalStorage('@cutlist/extra-space', '0'),
);

0 comments on commit 7b0e09a

Please sign in to comment.