Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
- adding medium size
- add clip display
- sanitize inWeight before calculation
- spacing in results
- fix select barbell weight after changing weight set
- reactive results when select/deselect clip
  • Loading branch information
jvogit committed Mar 6, 2024
1 parent f894546 commit ad2ba28
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
7 changes: 5 additions & 2 deletions svelteww/src/lib/WeightCalculatorlatorForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
selectedBarbellWeight) /
2;
if (isClipWeightSelected) inWeight -= selectedWeightPlateSet.clipWeight;
inWeight = Math.max(0, inWeight);
out = what_weights_unlimited(
inWeight,
Expand All @@ -43,7 +44,7 @@
<h1>Calculate Weights</h1>
<form on:submit|preventDefault={calculate}>
<h2>Weight Plates Set</h2>
<select bind:value={selectedWeightPlateSet}>
<select bind:value={selectedWeightPlateSet} on:change={() => selectedBarbellWeight = selectedWeightPlateSet.barbellWeights[0]}>
{#each weight_plates as weight_plate}
<option value={weight_plate}>
{weight_plate.displayName}
Expand All @@ -70,6 +71,7 @@
<input
type="checkbox"
bind:checked={isClipWeightSelected}
on:change={calculate}
name="clip weight"
/>
{selectedWeightPlateSet.fmtWeightWithUnit(
Expand All @@ -84,11 +86,12 @@

{#if out}
<p>The minimum amount needed is: {outMinAmt}</p>
<div style="width: 17rem;">
<div style="display: flex; flex-direction: column; gap: 10px; width: 17rem;">
{#each outWeights as weights}
<BarbellWeight
weights={weights.sort((a, b) => b - a)}
weightPlateStyleMap={selectedWeightPlateSet.weightsStyle}
clipped={isClipWeightSelected}
/>
{/each}
</div>
Expand Down
30 changes: 29 additions & 1 deletion svelteww/src/lib/weightplate/BarbellWeight.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
number,
[WeightPlateSize, WeightPlateColor]
>;
export let clipped: boolean;
const getWeightPlateSize = (weight: number) => {
return weightPlateStyleMap.get(weight)![0];
Expand All @@ -18,12 +19,28 @@
const getWeightPlateColor = (weight: number) => {
return weightPlateStyleMap.get(weight)![1];
};
$: clipped_weights = weights.filter(
(weight) => getWeightPlateSize(weight) != WeightPlateSize.SMALL,
);
$: unclipped_weights = weights.filter(
(weight) => getWeightPlateSize(weight) === WeightPlateSize.SMALL,
);
</script>

<div class="container">
<div class="barbell-shaft" />
<div class="barbell-collar" />
{#each weights as weight}
{#each clipped_weights as weight}
<WeightPlate
weightSize={getWeightPlateSize(weight)}
weightColor={getWeightPlateColor(weight)}
/>
{/each}
{#if clipped}
<div class="barbell-clip" />
{/if}
{#each unclipped_weights as weight}
<WeightPlate
weightSize={getWeightPlateSize(weight)}
weightColor={getWeightPlateColor(weight)}
Expand All @@ -40,6 +57,17 @@
height: 100%;
}
.barbell-clip {
width: 35px;
height: 55px;
border-radius: 2px;
background-image: linear-gradient(
to right,
silver 0 50%,
gray 50% 100%
);
}
.barbell-sleeve {
flex-grow: 1;
height: 25px;
Expand Down
8 changes: 8 additions & 0 deletions svelteww/src/lib/weightplate/WeightPlate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
border-radius: 3px;
}
.weight-plate-med {
width: 15px;
height: 135px;
border-style: solid;
border-width: 1px;
border-radius: 3px;
}
.weight-plate-sml {
width: 15px;
height: 100px;
Expand Down
1 change: 1 addition & 0 deletions svelteww/src/lib/weightplate/weighttypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum WeightPlateSize {
STD = "weight-plate-std",
MEDIUM = "weight-plate-med",
SMALL = "weight-plate-sml",
}

Expand Down
11 changes: 6 additions & 5 deletions svelteww/src/routes/weight/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
[2, [WeightPlateSize.STD, WeightPlateColor.BLUE]],
[3, [WeightPlateSize.STD, WeightPlateColor.YELLOW]],
[4, [WeightPlateSize.STD, WeightPlateColor.GREEN]],
[5, [WeightPlateSize.STD, WeightPlateColor.WHITE]],
[6, [WeightPlateSize.SMALL, WeightPlateColor.RED]],
[5, [WeightPlateSize.MEDIUM, WeightPlateColor.WHITE]],
[6, [WeightPlateSize.MEDIUM, WeightPlateColor.RED]],
[7, [WeightPlateSize.SMALL, WeightPlateColor.BLUE]],
[8, [WeightPlateSize.SMALL, WeightPlateColor.YELLOW]],
[9, [WeightPlateSize.SMALL, WeightPlateColor.GREEN]],
[10, [WeightPlateSize.SMALL, WeightPlateColor.WHITE]],
]);
]);
</script>

<div style="width: 17rem;">
<div>
<BarbellWeight
weights={[1, 2, 3, 4]}
weights={[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}
weightPlateStyleMap={weightMaps}
clipped={true}
/>
</div>

0 comments on commit ad2ba28

Please sign in to comment.