feat: support click avatar jump to resume page
This commit is contained in:
parent
96eb46821e
commit
c08b0bef95
@ -2,13 +2,13 @@ import { Image } from '@tarojs/components';
|
|||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { PropsWithChildren, useEffect, useState, useCallback } from 'react';
|
import { PropsWithChildren, useEffect, useState, useCallback } from 'react';
|
||||||
import { MaterialViewSource } from '@/constants/material';
|
|
||||||
|
|
||||||
|
import { PageUrl } from '@/constants/app';
|
||||||
|
import { MaterialViewSource } from '@/constants/material';
|
||||||
import useUserInfo from '@/hooks/use-user-info';
|
import useUserInfo from '@/hooks/use-user-info';
|
||||||
import { IChatMessage } from '@/types/message';
|
import { IChatMessage } from '@/types/message';
|
||||||
import { getScrollItemId } from '@/utils/common';
|
import { getScrollItemId } from '@/utils/common';
|
||||||
import { navigateTo } from '@/utils/route';
|
import { navigateTo } from '@/utils/route';
|
||||||
import { PageUrl } from '@/constants/app';
|
|
||||||
|
|
||||||
import './index.less';
|
import './index.less';
|
||||||
|
|
||||||
@ -19,12 +19,13 @@ export interface IBaseMessageProps {
|
|||||||
|
|
||||||
export interface IUserMessageProps extends PropsWithChildren, IBaseMessageProps {
|
export interface IUserMessageProps extends PropsWithChildren, IBaseMessageProps {
|
||||||
isRead?: boolean;
|
isRead?: boolean;
|
||||||
|
resumeId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PREFIX = 'base-message';
|
const PREFIX = 'base-message';
|
||||||
|
|
||||||
function BaseMessage(props: IUserMessageProps) {
|
function BaseMessage(props: IUserMessageProps) {
|
||||||
const { id, message, isRead: isReadProps, children } = props;
|
const { id, message, isRead: isReadProps, children, resumeId } = props;
|
||||||
const { userId } = useUserInfo();
|
const { userId } = useUserInfo();
|
||||||
const [isRead, setIsRead] = useState(message.isRead);
|
const [isRead, setIsRead] = useState(message.isRead);
|
||||||
const isSender = message.senderUserId === userId;
|
const isSender = message.senderUserId === userId;
|
||||||
@ -37,10 +38,12 @@ function BaseMessage(props: IUserMessageProps) {
|
|||||||
// const timer = setTimeout(() => setIsRead(true), 1200);
|
// const timer = setTimeout(() => setIsRead(true), 1200);
|
||||||
// return () => clearTimeout(timer);
|
// return () => clearTimeout(timer);
|
||||||
// }, [isSender]);
|
// }, [isSender]);
|
||||||
const handleClick = useCallback(
|
const handleClick = useCallback(() => {
|
||||||
() => navigateTo(PageUrl.MaterialView, { resumeId: message.jobId, source: MaterialViewSource.Chat }),
|
if (!resumeId || isSender) {
|
||||||
[message.jobId]
|
return;
|
||||||
);
|
}
|
||||||
|
navigateTo(PageUrl.MaterialView, { resumeId: resumeId, source: MaterialViewSource.Chat });
|
||||||
|
}, [resumeId, isSender]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isRead) {
|
if (isRead) {
|
||||||
return;
|
return;
|
||||||
@ -53,6 +56,7 @@ function BaseMessage(props: IUserMessageProps) {
|
|||||||
<Image
|
<Image
|
||||||
mode="aspectFit"
|
mode="aspectFit"
|
||||||
className={`${PREFIX}__avatar`}
|
className={`${PREFIX}__avatar`}
|
||||||
|
onClick={handleClick}
|
||||||
src={message.senderAvatarUrl || require('@/statics/png/default_avatar.png')}
|
src={message.senderAvatarUrl || require('@/statics/png/default_avatar.png')}
|
||||||
/>
|
/>
|
||||||
<div className={`${PREFIX}__content-container`}>
|
<div className={`${PREFIX}__content-container`}>
|
||||||
|
@ -31,7 +31,7 @@ import {
|
|||||||
PostMessageRequest,
|
PostMessageRequest,
|
||||||
} from '@/types/message';
|
} from '@/types/message';
|
||||||
import { isAnchorMode } from '@/utils/app';
|
import { isAnchorMode } from '@/utils/app';
|
||||||
import { getScrollItemId, last, logWithPrefix } from '@/utils/common';
|
import { getScrollItemId, last, logWithPrefix, safeJsonParse } from '@/utils/common';
|
||||||
import { collectEvent } from '@/utils/event';
|
import { collectEvent } from '@/utils/event';
|
||||||
import {
|
import {
|
||||||
isExchangeMessage,
|
isExchangeMessage,
|
||||||
@ -85,6 +85,15 @@ const getHeaderLeftButtonText = (job?: IJobMessage, material?: IMaterialMessage)
|
|||||||
return isAnchorMode() ? '不感兴趣' : '标记为不合适';
|
return isAnchorMode() ? '不感兴趣' : '标记为不合适';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getResumeId = (messages: IChatMessage[]) => {
|
||||||
|
const resumeStr = messages.find(it => it.type === MessageType.Material)?.actionObject;
|
||||||
|
if (resumeStr) {
|
||||||
|
const resumeObj = safeJsonParse(resumeStr);
|
||||||
|
return resumeObj.id;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
export default function MessageChat() {
|
export default function MessageChat() {
|
||||||
const listHeight = useListHeight(CALC_LIST_PROPS);
|
const listHeight = useListHeight(CALC_LIST_PROPS);
|
||||||
const [input, setInput] = useState('');
|
const [input, setInput] = useState('');
|
||||||
@ -96,6 +105,7 @@ export default function MessageChat() {
|
|||||||
const [messageStatusList, setMessageStatusList] = useState<IMessageStatus[]>([]);
|
const [messageStatusList, setMessageStatusList] = useState<IMessageStatus[]>([]);
|
||||||
const [jobId, setJobId] = useState<string>();
|
const [jobId, setJobId] = useState<string>();
|
||||||
const [job, setJob] = useState<IJobMessage>();
|
const [job, setJob] = useState<IJobMessage>();
|
||||||
|
const [resumeId, setResumeId] = useState<string | undefined>();
|
||||||
const [material, setMaterial] = useState<IMaterialMessage>();
|
const [material, setMaterial] = useState<IMaterialMessage>();
|
||||||
const [scrollItemId, setScrollItemId] = useState<string>();
|
const [scrollItemId, setScrollItemId] = useState<string>();
|
||||||
const scrollToLowerRef = useRef(false);
|
const scrollToLowerRef = useRef(false);
|
||||||
@ -252,6 +262,16 @@ export default function MessageChat() {
|
|||||||
// };
|
// };
|
||||||
// }, []);
|
// }, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (resumeId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setResumeId(getResumeId(messages));
|
||||||
|
}, [messages, resumeId]);
|
||||||
|
|
||||||
|
console.log('resumeId', resumeId)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!chat) {
|
if (!chat) {
|
||||||
return;
|
return;
|
||||||
@ -353,6 +373,7 @@ export default function MessageChat() {
|
|||||||
id={message.msgId}
|
id={message.msgId}
|
||||||
key={message.msgId}
|
key={message.msgId}
|
||||||
message={message}
|
message={message}
|
||||||
|
resumeId={resumeId}
|
||||||
isRead={messageStatusList.some(m => m.msgId === message.msgId && !!m.isRead)}
|
isRead={messageStatusList.some(m => m.msgId === message.msgId && !!m.isRead)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user