Refactor file page

- doFetchFileInfo used for App only
- avoid repeting right side content
This commit is contained in:
Rafael 2022-02-01 17:27:48 -03:00 committed by Thomas Zarebczan
parent 6443af34a0
commit 48e2de6ca4
3 changed files with 85 additions and 84 deletions

View file

@ -7,7 +7,6 @@ import {
selectIsStreamPlaceholderForUri, selectIsStreamPlaceholderForUri,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { makeSelectFileInfoForUri } from 'redux/selectors/file_info'; import { makeSelectFileInfoForUri } from 'redux/selectors/file_info';
import { doFetchFileInfo } from 'redux/actions/file_info';
import { makeSelectCollectionForId } from 'redux/selectors/collections'; import { makeSelectCollectionForId } from 'redux/selectors/collections';
import * as COLLECTIONS_CONSTS from 'constants/collections'; import * as COLLECTIONS_CONSTS from 'constants/collections';
import * as SETTINGS from 'constants/settings'; import * as SETTINGS from 'constants/settings';
@ -19,32 +18,33 @@ import { DISABLE_COMMENTS_TAG } from 'constants/tags';
import FilePage from './view'; import FilePage from './view';
const select = (state, props) => { const select = (state, props) => {
const { search } = props.location; const { uri } = props;
const { search } = location;
const urlParams = new URLSearchParams(search); const urlParams = new URLSearchParams(search);
const collectionId = urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID); const collectionId = urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID);
return { return {
linkedCommentId: urlParams.get('lc'), linkedCommentId: urlParams.get('lc'),
costInfo: selectCostInfoForUri(state, props.uri), costInfo: selectCostInfoForUri(state, uri),
obscureNsfw: !selectShowMatureContent(state), obscureNsfw: !selectShowMatureContent(state),
isMature: selectClaimIsNsfwForUri(state, props.uri), isMature: selectClaimIsNsfwForUri(state, uri),
fileInfo: makeSelectFileInfoForUri(props.uri)(state), fileInfo: makeSelectFileInfoForUri(uri)(state),
renderMode: makeSelectFileRenderModeForUri(props.uri)(state), renderMode: makeSelectFileRenderModeForUri(uri)(state),
videoTheaterMode: selectClientSetting(state, SETTINGS.VIDEO_THEATER_MODE), videoTheaterMode: selectClientSetting(state, SETTINGS.VIDEO_THEATER_MODE),
commentsDisabled: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_COMMENTS_TAG)(state), commentsDisabled: makeSelectTagInClaimOrChannelForUri(uri, DISABLE_COMMENTS_TAG)(state),
isLivestream: selectIsStreamPlaceholderForUri(state, props.uri), isLivestream: selectIsStreamPlaceholderForUri(state, uri),
collection: makeSelectCollectionForId(collectionId)(state), hasCollectionById: Boolean(makeSelectCollectionForId(collectionId)(state)),
collectionId, collectionId,
position: makeSelectContentPositionForUri(props.uri)(state), position: makeSelectContentPositionForUri(uri)(state),
}; };
}; };
const perform = (dispatch) => ({ const perform = {
fetchFileInfo: (uri) => dispatch(doFetchFileInfo(uri)), doFetchCostInfoForUri,
fetchCostInfo: (uri) => dispatch(doFetchCostInfoForUri(uri)), doSetContentHistoryItem,
setViewed: (uri) => dispatch(doSetContentHistoryItem(uri)), doSetPrimaryUri,
setPrimaryUri: (uri) => dispatch(doSetPrimaryUri(uri)), clearPosition,
clearPosition: (uri) => dispatch(clearPosition(uri)), };
});
export default withRouter(connect(select, perform)(FilePage)); export default withRouter(connect(select, perform)(FilePage));

View file

@ -25,47 +25,46 @@ type Props = {
costInfo: ?{ includesData: boolean, cost: number }, costInfo: ?{ includesData: boolean, cost: number },
fileInfo: FileListItem, fileInfo: FileListItem,
uri: string, uri: string,
fetchFileInfo: (string) => void,
fetchCostInfo: (string) => void,
setViewed: (string) => void,
renderMode: string, renderMode: string,
obscureNsfw: boolean, obscureNsfw: boolean,
isMature: boolean, isMature: boolean,
linkedCommentId?: string, linkedCommentId?: string,
setPrimaryUri: (?string) => void, hasCollectionById?: boolean,
collection?: Collection,
collectionId: string, collectionId: string,
videoTheaterMode: boolean, videoTheaterMode: boolean,
claimIsMine: boolean, claimIsMine: boolean,
commentsDisabled: boolean, commentsDisabled: boolean,
isLivestream: boolean, isLivestream: boolean,
clearPosition: (string) => void,
position: number, position: number,
doFetchCostInfoForUri: (uri: string) => void,
doSetContentHistoryItem: (uri: string) => void,
doSetPrimaryUri: (uri: ?string) => void,
clearPosition: (uri: string) => void,
}; };
function FilePage(props: Props) { export default function FilePage(props: Props) {
const { const {
uri, uri,
renderMode, renderMode,
fetchFileInfo,
fetchCostInfo,
setViewed,
fileInfo, fileInfo,
obscureNsfw, obscureNsfw,
isMature, isMature,
costInfo, costInfo,
linkedCommentId, linkedCommentId,
setPrimaryUri,
videoTheaterMode, videoTheaterMode,
claimIsMine, claimIsMine,
commentsDisabled, commentsDisabled,
collection, hasCollectionById,
collectionId, collectionId,
isLivestream, isLivestream,
clearPosition,
position, position,
doFetchCostInfoForUri,
doSetContentHistoryItem,
doSetPrimaryUri,
clearPosition,
} = props; } = props;
const cost = costInfo ? costInfo.cost : null; const cost = costInfo ? costInfo.cost : null;
const hasFileInfo = fileInfo !== undefined; const hasFileInfo = fileInfo !== undefined;
const isMarkdown = renderMode === RENDER_MODES.MARKDOWN; const isMarkdown = renderMode === RENDER_MODES.MARKDOWN;
@ -81,12 +80,6 @@ function FilePage(props: Props) {
React.useEffect(() => { React.useEffect(() => {
// always refresh file info when entering file page to see if we have the file // always refresh file info when entering file page to see if we have the file
// this could probably be refactored into more direct components now // this could probably be refactored into more direct components now
// @if TARGET='app'
if (!hasFileInfo) {
fetchFileInfo(uri);
}
// @endif
if (collectionId) { if (collectionId) {
clearPosition(uri); clearPosition(uri);
} }
@ -96,44 +89,39 @@ function FilePage(props: Props) {
} }
// See https://github.com/lbryio/lbry-desktop/pull/1563 for discussion // See https://github.com/lbryio/lbry-desktop/pull/1563 for discussion
fetchCostInfo(uri); doFetchCostInfoForUri(uri);
setViewed(uri); doSetContentHistoryItem(uri);
setPrimaryUri(uri); doSetPrimaryUri(uri);
return () => { return () => doSetPrimaryUri(null);
setPrimaryUri(null);
};
}, [ }, [
uri, uri,
hasFileInfo, hasFileInfo,
fileInfo, fileInfo,
videoPlayedEnoughToResetPosition, videoPlayedEnoughToResetPosition,
fetchFileInfo,
collectionId, collectionId,
clearPosition, clearPosition,
fetchCostInfo, doFetchCostInfoForUri,
setViewed, doSetContentHistoryItem,
setPrimaryUri, doSetPrimaryUri,
]); ]);
function renderFilePageLayout() { function renderFilePageLayout() {
if (RENDER_MODES.FLOATING_MODES.includes(renderMode)) { if (RENDER_MODES.FLOATING_MODES.includes(renderMode)) {
return ( return (
<React.Fragment> <div className={PRIMARY_PLAYER_WRAPPER_CLASS}>
<div className={PRIMARY_PLAYER_WRAPPER_CLASS}>
<FileRenderInitiator uri={uri} videoTheaterMode={videoTheaterMode} />
</div>
{/* playables will be rendered and injected by <FileRenderFloating> */} {/* playables will be rendered and injected by <FileRenderFloating> */}
</React.Fragment> <FileRenderInitiator uri={uri} videoTheaterMode={videoTheaterMode} />
</div>
); );
} }
if (RENDER_MODES.UNRENDERABLE_MODES.includes(renderMode)) { if (RENDER_MODES.UNRENDERABLE_MODES.includes(renderMode)) {
return ( return (
<React.Fragment> <>
<FileTitleSection uri={uri} /> <FileTitleSection uri={uri} />
<FileRenderDownload uri={uri} isFree={cost === 0} /> <FileRenderDownload uri={uri} isFree={cost === 0} />
</React.Fragment> </>
); );
} }
@ -147,43 +135,44 @@ function FilePage(props: Props) {
if (RENDER_MODES.TEXT_MODES.includes(renderMode)) { if (RENDER_MODES.TEXT_MODES.includes(renderMode)) {
return ( return (
<React.Fragment> <>
<FileTitleSection uri={uri} /> <FileTitleSection uri={uri} />
<FileRenderInitiator uri={uri} /> <FileRenderInitiator uri={uri} />
<FileRenderInline uri={uri} /> <FileRenderInline uri={uri} />
</React.Fragment> </>
); );
} }
if (renderMode === RENDER_MODES.IMAGE) { if (renderMode === RENDER_MODES.IMAGE) {
return ( return (
<React.Fragment> <>
<div className="file-render--img-container"> <div className="file-render--img-container">
<FileRenderInitiator uri={uri} /> <FileRenderInitiator uri={uri} />
<FileRenderInline uri={uri} /> <FileRenderInline uri={uri} />
</div> </div>
<FileTitleSection uri={uri} /> <FileTitleSection uri={uri} />
</React.Fragment> </>
); );
} }
return ( return (
<React.Fragment> <>
<FileRenderInitiator uri={uri} videoTheaterMode={videoTheaterMode} /> <FileRenderInitiator uri={uri} videoTheaterMode={videoTheaterMode} />
<FileRenderInline uri={uri} /> <FileRenderInline uri={uri} />
<FileTitleSection uri={uri} /> <FileTitleSection uri={uri} />
</React.Fragment> </>
); );
} }
const rightSideProps = { hasCollectionById, collectionId, uri };
if (obscureNsfw && isMature) { if (obscureNsfw && isMature) {
return ( return (
<Page className="file-page" filePage isMarkdown={isMarkdown}> <Page className="file-page" filePage isMarkdown={isMarkdown}>
<div className={classnames('section card-stack', `file-page__${renderMode}`)}> <div className={classnames('section card-stack', `file-page__${renderMode}`)}>
<FileTitleSection uri={uri} isNsfwBlocked /> <FileTitleSection uri={uri} isNsfwBlocked />
</div> </div>
{collection && !isMarkdown && !videoTheaterMode && <CollectionContent id={collectionId} uri={uri} />} {!isMarkdown && !videoTheaterMode && <RightSideContent {...rightSideProps} />}
{!collection && !isMarkdown && !videoTheaterMode && <RecommendedContent uri={uri} />}
</Page> </Page>
); );
} }
@ -195,7 +184,7 @@ function FilePage(props: Props) {
{!isMarkdown && ( {!isMarkdown && (
<div className="file-page__secondary-content"> <div className="file-page__secondary-content">
<div> <>
{claimIsMine && isLivestream && ( {claimIsMine && isLivestream && (
<div className="livestream__creator-message"> <div className="livestream__creator-message">
<h4>{__('Only visible to you')}</h4> <h4>{__('Only visible to you')}</h4>
@ -208,28 +197,44 @@ function FilePage(props: Props) {
</div> </div>
</div> </div>
)} )}
{RENDER_MODES.FLOATING_MODES.includes(renderMode) && <FileTitleSection uri={uri} />} {RENDER_MODES.FLOATING_MODES.includes(renderMode) && <FileTitleSection uri={uri} />}
{commentsDisabled && <Empty text={__('The creator of this content has disabled comments.')} />}
<React.Suspense fallback={null}> {commentsDisabled ? (
{!commentsDisabled && <CommentsList uri={uri} linkedCommentId={linkedCommentId} />} <Empty text={__('The creator of this content has disabled comments.')} />
</React.Suspense> ) : (
</div> <React.Suspense fallback={null}>
{!collection && !isMarkdown && videoTheaterMode && <RecommendedContent uri={uri} />} <CommentsList uri={uri} linkedCommentId={linkedCommentId} />
{collection && !isMarkdown && videoTheaterMode && <CollectionContent id={collectionId} uri={uri} />} </React.Suspense>
)}
</>
{!isMarkdown && videoTheaterMode && <RightSideContent {...rightSideProps} />}
</div> </div>
)} )}
</div> </div>
{collection && !isMarkdown && !videoTheaterMode && <CollectionContent id={collectionId} uri={uri} />}
{!collection && !isMarkdown && !videoTheaterMode && <RecommendedContent uri={uri} />} {!isMarkdown
{isMarkdown && ( ? !videoTheaterMode && <RightSideContent {...rightSideProps} />
<div className="file-page__post-comments"> : !commentsDisabled && (
<React.Suspense fallback={null}> <div className="file-page__post-comments">
{!commentsDisabled && <CommentsList uri={uri} linkedCommentId={linkedCommentId} commentsAreExpanded />} <React.Suspense fallback={null}>
</React.Suspense> <CommentsList uri={uri} linkedCommentId={linkedCommentId} commentsAreExpanded />
</div> </React.Suspense>
)} </div>
)}
</Page> </Page>
); );
} }
export default FilePage; type RightSideProps = {
hasCollectionById?: boolean,
collectionId?: string,
uri: string,
};
const RightSideContent = (rightSideProps: RightSideProps) => {
const { hasCollectionById, collectionId, uri } = rightSideProps;
return hasCollectionById ? <CollectionContent id={collectionId} uri={uri} /> : <RecommendedContent uri={uri} />;
};

View file

@ -108,7 +108,7 @@
.file-page__secondary-content { .file-page__secondary-content {
display: flex; display: flex;
flex-direction: row; flex-direction: column;
justify-content: center; justify-content: center;
width: 100%; width: 100%;
margin-top: var(--spacing-m); margin-top: var(--spacing-m);
@ -120,10 +120,6 @@
flex: 1; flex: 1;
max-width: 100%; max-width: 100%;
} }
@media (min-width: $breakpoint-medium) {
flex-direction: row;
}
} }
@keyframes fadeIn { @keyframes fadeIn {