lbry-desktop/ui/page/embedWrapper/view.jsx

43 lines
1.1 KiB
React
Raw Normal View History

// @flow
2020-01-31 20:33:40 +01:00
import React, { useEffect, useState } from 'react';
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>,
};
2020-01-31 19:25:48 +01:00
// $FlowFixMe apparently flow thinks this is wrong.
export const EmbedContext = React.createContext();
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(() => {
2020-02-04 07:02:39 +01:00
setHasRecordedView(false);
2020-01-31 20:33:40 +01:00
});
}
}, [triggerAnalyticsView, setHasRecordedView, hasRecordedView, uri, claim]);
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>
);
};
export default EmbedWrapperPage;