Skip to content

Commit

Permalink
Reset preferences to default btn (#385)
Browse files Browse the repository at this point in the history
* fix(frontend): do not allow reorder if pref change disabled

* fix(frontend): make text smaller

* perf(backend): select only needed attributes

* perf(backend): select only partial model

* fix(backend): introduce function to get entire user

* feat(backend): allow setting preferences to default

* feat(frontend): allow resetting preferences

* fix(frontend): reload page when preferences are reloaded

* build(backend): bump version

* fix(frontend): wait for response before reload
  • Loading branch information
IgnisDa authored Oct 3, 2023
1 parent 0627057 commit 9586611
Show file tree
Hide file tree
Showing 9 changed files with 410 additions and 231 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 = "2.20.0"
version = "2.20.1"
edition = "2021"
repository = "https://github.com/IgnisDa/ryot"
license = "GPL-V3"
Expand Down
28 changes: 27 additions & 1 deletion apps/backend/src/entities/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use argon2::{
};
use async_graphql::SimpleObject;
use async_trait::async_trait;
use sea_orm::{entity::prelude::*, ActiveValue};
use sea_orm::{entity::prelude::*, ActiveValue, FromQueryResult};
use serde::{Deserialize, Serialize};

use crate::{
Expand All @@ -19,6 +19,32 @@ fn get_hasher() -> Argon2<'static> {
Argon2::default()
}

#[derive(
Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromQueryResult, DerivePartialModel,
)]
#[sea_orm(entity = "Entity")]
pub struct UserWithOnlyPreferences {
pub preferences: UserPreferences,
}

#[derive(
Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromQueryResult, DerivePartialModel,
)]
#[sea_orm(entity = "Entity")]
pub struct UserWithOnlyIntegrationsAndNotifications {
pub yank_integrations: Option<UserYankIntegrations>,
pub sink_integrations: UserSinkIntegrations,
pub notifications: UserNotifications,
}

#[derive(
Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromQueryResult, DerivePartialModel,
)]
#[sea_orm(entity = "Entity")]
pub struct UserWithOnlySummary {
pub summary: Option<UserSummary>,
}

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, SimpleObject)]
#[graphql(name = "User")]
#[sea_orm(table_name = "user")]
Expand Down
5 changes: 3 additions & 2 deletions apps/backend/src/fitness/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
entities::{
exercise,
prelude::{Exercise, UserMeasurement, UserToExercise, Workout},
user::UserWithOnlyPreferences,
user_measurement, user_to_exercise, workout,
},
file_storage::FileStorageService,
Expand All @@ -34,7 +35,7 @@ use crate::{
SearchDetails, SearchInput, SearchResults, StoredUrl,
},
traits::AuthProvider,
utils::{get_case_insensitive_like_query, user_by_id},
utils::{get_case_insensitive_like_query, partial_user_by_id},
};

use super::logic::UserWorkoutInput;
Expand Down Expand Up @@ -505,7 +506,7 @@ impl ExerciseService {

#[instrument(skip(self))]
async fn create_user_workout(&self, user_id: i32, input: UserWorkoutInput) -> Result<String> {
let user = user_by_id(&self.db, user_id).await?;
let user = partial_user_by_id::<UserWithOnlyPreferences>(&self.db, user_id).await?;
let sf = Sonyflake::new().unwrap();
let id = sf.next_id().unwrap().to_string();
tracing::trace!("Creating new workout with id: {}", id);
Expand Down
11 changes: 6 additions & 5 deletions apps/backend/src/importer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tracing::instrument;

use crate::{
background::ApplicationJob,
entities::{import_report, prelude::ImportReport},
entities::{import_report, prelude::ImportReport, user::UserWithOnlyPreferences},
migrator::{ImportSource, MetadataLot},
miscellaneous::resolver::MiscellaneousService,
models::media::{
Expand All @@ -23,7 +23,7 @@ use crate::{
},
traits::AuthProvider,
users::UserReviewScale,
utils::user_by_id,
utils::partial_user_by_id,
};

mod goodreads;
Expand Down Expand Up @@ -260,9 +260,10 @@ impl ImporterService {
.await?
}
};
let preferences = user_by_id(&self.media_service.db, user_id)
.await?
.preferences;
let preferences =
partial_user_by_id::<UserWithOnlyPreferences>(&self.media_service.db, user_id)
.await?
.preferences;
import.media = import
.media
.into_iter()
Expand Down
Loading

0 comments on commit 9586611

Please sign in to comment.