feat: widget sdk
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/* eslint-disable @typescript-eslint/indent */
|
||||
import { FC, memo } from 'react';
|
||||
// import { MessagePayload } from '../../../app/slices/message';
|
||||
import { useAppSelector } from '../../../app/store';
|
||||
import TextMessage from './Message/Text';
|
||||
|
||||
type Props = {
|
||||
uid: number
|
||||
};
|
||||
|
||||
// 间隔10秒
|
||||
const interval = 10 * 1000;
|
||||
const Index: FC<Props> = ({ uid }) => {
|
||||
const { mids, messageMap } = useAppSelector(store => { return { mids: store.userMessage.byId[uid], messageMap: store.message }; });
|
||||
console.log("mids", mids, uid);
|
||||
|
||||
if (!mids) return null;
|
||||
return mids.map((mid, idx) => {
|
||||
const currMsg = messageMap[mid];
|
||||
const prevMsg = messageMap[mids[idx - 1]];
|
||||
const compact = !prevMsg
|
||||
? false
|
||||
: prevMsg.from_uid !== currMsg.from_uid
|
||||
? false
|
||||
: (currMsg.created_at ?? 0) - (prevMsg.created_at ?? 0) < interval;
|
||||
return <TextMessage key={currMsg.mid} {...currMsg} compact={compact} isFirst={idx === 0} />;
|
||||
});
|
||||
};
|
||||
|
||||
export default memo(Index, (prev, next) => {
|
||||
return JSON.stringify(prev.uid) === JSON.stringify(next.uid);
|
||||
});
|
||||
Reference in New Issue
Block a user