2024-05-01 19:38:12 +08:00
|
|
|
import React, { useEffect, useRef } from 'react';
|
2024-03-26 19:57:28 +08:00
|
|
|
import { useCreateUseSubscription } from '/imports/ui/core/hooks/createUseSubscription';
|
|
|
|
import MEETING_SUBSCRIPTION from '/imports/ui/core/graphql/queries/meetingSubscription';
|
|
|
|
import { Meeting } from '/imports/ui/Types/meeting';
|
|
|
|
import Meetings from '/imports/api/meetings';
|
2024-05-01 19:38:12 +08:00
|
|
|
import { AdapterProps } from '../graphqlToMiniMongoAdapterManager/component';
|
2024-03-26 19:57:28 +08:00
|
|
|
|
2024-05-01 19:38:12 +08:00
|
|
|
const MeetingGrapQlMiniMongoAdapter: React.FC<AdapterProps> = ({
|
|
|
|
onReady,
|
|
|
|
children,
|
|
|
|
}) => {
|
|
|
|
const ready = useRef(false);
|
2024-03-26 19:57:28 +08:00
|
|
|
const meetingSubscription = useCreateUseSubscription<Meeting>(MEETING_SUBSCRIPTION, {}, true);
|
|
|
|
const {
|
|
|
|
data: meetingData,
|
|
|
|
} = meetingSubscription();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (meetingData) {
|
2024-05-01 19:38:12 +08:00
|
|
|
if (!ready.current) {
|
|
|
|
ready.current = true;
|
|
|
|
onReady('MeetingGrapQlMiniMongoAdapter');
|
|
|
|
}
|
2024-03-26 19:57:28 +08:00
|
|
|
const meeting = JSON.parse(JSON.stringify(meetingData[0]));
|
|
|
|
const { meetingId } = meeting;
|
|
|
|
Meetings.upsert({ meetingId }, meeting);
|
|
|
|
}
|
|
|
|
}, [meetingData]);
|
2024-05-01 19:38:12 +08:00
|
|
|
return children;
|
2024-03-26 19:57:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default MeetingGrapQlMiniMongoAdapter;
|