Clean code

This commit is contained in:
Raphael Wickihalder 2022-05-04 12:36:48 +02:00 committed by Thomas Zarebczan
parent d3fc96d961
commit 7045f4ed45
2 changed files with 3 additions and 50 deletions

View file

@ -1,30 +1,9 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom'; import { withRouter } from 'react-router-dom';
import WatchHistoryPage from './view'; import WatchHistoryPage from './view';
import { import { makeSelectClaimForClaimId, makeSelectChannelForClaimUri } from 'redux/selectors/claims';
selectTitleForUri,
selectClaimIsMine,
makeSelectClaimIsPending,
makeSelectClaimForClaimId,
makeSelectChannelForClaimUri,
} from 'redux/selectors/claims';
import { selectHistory } from 'redux/selectors/content'; import { selectHistory } from 'redux/selectors/content';
import { doClearContentHistoryAll } from 'redux/actions/content'; import { doClearContentHistoryAll } from 'redux/actions/content';
import {
makeSelectCollectionForId,
makeSelectUrlsForCollectionId,
makeSelectIsResolvingCollectionForId,
makeSelectCollectionIsMine,
makeSelectCountForCollectionId,
makeSelectEditedCollectionForId,
} from 'redux/selectors/collections';
import { getThumbnailFromClaim } from 'util/claim';
import { doFetchItemsInCollection, doCollectionDelete, doCollectionEdit } from 'redux/actions/collections';
import { selectUser } from 'redux/selectors/user'; import { selectUser } from 'redux/selectors/user';
const select = (state, props) => { const select = (state, props) => {
@ -36,19 +15,7 @@ const select = (state, props) => {
const uri = (claim && (claim.canonical_url || claim.permanent_url)) || null; const uri = (claim && (claim.canonical_url || claim.permanent_url)) || null;
return { return {
collectionId,
claim,
collection: makeSelectCollectionForId(collectionId)(state),
collectionUrls: makeSelectUrlsForCollectionId(collectionId)(state),
collectionCount: makeSelectCountForCollectionId(collectionId)(state),
isResolvingCollection: makeSelectIsResolvingCollectionForId(collectionId)(state),
selectHistory: selectHistory(state, uri), selectHistory: selectHistory(state, uri),
title: selectTitleForUri(state, uri),
thumbnail: getThumbnailFromClaim(claim),
isMyClaim: selectClaimIsMine(state, claim), // or collection is mine?
isMyCollection: makeSelectCollectionIsMine(collectionId)(state),
claimIsPending: makeSelectClaimIsPending(uri)(state),
collectionHasEdits: Boolean(makeSelectEditedCollectionForId(collectionId)(state)),
uri, uri,
user: selectUser(state), user: selectUser(state),
channel: uri && makeSelectChannelForClaimUri(uri)(state), channel: uri && makeSelectChannelForClaimUri(uri)(state),
@ -57,9 +24,6 @@ const select = (state, props) => {
const perform = (dispatch) => ({ const perform = (dispatch) => ({
doClearContentHistoryAll: () => dispatch(doClearContentHistoryAll()), doClearContentHistoryAll: () => dispatch(doClearContentHistoryAll()),
fetchCollectionItems: (claimId, cb) => dispatch(doFetchItemsInCollection({ collectionId: claimId }, cb)), // if this collection is not resolved, resolve it
deleteCollection: (id, colKey) => dispatch(doCollectionDelete(id, colKey)),
editCollection: (id, params) => dispatch(doCollectionEdit(id, params)),
}); });
export default withRouter(connect(select, perform)(WatchHistoryPage)); export default withRouter(connect(select, perform)(WatchHistoryPage));

View file

@ -12,21 +12,12 @@ import Tooltip from 'component/common/tooltip';
export const PAGE_VIEW_QUERY = 'view'; export const PAGE_VIEW_QUERY = 'view';
type Props = { type Props = {
collectionId: string,
claim: Claim,
title: string,
thumbnail: string,
collectionUrls: Array<string>,
isResolvingCollection: boolean,
selectHistory: Array<any>, selectHistory: Array<any>,
doClearContentHistoryAll: () => void, doClearContentHistoryAll: () => void,
fetchCollectionItems: (string, () => void) => void,
resolveUris: (string) => void,
user: ?User,
}; };
export default function WatchHistoryPage(props: Props) { export default function WatchHistoryPage(props: Props) {
const { collectionId, selectHistory, doClearContentHistoryAll } = props; const { selectHistory, doClearContentHistoryAll } = props;
const [watchHistory, setWatchHistory] = useState([]); const [watchHistory, setWatchHistory] = useState([]);
const [unavailableUris] = React.useState([]); const [unavailableUris] = React.useState([]);
@ -67,9 +58,7 @@ export default function WatchHistoryPage(props: Props) {
)} )}
</div> </div>
</div> </div>
{watchHistory.length > 0 && ( {watchHistory.length > 0 && <ClaimList uris={watchHistory} unavailableUris={unavailableUris} inWatchHistory />}
<ClaimList uris={watchHistory} collectionId={collectionId} unavailableUris={unavailableUris} inWatchHistory />
)}
{watchHistory.length === 0 && ( {watchHistory.length === 0 && (
<div style={{ textAlign: 'center' }}> <div style={{ textAlign: 'center' }}>
<img src={YRBL_SAD_IMG_URL} /> <img src={YRBL_SAD_IMG_URL} />