diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 4cfac92..a9e79c9 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -5,6 +5,7 @@ use crate::{ FriendRemote, FriendRequestResponseDto, FriendshipResponseDto, SendFriendRequestDto, UserBasicDto, }, + remotes::user::UserRemote, services::cursor::start_cursor_tracking, state::{init_app_data, FDOLL}, }; @@ -192,6 +193,22 @@ async fn delete_doll(id: String) -> Result<(), String> { .map_err(|e| e.to_string()) } +#[tauri::command] +async fn set_active_doll(doll_id: String) -> Result<(), String> { + UserRemote::new() + .set_active_doll(&doll_id) + .await + .map_err(|e| e.to_string()) +} + +#[tauri::command] +async fn remove_active_doll() -> Result<(), String> { + UserRemote::new() + .remove_active_doll() + .await + .map_err(|e| e.to_string()) +} + #[tauri::command] fn recolor_gif_base64( white_color_hex: String, @@ -235,6 +252,8 @@ pub fn run() { create_doll, update_doll, delete_doll, + set_active_doll, + remove_active_doll, recolor_gif_base64, quit_app ]) diff --git a/src-tauri/src/remotes/friends.rs b/src-tauri/src/remotes/friends.rs index 52b086e..92371c1 100644 --- a/src-tauri/src/remotes/friends.rs +++ b/src-tauri/src/remotes/friends.rs @@ -22,6 +22,7 @@ pub struct UserBasicDto { pub id: String, pub name: String, pub username: Option, + pub active_doll_id: Option, } #[derive(Default, Serialize, Deserialize, Clone, Debug, TS)] diff --git a/src-tauri/src/remotes/user.rs b/src-tauri/src/remotes/user.rs index 43691b3..7fccc81 100644 --- a/src-tauri/src/remotes/user.rs +++ b/src-tauri/src/remotes/user.rs @@ -18,6 +18,7 @@ pub struct UserProfile { pub created_at: String, pub updated_at: String, pub last_login_at: Option, + pub active_doll_id: Option, } #[derive(Default, Serialize, Deserialize, Clone, Debug, TS)] @@ -79,4 +80,18 @@ impl UserRemote { resp.error_for_status()?; Ok(()) } + + pub async fn set_active_doll(&self, doll_id: &str) -> Result<(), Error> { + let url = format!("{}/users/me/active-doll/{}", self.base_url, doll_id); + let resp = with_auth(self.client.put(url)).await.send().await?; + resp.error_for_status()?; + Ok(()) + } + + pub async fn remove_active_doll(&self) -> Result<(), Error> { + let url = format!("{}/users/me/active-doll", self.base_url); + let resp = with_auth(self.client.delete(url)).await.send().await?; + resp.error_for_status()?; + Ok(()) + } } diff --git a/src/routes/app-menu/tabs/your-dolls.svelte b/src/routes/app-menu/tabs/your-dolls.svelte index b5f7c42..d033ff1 100644 --- a/src/routes/app-menu/tabs/your-dolls.svelte +++ b/src/routes/app-menu/tabs/your-dolls.svelte @@ -2,11 +2,14 @@ import { onMount } from "svelte"; import { invoke } from "@tauri-apps/api/core"; import type { DollDto } from "../../../types/bindings/DollDto"; + import type { UserProfile } from "../../../types/bindings/UserProfile"; + import type { AppData } from "../../../types/bindings/AppData"; import type { CreateDollDto } from "../../../types/bindings/CreateDollDto"; import type { UpdateDollDto } from "../../../types/bindings/UpdateDollDto"; import DollPreview from "./DollPreview.svelte"; let dolls: DollDto[] = []; + let user: UserProfile | null = null; let loading = false; let error: string | null = null; let isCreateModalOpen = false; @@ -29,6 +32,10 @@ loading = true; try { dolls = await invoke("get_dolls"); + // Use refresh_app_data to ensure we get the latest user state (including activeDollId) + // from the server, as the local state might be stale after updates. + const appData: AppData = await invoke("refresh_app_data"); + user = appData.user; } catch (e) { error = (e as Error)?.message ?? String(e); } finally { @@ -112,6 +119,24 @@ error = (e as Error)?.message ?? String(e); } } + + async function handleSetActiveDoll(dollId: string) { + try { + await invoke("set_active_doll", { dollId }); + await refreshDolls(); + } catch (e) { + error = (e as Error)?.message ?? String(e); + } + } + + async function handleRemoveActiveDoll() { + try { + await invoke("remove_active_doll"); + await refreshDolls(); + } catch (e) { + error = (e as Error)?.message ?? String(e); + } + }
@@ -140,9 +165,16 @@

No dolls found. Create your first doll!

{:else} -
+
{#each dolls as doll (doll.id)} -
+
+ {#if user?.activeDollId === doll.id} +
+ Active +
+ {/if}

{doll.name}

@@ -170,6 +202,17 @@
+ {#if user?.activeDollId === doll.id} + + {:else} + + {/if} , createdAt: string, updatedAt: string, lastLoginAt: string | null, }; +export type UserProfile = { id: string, keycloakSub: string, name: string, email: string, username: string | null, roles: Array, createdAt: string, updatedAt: string, lastLoginAt: string | null, activeDollId: string | null, };