Skip to content

Commit

Permalink
General changes (#428)
Browse files Browse the repository at this point in the history
* feat(backend): eliminate invalid stats

* feat(backend): remove useless mutation

* chore(frontend): adapt to new gql schema

* build(backend): bump version
  • Loading branch information
IgnisDa authored Oct 23, 2023
1 parent 77770c0 commit 5865d25
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 137 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ryot"
version = "3.0.12"
version = "3.0.13"
edition = "2021"
repository = "https://github.com/IgnisDa/ryot"
license = "GPL-V3"
Expand Down
22 changes: 21 additions & 1 deletion apps/backend/src/fitness/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
ExerciseBestSetRecord, ProcessedExercise, UserToExerciseBestSetExtraInformation,
UserToExerciseExtraInformation, UserToExerciseHistoryExtraInformation, UserWorkoutInput,
UserWorkoutSetRecord, WorkoutInformation, WorkoutSetPersonalBest, WorkoutSetRecord,
WorkoutSummary, WorkoutSummaryExercise, WorkoutTotalMeasurement,
WorkoutSetStatistic, WorkoutSummary, WorkoutSummaryExercise, WorkoutTotalMeasurement,
},
users::{UserExercisePreferences, UserUnitSystem},
};
Expand Down Expand Up @@ -76,6 +76,25 @@ impl UserWorkoutSetRecord {
}
};
}

/// Set the invalid statistics to `None` according to the type of exercise.
pub fn remove_invalids(&mut self, exercise_lot: &ExerciseLot) {
let mut stats = WorkoutSetStatistic {
..Default::default()
};
match exercise_lot {
ExerciseLot::Duration => stats.duration = self.statistic.duration,
ExerciseLot::DistanceAndDuration => {
stats.distance = self.statistic.distance;
stats.duration = self.statistic.duration;
}
ExerciseLot::RepsAndWeight => {
stats.reps = self.statistic.reps;
stats.weight = self.statistic.weight;
}
}
self.statistic = stats;
}
}

impl UserWorkoutInput {
Expand Down Expand Up @@ -140,6 +159,7 @@ impl UserWorkoutInput {
};
for set in ex.sets.iter_mut() {
set.translate_units(preferences.unit_system);
set.remove_invalids(&db_ex.lot);
if let Some(r) = set.statistic.reps {
total.reps += r;
if let Some(w) = set.statistic.weight {
Expand Down
11 changes: 0 additions & 11 deletions apps/backend/src/miscellaneous/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,17 +1034,6 @@ impl MiscellaneousMutation {
service.create_custom_media(input, user_id).await
}

/// Mark a user's progress on a specific media item.
async fn progress_update(
&self,
gql_ctx: &Context<'_>,
input: ProgressUpdateInput,
) -> Result<ProgressUpdateResultUnion> {
let service = gql_ctx.data_unchecked::<Arc<MiscellaneousService>>();
let user_id = service.user_id_from_ctx(gql_ctx).await?;
service.progress_update(input, user_id).await
}

/// Deploy job to update progress of media items in bulk.
async fn deploy_bulk_progress_update(
&self,
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ pub mod fitness {
SimpleObject,
InputObject,
Schematic,
Default,
)]
#[graphql(input_name = "SetStatisticInput")]
pub struct WorkoutSetStatistic {
Expand Down
6 changes: 3 additions & 3 deletions apps/frontend/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ const DisplayStatForMediaType = (props: {
) : undefined;
};

const Section = (props: {children: JSX.Element[]}) => {
return <Stack gap="sm">{props.children}</Stack>
}
const Section = (props: { children: JSX.Element[] }) => {
return <Stack gap="sm">{props.children}</Stack>;
};

const Page: NextPageWithLayout = () => {
const theme = useMantineTheme();
Expand Down
86 changes: 52 additions & 34 deletions apps/frontend/src/pages/media/item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import {
type DeleteMediaReminderMutationVariables,
DeleteSeenItemDocument,
type DeleteSeenItemMutationVariables,
DeployBulkProgressUpdateDocument,
type DeployBulkProgressUpdateMutationVariables,
DeployUpdateMetadataJobDocument,
type DeployUpdateMetadataJobMutationVariables,
EntityLot,
Expand All @@ -59,8 +61,6 @@ import {
MetadataLot,
MetadataSource,
MetadataVideoSource,
ProgressUpdateDocument,
type ProgressUpdateMutationVariables,
SeenState,
ToggleMediaMonitorDocument,
type ToggleMediaMonitorMutationVariables,
Expand Down Expand Up @@ -117,16 +117,20 @@ const ProgressModal = (props: {
}) => {
const [value, setValue] = useState(props.progress);
const progressUpdate = useMutation({
mutationFn: async (variables: ProgressUpdateMutationVariables) => {
const { progressUpdate } = await gqlClient.request(
ProgressUpdateDocument,
mutationFn: async (
variables: DeployBulkProgressUpdateMutationVariables,
) => {
const { deployBulkProgressUpdate } = await gqlClient.request(
DeployBulkProgressUpdateDocument,
variables,
);
return progressUpdate;
return deployBulkProgressUpdate;
},
onSuccess: () => {
props.refetch();
props.onClose();
setTimeout(() => {
props.refetch();
}, 1000);
},
});

Expand Down Expand Up @@ -196,11 +200,13 @@ const ProgressModal = (props: {
variant="outline"
onClick={async () => {
await progressUpdate.mutateAsync({
input: {
progress: value,
metadataId: props.metadataId,
date: DateTime.now().toISODate(),
},
input: [
{
progress: value,
metadataId: props.metadataId,
date: DateTime.now().toISODate(),
},
],
});
}}
>
Expand Down Expand Up @@ -447,15 +453,19 @@ const Page: NextPageWithLayout = () => {
enabled: !!metadataId,
});
const progressUpdate = useMutation({
mutationFn: async (variables: ProgressUpdateMutationVariables) => {
const { progressUpdate } = await gqlClient.request(
ProgressUpdateDocument,
mutationFn: async (
variables: DeployBulkProgressUpdateMutationVariables,
) => {
const { deployBulkProgressUpdate } = await gqlClient.request(
DeployBulkProgressUpdateDocument,
variables,
);
return progressUpdate;
return deployBulkProgressUpdate;
},
onSuccess: () => {
userMediaDetails.refetch();
setTimeout(() => {
userMediaDetails.refetch();
}, 1000);
},
});
const deleteMediaReminder = useMutation({
Expand Down Expand Up @@ -533,10 +543,12 @@ const Page: NextPageWithLayout = () => {
<Menu.Item
onClick={() => {
progressUpdate.mutate({
input: {
metadataId: metadataId,
changeState: SeenState.OnAHold,
},
input: [
{
metadataId: metadataId,
changeState: SeenState.OnAHold,
},
],
});
}}
>
Expand All @@ -554,10 +566,12 @@ const Page: NextPageWithLayout = () => {
);
if (yes)
progressUpdate.mutate({
input: {
metadataId: metadataId,
changeState: SeenState.Dropped,
},
input: [
{
metadataId: metadataId,
changeState: SeenState.Dropped,
},
],
});
}}
>
Expand Down Expand Up @@ -1034,11 +1048,13 @@ const Page: NextPageWithLayout = () => {
<Menu.Item
onClick={async () => {
await progressUpdate.mutateAsync({
input: {
progress: 100,
metadataId: metadataId,
date: DateTime.now().toISODate(),
},
input: [
{
progress: 100,
metadataId: metadataId,
date: DateTime.now().toISODate(),
},
],
});
}}
>
Expand All @@ -1061,10 +1077,12 @@ const Page: NextPageWithLayout = () => {
<Menu.Item
onClick={async () => {
await progressUpdate.mutateAsync({
input: {
metadataId: metadataId,
progress: 0,
},
input: [
{
metadataId: metadataId,
progress: 0,
},
],
});
}}
>
Expand Down
Loading

0 comments on commit 5865d25

Please sign in to comment.