Skip to content

Commit 5d807e9

Browse files
authored
Updates (#917)
* fix(frontend): do not render merge metadata modal inside menu * feat(frontend): display season using a combination of accordion and virtuoso list * feat(backend): do not store duplicated workout data * perf(backend): do not get entire records in history * refactor(backend): change all edits to updates for mutation names * chore(frontend): start adapting to new gql schema * feat(frontend): adapt to new gql schema * refactor(frontend): do not send a lot of data as prop * feat(frontend): virtualize exercise history * fix(frontend): change height of component * feat(frontend): add scroll margin * fix(frontend): do not mount tabs to save query * feat(database): migration to add new column to integration * feat(backend): mutation to update an integration * feat(frontend): respect new column for integration Disabled integrations will error out. * feat(frontend): open modal to edit integration * feat(frontend): actually perform the integration update * feat(database): migration to add new column to notification platform * feat(backend): respect new column for notification platform * feat(backend): allow editing notification platforms * feat(frontend): allow toggling notification pause/play state * fix(frontend): layout issues
1 parent a6e7bfc commit 5d807e9

30 files changed

+824
-506
lines changed

apps/backend/src/entities/integration.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct Model {
2121
pub user_id: String,
2222
pub lot: IntegrationLot,
2323
pub source: IntegrationSource,
24+
pub is_disabled: Option<bool>,
2425
#[graphql(skip_input)]
2526
pub created_on: DateTimeUtc,
2627
#[graphql(skip_input)]

apps/backend/src/entities/notification_platform.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct Model {
1616
pub id: String,
1717
pub lot: NotificationPlatformLot,
1818
pub created_on: DateTimeWithTimeZone,
19+
pub is_disabled: Option<bool>,
1920
#[graphql(skip)]
2021
pub platform_specifics: NotificationPlatformSpecifics,
2122
pub description: String,

apps/backend/src/fitness/logic.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use sea_orm::{
1010

1111
use crate::{
1212
entities::{
13-
prelude::{Exercise, UserToEntity},
13+
prelude::{Exercise, UserToEntity, Workout},
1414
user_to_entity, workout,
1515
},
1616
models::fitness::{
@@ -237,7 +237,13 @@ impl UserWorkoutInput {
237237
.and_then(|record| record.sets.first());
238238
let set = sets.get_mut(set_idx).unwrap();
239239
if let Some(r) = possible_record {
240-
if set.get_personal_best(best_type) > r.data.get_personal_best(best_type) {
240+
let workout = Workout::find_by_id(r.workout_id.clone())
241+
.one(db)
242+
.await?
243+
.unwrap();
244+
let workout_set =
245+
workout.information.exercises[r.exercise_idx].sets[r.set_idx].clone();
246+
if set.get_personal_best(best_type) > workout_set.get_personal_best(best_type) {
241247
set.personal_bests.push(*best_type);
242248
total.personal_bests_achieved += 1;
243249
}
@@ -251,10 +257,8 @@ impl UserWorkoutInput {
251257
for best in set.personal_bests.iter() {
252258
let to_insert_record = ExerciseBestSetRecord {
253259
workout_id: id.clone(),
254-
workout_done_on: input.end_time,
255260
exercise_idx,
256261
set_idx,
257-
data: set.clone(),
258262
};
259263
if let Some(record) = personal_bests.iter_mut().find(|pb| pb.lot == *best) {
260264
let mut data =

apps/backend/src/fitness/resolver.rs

+17-55
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use crate::{
3030
models::{
3131
fitness::{
3232
Exercise as GithubExercise, ExerciseAttributes, ExerciseCategory,
33-
GithubExerciseAttributes, UserExerciseInput, UserWorkoutInput, UserWorkoutSetRecord,
34-
WorkoutListItem, WorkoutSetRecord,
33+
GithubExerciseAttributes, UserExerciseInput, UserToExerciseHistoryExtraInformation,
34+
UserWorkoutInput, UserWorkoutSetRecord, WorkoutListItem,
3535
},
3636
ChangeCollectionToEntityInput, SearchDetails, SearchInput, SearchResults, StoredUrl,
3737
},
@@ -94,31 +94,22 @@ struct UserMeasurementsListInput {
9494
end_time: Option<DateTimeUtc>,
9595
}
9696

97-
#[derive(Debug, Serialize, Deserialize, SimpleObject, Clone)]
98-
struct UserExerciseHistoryInformation {
99-
workout_id: String,
100-
workout_name: String,
101-
workout_time: DateTimeUtc,
102-
index: usize,
103-
sets: Vec<WorkoutSetRecord>,
104-
}
105-
10697
#[derive(Debug, Serialize, Deserialize, SimpleObject, Clone)]
10798
struct UserExerciseDetails {
10899
details: Option<user_to_entity::Model>,
109-
history: Option<Vec<UserExerciseHistoryInformation>>,
100+
history: Option<Vec<UserToExerciseHistoryExtraInformation>>,
110101
collections: Vec<collection::Model>,
111102
}
112103

113104
#[derive(Clone, Debug, Deserialize, Serialize, InputObject)]
114-
struct EditUserWorkoutInput {
105+
struct UpdateUserWorkoutInput {
115106
id: String,
116107
start_time: Option<DateTimeUtc>,
117108
end_time: Option<DateTimeUtc>,
118109
}
119110

120111
#[derive(Clone, Debug, Deserialize, Serialize, InputObject)]
121-
struct EditCustomExerciseInput {
112+
struct UpdateCustomExerciseInput {
122113
old_name: String,
123114
should_delete: Option<bool>,
124115
#[graphql(flatten)]
@@ -249,14 +240,14 @@ impl ExerciseMutation {
249240
}
250241

251242
/// Change the details about a user's workout.
252-
async fn edit_user_workout(
243+
async fn update_user_workout(
253244
&self,
254245
gql_ctx: &Context<'_>,
255-
input: EditUserWorkoutInput,
246+
input: UpdateUserWorkoutInput,
256247
) -> Result<bool> {
257248
let service = gql_ctx.data_unchecked::<Arc<ExerciseService>>();
258249
let user_id = self.user_id_from_ctx(gql_ctx).await?;
259-
service.edit_user_workout(user_id, input).await
250+
service.update_user_workout(user_id, input).await
260251
}
261252

262253
/// Delete a workout and remove all exercise associations.
@@ -277,15 +268,15 @@ impl ExerciseMutation {
277268
service.create_custom_exercise(user_id, input).await
278269
}
279270

280-
/// Edit a custom exercise.
281-
async fn edit_custom_exercise(
271+
/// Update a custom exercise.
272+
async fn update_custom_exercise(
282273
&self,
283274
gql_ctx: &Context<'_>,
284-
input: EditCustomExerciseInput,
275+
input: UpdateCustomExerciseInput,
285276
) -> Result<bool> {
286277
let service = gql_ctx.data_unchecked::<Arc<ExerciseService>>();
287278
let user_id = self.user_id_from_ctx(gql_ctx).await?;
288-
service.edit_custom_exercise(user_id, input).await
279+
service.update_custom_exercise(user_id, input).await
289280
}
290281
}
291282

@@ -406,36 +397,7 @@ impl ExerciseService {
406397
.exercise_extra_information
407398
.clone()
408399
.unwrap_or_default();
409-
let workouts = Workout::find()
410-
.filter(
411-
workout::Column::Id.is_in(
412-
user_to_exercise_extra_information
413-
.history
414-
.iter()
415-
.map(|h| h.workout_id.clone()),
416-
),
417-
)
418-
.order_by_desc(workout::Column::EndTime)
419-
.all(&self.db)
420-
.await?;
421-
let history = workouts
422-
.into_iter()
423-
.map(|w| {
424-
let element = user_to_exercise_extra_information
425-
.history
426-
.iter()
427-
.find(|h| h.workout_id == w.id)
428-
.unwrap();
429-
UserExerciseHistoryInformation {
430-
workout_id: w.id,
431-
workout_name: w.name,
432-
workout_time: w.start_time,
433-
index: element.idx,
434-
sets: w.information.exercises[element.idx].sets.clone(),
435-
}
436-
})
437-
.collect_vec();
438-
resp.history = Some(history);
400+
resp.history = Some(user_to_exercise_extra_information.history);
439401
resp.details = Some(association);
440402
}
441403
Ok(resp)
@@ -738,10 +700,10 @@ impl ExerciseService {
738700
Ok(identifier)
739701
}
740702

741-
async fn edit_user_workout(
703+
async fn update_user_workout(
742704
&self,
743705
user_id: String,
744-
input: EditUserWorkoutInput,
706+
input: UpdateUserWorkoutInput,
745707
) -> Result<bool> {
746708
if let Some(wkt) = Workout::find()
747709
.filter(workout::Column::UserId.eq(user_id))
@@ -899,10 +861,10 @@ impl ExerciseService {
899861
}
900862
}
901863

902-
async fn edit_custom_exercise(
864+
async fn update_custom_exercise(
903865
&self,
904866
user_id: String,
905-
input: EditCustomExerciseInput,
867+
input: UpdateCustomExerciseInput,
906868
) -> Result<bool> {
907869
let entities = UserToEntity::find()
908870
.filter(user_to_entity::Column::UserId.eq(&user_id))

0 commit comments

Comments
 (0)