diff --git a/src/common/component/Avatar.tsx b/src/common/component/Avatar.tsx index 37113473..c26ae36c 100644 --- a/src/common/component/Avatar.tsx +++ b/src/common/component/Avatar.tsx @@ -1,17 +1,16 @@ import { useState, useEffect, memo, SyntheticEvent, FC } from "react"; import { getInitials, getInitialsAvatar } from "../utils"; -interface Props { - className?: string; - alt?: string; - url?: string; - name?: string; +interface Props extends Partial { + // className?: string; + // alt?: string; + // src?: string; + // name?: string; type?: "user" | "channel"; } -const Avatar: FC = ({ url = "", name = "Deleted User", type = "user", ...rest }) => { - const [src, setSrc] = useState(""); - +const Avatar: FC = ({ src = "", name = "Deleted User", type = "user", ...rest }) => { + const [url, setUrl] = useState(""); const handleError = (err: SyntheticEvent) => { console.error("load avatar error", err); const tmp = getInitialsAvatar({ @@ -19,26 +18,26 @@ const Avatar: FC = ({ url = "", name = "Deleted User", type = "user", ... background: type == "channel" ? "#EAECF0" : undefined, foreground: type == "channel" ? "#475467" : undefined }); - setSrc(tmp); + setUrl(tmp); }; useEffect(() => { - if (!url) { + if (!src) { const tmp = getInitialsAvatar({ initials: getInitials(name), background: type == "channel" ? "#EAECF0" : undefined, foreground: type == "channel" ? "#475467" : undefined }); - setSrc(tmp); + setUrl(tmp); } else { - setSrc(url); + setUrl(src); } - }, [url, name]); - if (!src) return null; + }, [src, name]); + if (!url) return null; - return ; + return ; }; export default memo(Avatar, (prev, next) => { - return prev.url == next.url; + return prev.src == next.src; }); diff --git a/src/common/component/AvatarUploader.tsx b/src/common/component/AvatarUploader.tsx index 6d17a61c..a72efa94 100644 --- a/src/common/component/AvatarUploader.tsx +++ b/src/common/component/AvatarUploader.tsx @@ -53,23 +53,32 @@ const StyledWrapper = styled.div` } } .icon { + display: none; width: 28px; height: 28px; position: absolute; top: 0; right: 0; } + &:hover .icon{ + display: block; + } `; +type UID = number; interface Props { + uid?: UID, + className?: string, url?: string; name?: string; type?: "user" | "channel"; disabled?: boolean; - uploadImage: (file: File) => void; + uploadImage: (param: File | { uid: number, file: File }) => void; } const AvatarUploader: FC = ({ + uid, + className = "", url = "", name = "", type = "user", @@ -83,14 +92,18 @@ const AvatarUploader: FC = ({ if (!evt.target.files) return; const [file] = Array.from(evt.target.files); setUploading(true); - await uploadImage(file); + if (uid) { + await uploadImage({ uid, file }); + } else { + await uploadImage(file); + } setUploading(false); }; return ( - +
- + {!disabled && ( <>
{uploading ? t("status.uploading") : t("action.change_avatar")}
diff --git a/src/common/component/Channel.tsx b/src/common/component/Channel.tsx index 2eb194f2..820b6a68 100644 --- a/src/common/component/Channel.tsx +++ b/src/common/component/Channel.tsx @@ -69,7 +69,7 @@ const Channel: FC = ({ interactive = true, id, compact = false, avatarSiz className={`${interactive ? "interactive" : ""} ${compact ? "compact" : ""}`} >
- +
{!compact && (
diff --git a/src/common/component/Message/FavoredMessage.tsx b/src/common/component/Message/FavoredMessage.tsx index 992bdff8..419cb86a 100644 --- a/src/common/component/Message/FavoredMessage.tsx +++ b/src/common/component/Message/FavoredMessage.tsx @@ -33,7 +33,7 @@ const FavoredMessage: FC = ({ id = "" }) => { {user && (
- +
)}
diff --git a/src/common/component/Message/ForwardedMessage.tsx b/src/common/component/Message/ForwardedMessage.tsx index b820d5ae..9a561cec 100644 --- a/src/common/component/Message/ForwardedMessage.tsx +++ b/src/common/component/Message/ForwardedMessage.tsx @@ -63,7 +63,7 @@ const ForwardedMessage: FC = ({ context, to, from_uid, id }) => { {user && (
- +
)}
diff --git a/src/common/component/Message/PreviewMessage.tsx b/src/common/component/Message/PreviewMessage.tsx index d575a43f..6df9ac76 100644 --- a/src/common/component/Message/PreviewMessage.tsx +++ b/src/common/component/Message/PreviewMessage.tsx @@ -19,7 +19,7 @@ const PreviewMessage: FC = ({ mid = 0 }) => { return (
- +
diff --git a/src/common/component/Message/Reply.tsx b/src/common/component/Message/Reply.tsx index a96245e8..84371a9d 100644 --- a/src/common/component/Message/Reply.tsx +++ b/src/common/component/Message/Reply.tsx @@ -177,7 +177,7 @@ const Reply: FC = ({ mid, interactive = true }) => { onClick={interactive ? handleClick : undefined} >
- + {currUser.name}
{renderContent(data)}
diff --git a/src/common/component/Message/index.tsx b/src/common/component/Message/index.tsx index be4c2860..f5d8079d 100644 --- a/src/common/component/Message/index.tsx +++ b/src/common/component/Message/index.tsx @@ -91,9 +91,8 @@ const Message: FC = ({ onContextMenu={readOnly ? undefined : handleContextMenuEvent} data-msg-mid={mid} ref={inviewRef} - className={`message ${readOnly ? "readonly" : ""} ${pinInfo ? "pinned" : ""} ${ - contextMenuVisible ? "contextVisible" : "" - } `} + className={`message ${readOnly ? "readonly" : ""} ${pinInfo ? "pinned" : ""} ${contextMenuVisible ? "contextVisible" : "" + } `} > = ({ content={} >
- +
= ({ >
{currUser?.name || "Deleted User"} diff --git a/src/common/component/Profile/index.tsx b/src/common/component/Profile/index.tsx index e5b7ce7c..c5d698cc 100644 --- a/src/common/component/Profile/index.tsx +++ b/src/common/component/Profile/index.tsx @@ -47,7 +47,7 @@ const Profile: FC = ({ uid, type = "embed", cid }) => { return ( - +

{name}

{email} {/*

{introduction}

*/} diff --git a/src/common/component/User/index.tsx b/src/common/component/User/index.tsx index e3c23d54..7bf993c0 100644 --- a/src/common/component/User/index.tsx +++ b/src/common/component/User/index.tsx @@ -58,7 +58,7 @@ const User: FC = ({ onContextMenu={enableContextMenu ? handleContextMenuEvent : undefined} >
- +
{!compact && {curr?.name}} @@ -88,7 +88,7 @@ const User: FC = ({ onContextMenu={enableContextMenu ? handleContextMenuEvent : undefined} >
- +
{!compact && {curr?.name}} diff --git a/src/routes/chat/GuestSessionList/Session.tsx b/src/routes/chat/GuestSessionList/Session.tsx index 4499661d..99a5907f 100644 --- a/src/routes/chat/GuestSessionList/Session.tsx +++ b/src/routes/chat/GuestSessionList/Session.tsx @@ -41,7 +41,7 @@ const Session: FC = ({ id, mid }) => {
  • - +
    diff --git a/src/routes/chat/SessionList/Session.tsx b/src/routes/chat/SessionList/Session.tsx index 04a2ca74..22af7815 100644 --- a/src/routes/chat/SessionList/Session.tsx +++ b/src/routes/chat/SessionList/Session.tsx @@ -117,7 +117,7 @@ const Session: FC = ({ {type == "user" ? ( ) : ( - + )}
    diff --git a/src/routes/home/User.tsx b/src/routes/home/User.tsx index d00b8c49..02da160f 100644 --- a/src/routes/home/User.tsx +++ b/src/routes/home/User.tsx @@ -31,7 +31,7 @@ const User: FC = ({ uid }) => {
    - +
    diff --git a/src/routes/resources/Filter/index.tsx b/src/routes/resources/Filter/index.tsx index 8b1599fa..8a43fa9c 100644 --- a/src/routes/resources/Filter/index.tsx +++ b/src/routes/resources/Filter/index.tsx @@ -93,7 +93,7 @@ export default function Filter({ filter, updateFilter }) { onClick={toggleFilterVisible.bind(null, { from: true })} > {from && ( - + )} {t("from")} {from && userMap[from].name}