Skip to content

Commit

Permalink
Allow muting sounds in workout logging (#1120)
Browse files Browse the repository at this point in the history
* feat(migrations): add new preference field

* feat(backend): add new field for logging workouts

* feat(frontend): allow editing new user preference

* feat(frontend): respect new workout logging preference
  • Loading branch information
IgnisDa authored Nov 27, 2024
1 parent b866e5b commit 1a7ff30
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 21 deletions.
6 changes: 3 additions & 3 deletions apps/frontend/app/routes/_dashboard.fitness.$action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default function Page() {
const [currentWorkout, setCurrentWorkout] = useCurrentWorkout();
const playCompleteTimerSound = () => {
const sound = new Howl({ src: ["/timer-completed.mp3"] });
sound.play();
if (!userPreferences.fitness.logging.muteSounds) sound.play();
if (document.visibilityState === "visible") return;
sendNotificationToServiceWorker(
"Timer completed",
Expand Down Expand Up @@ -964,7 +964,7 @@ const ExerciseDisplay = (props: {

const playAddSetSound = () => {
const sound = new Howl({ src: ["/add-set.mp3"] });
sound.play();
if (!userPreferences.fitness.logging.muteSounds) sound.play();
};
const [cameraFacing, toggleCameraFacing] = useToggle([
"environment",
Expand Down Expand Up @@ -1589,7 +1589,7 @@ const SetDisplay = (props: {

const playCheckSound = () => {
const sound = new Howl({ src: ["/check.mp3"] });
sound.play();
if (!userPreferences.fitness.logging.muteSounds) sound.play();
};

useDidUpdate(() => {
Expand Down
41 changes: 27 additions & 14 deletions apps/frontend/app/routes/_dashboard.settings.preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -586,20 +586,33 @@ export default function Page() {
</SimpleGrid>
</Input.Wrapper>
<Divider />
<Switch
label="Show details and history while editing workouts/templates"
size="xs"
disabled={!!isEditDisabled}
defaultChecked={
userPreferences.fitness.logging.showDetailsWhileEditing
}
onChange={(ev) => {
appendPref(
"fitness.logging.show_details_while_editing",
String(ev.currentTarget.checked),
);
}}
/>
{(["muteSounds", "showDetailsWhileEditing"] as const).map(
(option) => (
<Switch
key={option}
label={match(option)
.with(
"muteSounds",
() => "Mute sounds while logging workouts",
)
.with(
"showDetailsWhileEditing",
() =>
"Show details and history while editing workouts/templates",
)
.exhaustive()}
size="xs"
disabled={!!isEditDisabled}
defaultChecked={userPreferences.fitness.logging[option]}
onChange={(ev) => {
appendPref(
`fitness.logging.${snakeCase(option)}`,
String(ev.currentTarget.checked),
);
}}
/>
),
)}
<Divider />
<Input.Wrapper label="The default measurements you want to keep track of">
<SimpleGrid cols={2} mt="xs">
Expand Down
2 changes: 2 additions & 0 deletions crates/migrations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ mod m20241019_changes_for_issue_964;
mod m20241025_changes_for_issue_1084;
mod m20241110_changes_for_issue_1103;
mod m20241121_changes_for_issue_445;
mod m20241124_changes_for_issue_1118;

pub use m20230410_create_metadata::Metadata as AliasedMetadata;
pub use m20230413_create_person::Person as AliasedPerson;
Expand Down Expand Up @@ -119,6 +120,7 @@ impl MigratorTrait for Migrator {
Box::new(m20241025_changes_for_issue_1084::Migration),
Box::new(m20241110_changes_for_issue_1103::Migration),
Box::new(m20241121_changes_for_issue_445::Migration),
Box::new(m20241124_changes_for_issue_1118::Migration),
]
}
}
22 changes: 22 additions & 0 deletions crates/migrations/src/m20241124_changes_for_issue_1118.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
db.execute_unprepared(
r#"
UPDATE "user" SET "preferences" = jsonb_set("preferences", '{fitness,logging,mute_sounds}', 'false');
"#,
)
.await?;
Ok(())
}

async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
}
1 change: 1 addition & 0 deletions crates/models/user/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub struct UserFitnessFeaturesEnabledPreferences {
pub struct UserFitnessLoggingPreferences {
#[educe(Default = true)]
pub show_details_while_editing: bool,
pub mute_sounds: bool,
}

#[derive(
Expand Down
3 changes: 3 additions & 0 deletions crates/services/user/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ impl UserService {
preferences.fitness.logging.show_details_while_editing =
value_bool.unwrap();
}
"mute_sounds" => {
preferences.fitness.logging.mute_sounds = value_bool.unwrap();
}
_ => return Err(err()),
},
_ => return Err(err()),
Expand Down
4 changes: 2 additions & 2 deletions libs/generated/src/graphql/backend/gql.ts

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions libs/generated/src/graphql/backend/graphql.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions libs/generated/src/graphql/backend/types.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,7 @@ export type UserFitnessFeaturesEnabledPreferences = {

export type UserFitnessLoggingPreferences = {
__typename?: 'UserFitnessLoggingPreferences';
muteSounds: Scalars['Boolean']['output'];
showDetailsWhileEditing: Scalars['Boolean']['output'];
};

Expand Down
1 change: 1 addition & 0 deletions libs/graphql/src/backend/queries/UserDetails.gql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ query UserDetails {
}
fitness {
logging {
muteSounds
showDetailsWhileEditing
}
exercises {
Expand Down

0 comments on commit 1a7ff30

Please sign in to comment.