2019-12-30 20:54:53 +01:00
|
|
|
// @flow
|
2020-01-31 20:33:40 +01:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2019-12-30 20:54:53 +01:00
|
|
|
import FileRender from 'component/fileRender';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
resolveUri: string => void,
|
|
|
|
claim: Claim,
|
2020-01-31 20:33:40 +01:00
|
|
|
triggerAnalyticsView: string => Promise<any>,
|
2019-12-30 20:54:53 +01:00
|
|
|
};
|
2020-01-31 19:25:48 +01:00
|
|
|
// $FlowFixMe apparently flow thinks this is wrong.
|
|
|
|
export const EmbedContext = React.createContext();
|
2019-12-30 20:54:53 +01:00
|
|
|
const EmbedWrapperPage = (props: Props) => {
|
2020-01-31 20:33:40 +01:00
|
|
|
const { resolveUri, claim, uri, triggerAnalyticsView } = props;
|
|
|
|
const [hasRecordedView, setHasRecordedView] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!hasRecordedView && uri && claim) {
|
|
|
|
triggerAnalyticsView(uri).then(() => {
|
|
|
|
setHasRecordedView(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [triggerAnalyticsView, setHasRecordedView, hasRecordedView, uri, claim]);
|
|
|
|
|
2019-12-30 20:54:53 +01:00
|
|
|
useEffect(() => {
|
|
|
|
if (resolveUri && uri) {
|
|
|
|
resolveUri(uri);
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
2020-01-31 19:25:48 +01:00
|
|
|
return (
|
|
|
|
<div className={'embed__wrapper'}>
|
|
|
|
{claim && (
|
|
|
|
<EmbedContext.Provider value>
|
|
|
|
<FileRender uri={uri} embedded />
|
|
|
|
</EmbedContext.Provider>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2019-12-30 20:54:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default EmbedWrapperPage;
|