2021-05-03 20:24:07 +08:00
|
|
|
import { useContext, useEffect } from 'react';
|
2021-02-02 06:12:04 +08:00
|
|
|
import GroupChat from '/imports/api/group-chat';
|
|
|
|
import { GroupChatContext, ACTIONS } from './context';
|
|
|
|
|
|
|
|
const Adapter = () => {
|
|
|
|
const usingGroupChatContext = useContext(GroupChatContext);
|
|
|
|
const { dispatch } = usingGroupChatContext;
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-02-17 02:08:31 +08:00
|
|
|
const groupChatCursor = GroupChat.find({});
|
2021-02-02 06:12:04 +08:00
|
|
|
|
2023-02-17 02:08:31 +08:00
|
|
|
groupChatCursor.observe({
|
|
|
|
added: (obj) => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.ADDED,
|
|
|
|
value: {
|
|
|
|
groupChat: obj,
|
|
|
|
},
|
2021-02-02 06:12:04 +08:00
|
|
|
});
|
2023-02-17 02:08:31 +08:00
|
|
|
},
|
|
|
|
});
|
2021-02-02 06:12:04 +08:00
|
|
|
}, []);
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Adapter;
|