mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 09:04:55 +00:00
feat: preferences syncing frontend (#7192)
* feat: prefs frontend * fix: DI issue * fix: lint * feat: appearance settings cleanup + fix settings, remove pinia * fix: sync btn when logged out * fix: prepr * fix: sidebar issue * feat: language coverage + cleanup * feat: cleanup lang settings * fix: fmt * fix: CI * fix: ci * fix: storybook * feat: bring back loader/game version sort --------- Co-authored-by: tdgao <mr.trumgao@gmail.com>
This commit is contained in:
@@ -109,6 +109,51 @@ pub async fn get_user_collections(user_id: &str) -> crate::Result<Value> {
|
||||
.await
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn get_user_preferences(user_id: &str) -> crate::Result<Value> {
|
||||
let state = State::get().await?;
|
||||
let user_id = urlencoding::encode(user_id);
|
||||
|
||||
fetch_json(
|
||||
Method::GET,
|
||||
&format!(
|
||||
"{}user/{}/preferences",
|
||||
env!("MODRINTH_API_URL_V3"),
|
||||
user_id
|
||||
),
|
||||
None,
|
||||
None,
|
||||
Some("/v3/user/:id/preferences"),
|
||||
&state.api_semaphore,
|
||||
&state.pool,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(preferences))]
|
||||
pub async fn patch_user_preferences(
|
||||
user_id: &str,
|
||||
preferences: Value,
|
||||
) -> crate::Result<Value> {
|
||||
let state = State::get().await?;
|
||||
let user_id = urlencoding::encode(user_id);
|
||||
|
||||
fetch_json(
|
||||
Method::PATCH,
|
||||
&format!(
|
||||
"{}user/{}/preferences",
|
||||
env!("MODRINTH_API_URL_V3"),
|
||||
user_id
|
||||
),
|
||||
None,
|
||||
Some(preferences),
|
||||
Some("/v3/user/:id/preferences"),
|
||||
&state.api_semaphore,
|
||||
&state.pool,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(patch))]
|
||||
pub async fn patch_user(user_id: &str, patch: Value) -> crate::Result<()> {
|
||||
let state = State::get().await?;
|
||||
|
||||
@@ -19,6 +19,8 @@ pub struct Settings {
|
||||
pub advanced_rendering: bool,
|
||||
pub native_decorations: bool,
|
||||
pub toggle_sidebar: bool,
|
||||
pub sync_theme_across_devices: bool,
|
||||
pub sync_behavior_across_devices: bool,
|
||||
|
||||
pub telemetry: bool,
|
||||
pub discord_rpc: bool,
|
||||
@@ -88,6 +90,7 @@ impl Settings {
|
||||
hook_pre_launch, hook_wrapper, hook_post_exit,
|
||||
custom_dir, prev_custom_dir, migrated, json(feature_flags) feature_flags, toggle_sidebar,
|
||||
skipped_update, pending_update_toast_for_version, auto_download_updates,
|
||||
sync_theme_across_devices, sync_behavior_across_devices,
|
||||
version
|
||||
FROM settings
|
||||
"
|
||||
@@ -146,6 +149,8 @@ impl Settings {
|
||||
pending_update_toast_for_version: res
|
||||
.pending_update_toast_for_version,
|
||||
auto_download_updates: res.auto_download_updates.map(|x| x == 1),
|
||||
sync_theme_across_devices: res.sync_theme_across_devices == 1,
|
||||
sync_behavior_across_devices: res.sync_behavior_across_devices == 1,
|
||||
version: res.version as usize,
|
||||
})
|
||||
}
|
||||
@@ -206,7 +211,10 @@ impl Settings {
|
||||
pending_update_toast_for_version = $30,
|
||||
auto_download_updates = $31,
|
||||
|
||||
version = $32
|
||||
sync_theme_across_devices = $32,
|
||||
sync_behavior_across_devices = $33,
|
||||
|
||||
version = $34
|
||||
",
|
||||
max_concurrent_writes,
|
||||
max_concurrent_downloads,
|
||||
@@ -239,6 +247,8 @@ impl Settings {
|
||||
self.skipped_update,
|
||||
self.pending_update_toast_for_version,
|
||||
self.auto_download_updates,
|
||||
self.sync_theme_across_devices,
|
||||
self.sync_behavior_across_devices,
|
||||
version,
|
||||
)
|
||||
.execute(exec)
|
||||
|
||||
Reference in New Issue
Block a user