bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/pads/pads-graphql/hooks/useRev.ts
Tainan Felipe 3bc40df230
Add: useDeduplicatedSubscription hook (#20376)
* Add: useDeduplicatedSubscription hook

* Fix: TS error

* Add: components using useDeduplicatedSubscription

* Change: Move to useDeduplicatedSubscription

* Change: unsubscribe logic to own useEffect

* Change: remove file import over package

* Fix: TS errors

* Fix: private chat not loading

* Change: revert changes on queries

* Fix: eslint error

* Remove: html-webpack-plugin package

* Fix: external video

* Add: comment about the stringToHash function

* Fix: video player showing tools over presentation
2024-06-04 10:40:54 -03:00

39 lines
882 B
TypeScript

import { gql } from '@apollo/client';
import { useEffect, useState } from 'react';
import useDeduplicatedSubscription from '/imports/ui/core/hooks/useDeduplicatedSubscription';
interface GetPadLastRevResponse {
sharedNotes: Array<{
lastRev: number;
}>;
}
const GET_PAD_LAST_REV = gql`
subscription GetPadLastRev($externalId: String!) {
sharedNotes(
where: { sharedNotesExtId: { _eq: $externalId } }
) {
lastRev
}
}
`;
const useRev = (externalId: string) => {
const [rev, setRev] = useState(0);
const { data: padRevData } = useDeduplicatedSubscription<GetPadLastRevResponse>(
GET_PAD_LAST_REV,
{ variables: { externalId } },
);
useEffect(() => {
if (!padRevData) return;
const pad = padRevData.sharedNotes[0];
if (!pad) return;
setRev(pad.lastRev);
}, [padRevData]);
return rev;
};
export default useRev;