web: allow editing group and channel descriptions in chat info
Some checks failed
CI / test (push) Failing after 2m11s

This commit is contained in:
2026-03-08 22:56:07 +03:00
parent 0bc7760eee
commit bf7b4fa3c0
2 changed files with 22 additions and 5 deletions

View File

@@ -48,6 +48,7 @@ export function ChatInfoPanel({ chatId, open, onClose }: Props) {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [titleDraft, setTitleDraft] = useState("");
const [descriptionDraft, setDescriptionDraft] = useState("");
const [savingTitle, setSavingTitle] = useState(false);
const [chatAvatarUploading, setChatAvatarUploading] = useState(false);
const [searchQuery, setSearchQuery] = useState("");
@@ -210,6 +211,7 @@ export function ChatInfoPanel({ chatId, open, onClose }: Props) {
const detail = await getChatDetail(targetChatId);
setChat(detail);
setTitleDraft(detail.title ?? "");
setDescriptionDraft(detail.description ?? "");
const notificationSettings = await getChatNotificationSettings(targetChatId);
setMuted(notificationSettings.muted);
if (detail.type === "private" && !detail.is_saved && detail.counterpart_user_id) {
@@ -487,23 +489,38 @@ export function ChatInfoPanel({ chatId, open, onClose }: Props) {
value={titleDraft}
onChange={(e) => setTitleDraft(e.target.value)}
/>
<p className="mt-2 text-xs text-slate-400">Description</p>
<textarea
className="mt-1 min-h-[88px] w-full resize-y rounded bg-slate-800 px-3 py-2 text-sm outline-none"
maxLength={512}
onChange={(e) => setDescriptionDraft(e.target.value)}
placeholder="Enter chat description"
value={descriptionDraft}
/>
<p className="mt-1 text-[11px] text-slate-500">{descriptionDraft.length}/512</p>
<button
className="mt-2 w-full rounded bg-sky-500 px-3 py-2 text-sm font-semibold text-slate-950 disabled:opacity-60"
disabled={savingTitle || !titleDraft.trim() || chatAvatarUploading}
onClick={async () => {
setSavingTitle(true);
try {
const updated = await updateChatProfile(chatId, { title: titleDraft.trim() });
const normalizedDescription = descriptionDraft.trim();
const updated = await updateChatProfile(chatId, {
title: titleDraft.trim(),
description: normalizedDescription.length ? normalizedDescription : null,
});
setChat((prev) => (prev ? { ...prev, ...updated } : prev));
setDescriptionDraft(updated.description ?? "");
await loadChats();
showToast("Chat profile updated");
} catch {
setError("Failed to update title");
setError("Failed to update chat profile");
} finally {
setSavingTitle(false);
}
}}
>
Save title
Save profile
</button>
</>
) : null}