updated friend field to be optional (frontend bug fix, not that I have

no friends)
This commit is contained in:
2026-02-17 21:37:15 +08:00
parent 8578ba3376
commit f1d03fc96a
4 changed files with 31 additions and 24 deletions

View File

@@ -18,7 +18,7 @@ pub struct UserBasicDto {
#[ts(export)]
pub struct FriendshipResponseDto {
pub id: String,
pub friend: UserBasicDto,
pub friend: Option<UserBasicDto>,
pub created_at: String,
}

View File

@@ -303,6 +303,7 @@
{:else}
<div class="flex flex-col gap-2">
{#each friends as friend (friend.id)}
{#if friend.friend}
<div class="card px-3 py-2 bg-base-200/50">
<div class="flex items-center justify-between">
<div>
@@ -314,12 +315,17 @@
<button
class="btn btn-sm btn-outline"
disabled={loading.action}
on:click={() => handleUnfriend(friend.friend.id)}
on:click={() => {
friend.friend
? handleUnfriend(friend.friend.id)
: null;
}}
>
Unfriend
</button>
</div>
</div>
{/if}
{/each}
</div>
{/if}

View File

@@ -23,8 +23,8 @@
let isInteractive = $derived($sceneInteractive);
function getFriendById(userId: string) {
const friend = $appData?.friends?.find((f) => f.friend.id === userId);
return friend!.friend;
const friend = $appData?.friends?.find((f) => f.friend?.id === userId);
return friend?.friend;
}
function getFriendDoll(userId: string) {
@@ -32,8 +32,8 @@
return $friendsActiveDolls[userId];
}
const friend = $appData?.friends?.find((f) => f.friend.id === userId);
return friend?.friend.activeDoll;
const friend = $appData?.friends?.find((f) => f.friend?.id === userId);
return friend?.friend?.activeDoll;
}
function getFriendStatus(userId: string) {
@@ -109,7 +109,7 @@
{#each Object.entries($friendsCursorPositions) as [userId, position]}
{@const status = getFriendStatus(userId)}
<div class="badge py-3 text-xs text-left flex flex-row gap-2">
<span class="font-bold">{getFriendById(userId).name}</span>
<span class="font-bold">{getFriendById(userId)?.name}</span>
<div class="flex flex-row font-mono gap-2">
<span>
({position.mapped.x.toFixed(3)}, {position.mapped.y.toFixed(
@@ -143,12 +143,13 @@
{#if Object.keys($friendsCursorPositions).length > 0}
{#each Object.entries($friendsCursorPositions) as [userId, position]}
{@const doll = getFriendDoll(userId)}
{#if doll}
{@const friend = getFriendById(userId)}
{#if doll && friend}
<DesktopPet
id={userId}
targetX={position.mapped.x * innerWidth}
targetY={position.mapped.y * innerHeight}
user={getFriendById(userId)}
user={friend}
userStatus={getFriendStatus(userId)}
{doll}
{isInteractive}

View File

@@ -1,4 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { UserBasicDto } from "./UserBasicDto";
export type FriendshipResponseDto = { id: string, friend: UserBasicDto, createdAt: string, };
export type FriendshipResponseDto = { id: string, friend: UserBasicDto | null, createdAt: string, };