Skip to content

Commit

Permalink
Add new exercise lots (#1228)
Browse files Browse the repository at this point in the history
* refactor(models/enum): change order of attributes

* feat(backend): add new exercise lot

* feat(frontend): handle new exercise lot

* ci: Run CI

* chore(utils/common): add personal bests to exercise lot

* build(models/enum): add new dependency

* refactor(backend): associate named meta

* feat(backend): add new personal best type

* chore(frontend): adapt to new gql schema

* ci: Run CI

* refactor(backend): move to using enum meta

* refactor(backend): move to using enum meta for metadata group lots

* fix(frontend): display stuff regardless

* chore(models/common): change order of attributes

* chore(models/common): add newline
  • Loading branch information
IgnisDa authored Feb 2, 2025
1 parent 654c3f5 commit a353de9
Show file tree
Hide file tree
Showing 17 changed files with 396 additions and 308 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion apps/frontend/app/components/fitness.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export const getSetStatisticsTextToDisplay = (
unit: UserUnitSystem,
) => {
return match(lot)
.with(ExerciseLot.Reps, () => [`${statistic.reps} reps`, undefined])
.with(ExerciseLot.RepsAndDuration, () => [
`${statistic.reps} reps for ${Number(statistic.duration).toFixed(2)} min`,
undefined,
])
.with(ExerciseLot.DistanceAndDuration, () => [
`${displayDistanceWithUnit(unit, statistic.distance)} for ${Number(
statistic.duration,
Expand All @@ -75,13 +80,16 @@ export const getSetStatisticsTextToDisplay = (
`${Number(statistic.duration).toFixed(2)} min`,
undefined,
])
.with(ExerciseLot.Reps, () => [`${statistic.reps} reps`, undefined])
.with(ExerciseLot.RepsAndWeight, () => [
statistic.weight && statistic.weight !== "0"
? `${displayWeightWithUnit(unit, statistic.weight)} × ${statistic.reps}`
: `${statistic.reps} reps`,
statistic.oneRm ? `${Number(statistic.oneRm).toFixed(1)} RM` : null,
])
.with(ExerciseLot.RepsAndDurationAndDistance, () => [
`${displayDistanceWithUnit(unit, statistic.distance)} × ${statistic.reps}`,
`${Number(statistic.duration).toFixed(2)} min`,
])
.exhaustive();
};

Expand Down
36 changes: 28 additions & 8 deletions apps/frontend/app/routes/_dashboard.fitness.$action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1461,10 +1461,17 @@ const ExerciseDisplay = (props: {

const exerciseHistory = userExerciseDetails?.history;
const [durationCol, distanceCol, weightCol, repsCol] = match(exercise.lot)
.with(ExerciseLot.DistanceAndDuration, () => [true, true, false, false])
.with(ExerciseLot.Reps, () => [false, false, false, true])
.with(ExerciseLot.Duration, () => [true, false, false, false])
.with(ExerciseLot.RepsAndWeight, () => [false, false, true, true])
.with(ExerciseLot.Reps, () => [false, false, false, true])
.with(ExerciseLot.RepsAndDuration, () => [true, false, false, true])
.with(ExerciseLot.DistanceAndDuration, () => [true, true, false, false])
.with(ExerciseLot.RepsAndDurationAndDistance, () => [
true,
true,
false,
true,
])
.exhaustive();
const toBeDisplayedColumns =
[durationCol, distanceCol, weightCol, repsCol].filter(Boolean).length + 1;
Expand Down Expand Up @@ -2289,24 +2296,37 @@ const SetDisplay = (props: {
variant={set.confirmedAt ? "filled" : "outline"}
disabled={
!match(exercise.lot)
.with(ExerciseLot.Reps, () =>
isString(set.statistic.reps),
)
.with(ExerciseLot.Duration, () =>
isString(set.statistic.duration),
)
.with(
ExerciseLot.RepsAndDuration,
() =>
isString(set.statistic.reps) &&
isString(set.statistic.duration),
)
.with(
ExerciseLot.DistanceAndDuration,
() =>
isString(set.statistic.distance) &&
isString(set.statistic.duration),
)
.with(ExerciseLot.Duration, () =>
isString(set.statistic.duration),
)
.with(ExerciseLot.Reps, () =>
isString(set.statistic.reps),
)
.with(
ExerciseLot.RepsAndWeight,
() =>
isString(set.statistic.reps) &&
isString(set.statistic.weight),
)
.with(
ExerciseLot.RepsAndDurationAndDistance,
() =>
isString(set.statistic.reps) &&
isString(set.statistic.duration) &&
isString(set.statistic.distance),
)
.exhaustive()
}
onClick={async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,10 @@ export default function Page() {
WorkoutSetPersonalBest.Weight,
() => stat?.weight,
)
.with(
WorkoutSetPersonalBest.Distance,
() => stat?.distance,
)
.exhaustive();
return {
name: dayjsLib(h.workoutEndOn).format("DD/MM/YYYY"),
Expand Down Expand Up @@ -745,6 +749,9 @@ const DisplayPersonalBest = (props: {
displayWeightWithUnit(unitSystem, set.statistic.weight),
)
.with(WorkoutSetPersonalBest.Pace, () => `${set.statistic.pace}/min`)
.with(WorkoutSetPersonalBest.Distance, () =>
displayDistanceWithUnit(unitSystem, set.statistic.distance),
)
.exhaustive()}
</Text>
<Group>
Expand Down
84 changes: 40 additions & 44 deletions apps/frontend/app/routes/_dashboard.media.$action.$lot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,50 +336,46 @@ export default function Page() {
<FiltersModalForm />
</FiltersModal>
</Group>
{loaderData.mediaList.list.response.details.total > 0 ? (
<>
<DisplayListDetailsAndRefresh
cacheId={loaderData.mediaList.list.cacheId}
total={loaderData.mediaList.list.response.details.total}
/>
{(loaderData.mediaList?.url.startDateRange ||
loaderData.mediaList?.url.endDateRange) &&
!coreDetails.isServerKeyValidated ? (
<ProRequiredAlert alertText="Ryot Pro is required to filter by dates" />
) : (
<ApplicationGrid>
{loaderData.mediaList.list.response.items.map((item) => {
const becItem = {
entityId: item,
entityLot: EntityLot.Metadata,
};
const isAdded = bulkEditingCollection.isAdded(becItem);
return (
<MetadataDisplayItem
key={item}
metadataId={item}
rightLabelHistory
topRight={
bulkEditingState &&
bulkEditingState.data.action === "add" ? (
<ActionIcon
variant={isAdded ? "filled" : "transparent"}
color="green"
onClick={() => {
if (isAdded) bulkEditingState.remove(becItem);
else bulkEditingState.add(becItem);
}}
>
<IconCheck size={18} />
</ActionIcon>
) : undefined
}
/>
);
})}
</ApplicationGrid>
)}
</>
<DisplayListDetailsAndRefresh
cacheId={loaderData.mediaList.list.cacheId}
total={loaderData.mediaList.list.response.details.total}
/>
{(loaderData.mediaList?.url.startDateRange ||
loaderData.mediaList?.url.endDateRange) &&
!coreDetails.isServerKeyValidated ? (
<ProRequiredAlert alertText="Ryot Pro is required to filter by dates" />
) : loaderData.mediaList.list.response.details.total > 0 ? (
<ApplicationGrid>
{loaderData.mediaList.list.response.items.map((item) => {
const becItem = {
entityId: item,
entityLot: EntityLot.Metadata,
};
const isAdded = bulkEditingCollection.isAdded(becItem);
return (
<MetadataDisplayItem
key={item}
metadataId={item}
rightLabelHistory
topRight={
bulkEditingState &&
bulkEditingState.data.action === "add" ? (
<ActionIcon
variant={isAdded ? "filled" : "transparent"}
color="green"
onClick={() => {
if (isAdded) bulkEditingState.remove(becItem);
else bulkEditingState.add(becItem);
}}
>
<IconCheck size={18} />
</ActionIcon>
) : undefined
}
/>
);
})}
</ApplicationGrid>
) : (
<Text>You do not have any saved yet</Text>
)}
Expand Down
5 changes: 3 additions & 2 deletions crates/models/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub enum DefaultCollection {

meta! {
DefaultCollection, (Option<Vec<CollectionExtraInformation>>, &'static str);

Watchlist, (None, "Things I want to watch in the future.");
InProgress, (None, "Media items that I am currently watching.");
Completed, (None, "Media items that I have completed.");
Expand All @@ -109,15 +110,15 @@ meta! {
Reminders, (Some(
vec![
CollectionExtraInformation {
name: "Reminder".to_string(),
required: Some(true),
name: "Reminder".to_string(),
lot: CollectionExtraInformationLot::Date,
description: "When do you want to be reminded?".to_string(),
..Default::default()
},
CollectionExtraInformation {
name: "Text".to_string(),
required: Some(true),
name: "Text".to_string(),
lot: CollectionExtraInformationLot::String,
description: "What do you want to be reminded about?".to_string(),
..Default::default()
Expand Down
1 change: 1 addition & 0 deletions crates/models/enum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
async-graphql = { workspace = true }
enum_meta = { workspace = true }
schematic = { workspace = true }
sea-orm = { workspace = true }
sea-orm-migration = { workspace = true }
Expand Down
Loading

0 comments on commit a353de9

Please sign in to comment.