(props: LinkmanProps)
| 23 | } |
| 24 | |
| 25 | function Linkman(props: LinkmanProps) { |
| 26 | const { id, name, avatar, preview, unread, time } = props; |
| 27 | |
| 28 | const action = useAction(); |
| 29 | const focus = useSelector((state: State) => state.focus); |
| 30 | const aero = useAero(); |
| 31 | const { linkmans } = useStore(); |
| 32 | |
| 33 | function formatTime() { |
| 34 | const nowTime = new Date(); |
| 35 | if (Time.isToday(nowTime, time)) { |
| 36 | return Time.getHourMinute(time); |
| 37 | } |
| 38 | if (Time.isYesterday(nowTime, time)) { |
| 39 | return '昨天'; |
| 40 | } |
| 41 | return Time.getMonthDate(time); |
| 42 | } |
| 43 | |
| 44 | async function handleClick() { |
| 45 | // Update next linkman read history |
| 46 | const nextFocusLinkman = linkmans[id]; |
| 47 | if (nextFocusLinkman) { |
| 48 | const messageKeys = Object.keys(nextFocusLinkman.messages); |
| 49 | if (messageKeys.length > 0) { |
| 50 | const lastMessageId = |
| 51 | nextFocusLinkman.messages[ |
| 52 | messageKeys[messageKeys.length - 1] |
| 53 | ]._id; |
| 54 | updateHistory(nextFocusLinkman._id, lastMessageId); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | action.setFocus(id); |
| 59 | if (isMobile) { |
| 60 | action.setStatus('functionBarAndLinkmanListVisible', false); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return ( |
| 65 | <div |
| 66 | className={`${Style.linkman} ${id === focus ? Style.focus : ''}`} |
| 67 | onClick={handleClick} |
| 68 | role="button" |
| 69 | {...aero} |
| 70 | > |
| 71 | <Avatar src={avatar} size={48} /> |
| 72 | <div className={Style.container}> |
| 73 | <div className={`${Style.rowContainer} ${Style.nameTimeBlock}`}> |
| 74 | <p className={Style.name}>{name}</p> |
| 75 | <p className={Style.time}>{formatTime()}</p> |
| 76 | </div> |
| 77 | <div |
| 78 | className={`${Style.rowContainer} ${Style.previewUnreadBlock}`} |
| 79 | > |
| 80 | <p |
| 81 | className={Style.preview} |
| 82 | // eslint-disable-next-line react/no-danger |
nothing calls this directly
no test coverage detected