diff --git a/frontend/src/chat/dm.ts b/frontend/src/chat/dm.ts index 13450c3..fc56e4f 100644 --- a/frontend/src/chat/dm.ts +++ b/frontend/src/chat/dm.ts @@ -9,6 +9,7 @@ import { request, websocket } from "../websocket"; import type { FetchDMResponse, SendDMRequest, WebSocketMessage, User, DmEnvelope } from "../core/types"; import type { Tabs } from "mdui/components/tabs"; import { b64, ub64 } from "../utils/utils"; +import defaultAvatar from "../resources/images/default-avatar.png"; export async function sendDm(recipientId: number, recipientPublicKeyB64: string, plaintext: string): Promise { const keys = getCurrentKeys(); @@ -101,7 +102,7 @@ async function loadUsers() { // Add avatar const avatar = document.createElement("img"); - avatar.src = u.profile_picture || "./src/resources/images/default-avatar.png"; + avatar.src = u.profile_picture || defaultAvatar; avatar.alt = u.username; avatar.slot = "icon"; avatar.style.width = "40px"; @@ -111,7 +112,7 @@ async function loadUsers() { // Handle avatar load error avatar.addEventListener("error", () => { - avatar.src = "./src/resources/images/default-avatar.png"; + avatar.src = defaultAvatar; }); item.appendChild(avatar); diff --git a/frontend/src/core/types.d.ts b/frontend/src/core/types.d.ts index b4cb17a..e408693 100644 --- a/frontend/src/core/types.d.ts +++ b/frontend/src/core/types.d.ts @@ -223,4 +223,12 @@ export interface WebSocketError { export interface WebSocketCredentials { scheme: string; credentials: string; +} + +// ----------- +// React types +// ----------- +export interface DialogProps { + isOpen: boolean; + onOpenChange: (value: boolean) => void; } \ No newline at end of file diff --git a/frontend/src/ui/components/chat/LeftPanel.tsx b/frontend/src/ui/components/chat/LeftPanel.tsx index 39338b8..5d24d6e 100644 --- a/frontend/src/ui/components/chat/LeftPanel.tsx +++ b/frontend/src/ui/components/chat/LeftPanel.tsx @@ -2,6 +2,8 @@ import { PRODUCT_NAME } from "../../../core/config"; import { useDialog } from "../../contexts/DialogContext"; import { useChat } from "../../hooks/useChat"; import defaultAvatar from "../../../resources/images/default-avatar.png"; +import { useState } from "react"; +import { ProfileDialog } from "../profile/ProfileDialog"; function BottomAppBar() { const { openSettings } = useDialog(); @@ -70,20 +72,17 @@ function ChatTabs() { function ChatHeader() { - const { openProfile } = useDialog(); - - const handleProfileClick = () => { - openProfile(); - }; + const [isProfileOpen, setProfileOpen] = useState(false); return (
{PRODUCT_NAME}
- + setProfileOpen(true)}>
+
); } diff --git a/frontend/src/ui/components/chat/UserProfileDialog.tsx b/frontend/src/ui/components/chat/UserProfileDialog.tsx index 8dbf322..d484189 100644 --- a/frontend/src/ui/components/chat/UserProfileDialog.tsx +++ b/frontend/src/ui/components/chat/UserProfileDialog.tsx @@ -3,7 +3,7 @@ export function UserProfileDialog() {
- Profile Picture + Profile Picture
diff --git a/frontend/src/ui/components/profile/ProfileDialog.tsx b/frontend/src/ui/components/profile/ProfileDialog.tsx index 27512dd..c3dba58 100644 --- a/frontend/src/ui/components/profile/ProfileDialog.tsx +++ b/frontend/src/ui/components/profile/ProfileDialog.tsx @@ -1,21 +1,21 @@ -import { useState } from "react"; -import { useDialog } from "../../contexts/DialogContext"; +import { useState, type FormEvent } from "react"; import defaultAvatar from "../../../resources/images/default-avatar.png"; +import type { TextField } from "mdui/components/text-field"; +import type { DialogProps } from "../../../core/types"; -export function ProfileDialog() { +export function ProfileDialog({ isOpen, onOpenChange }: DialogProps) { const [username, setUsername] = useState("user123"); const [description, setDescription] = useState(""); - const { isProfileOpen, closeProfile } = useDialog(); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); // TODO: Implement profile update logic console.log("Profile update:", { username, description }); - closeProfile(); + onOpenChange(false); }; return ( - +
@@ -28,7 +28,7 @@ export function ProfileDialog() { label="Имя пользователя" variant="outlined" value={username} - onChange={(e: any) => setUsername(e.target.value)} + onChange={(e: FormEvent) => setUsername((e.target as TextField).value)} autocomplete="username">
@@ -39,13 +39,13 @@ export function ProfileDialog() { label="О себе" variant="outlined" value={description} - onChange={(e: any) => setDescription(e.target.value)} + onChange={(e: FormEvent) => setDescription((e.target as TextField).value)} placeholder="Расскажите о себе..." autocomplete="none">
Сохранить изменения - Закрыть + onOpenChange(false)}>Закрыть
diff --git a/frontend/src/ui/screen/ChatScreen.tsx b/frontend/src/ui/screen/ChatScreen.tsx index 18101d1..5bb6432 100644 --- a/frontend/src/ui/screen/ChatScreen.tsx +++ b/frontend/src/ui/screen/ChatScreen.tsx @@ -12,7 +12,6 @@ export default function ChatScreen() { <> -