Skip to content

Commit

Permalink
add recommended content
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Yesmunt committed Aug 3, 2018
1 parent 0110f17 commit a411a62
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 62 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"formik": "^0.10.4",
"hast-util-sanitize": "^1.1.2",
"keytar": "^4.2.1",
"lbry-redux": "lbryio/lbry-redux#b4fffe863df316bc73183567ab978221ee623b8c",
"lbry-redux": "lbryio/lbry-redux#03c3354c12f7834e6ed63705ff19487669be32b9",
"localforage": "^1.7.1",
"mime": "^2.3.1",
"mixpanel-browser": "^2.17.1",
Expand Down
16 changes: 6 additions & 10 deletions src/renderer/component/fileCard/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,13 @@ class FileCard extends React.PureComponent<Props> {
<TruncatedText lines={3}>{title}</TruncatedText>
</div>
<div className="card__subtitle">
{pending ? (
<div>Pending...</div>
) : (
<React.Fragment>
<UriIndicator uri={uri} link />
{isRewardContent && <Icon iconColor="red" icon={icons.FEATURED} />}
{fileInfo && <Icon icon={icons.LOCAL} />}
</React.Fragment>
)}
{pending ? <div>Pending...</div> : <UriIndicator uri={uri} link />}
</div>
<div className="card__file-properties">
{showPrice && <FilePrice uri={uri} />}
{isRewardContent && <Icon iconColor="red" icon={icons.FEATURED} />}
{fileInfo && <Icon icon={icons.LOCAL} />}
</div>
{showPrice && <FilePrice uri={uri} />}
</div>
</section>
);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/component/fileTile/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class FileTile extends React.PureComponent<Props> {
'card__title--x-small': small,
})}
>
<TruncatedText lines={3}>{title || name}</TruncatedText>
<TruncatedText lines={small ? 2 : 3}>{title || name}</TruncatedText>
</div>
<div
className={classnames('card__subtitle', {
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/component/recommendedContent/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as settings from 'constants/settings';
import { connect } from 'react-redux';
import { doFetchClaimsByChannel } from 'redux/actions/content';
import { makeSelectClaimsInChannelForCurrentPage } from 'lbry-redux';
import { makeSelectClaimForUri, doSearch, makeSelectRecommendedContentForUri } from 'lbry-redux';
import { doSetClientSetting } from 'redux/actions/settings';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import RecommendedVideos from './view';

const select = (state, props) => ({
claimsInChannel: makeSelectClaimsInChannelForCurrentPage(props.channelUri)(state),
claim: makeSelectClaimForUri(props.uri)(state),
recommendedContent: makeSelectRecommendedContentForUri(props.uri)(state),
autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state),
});

const perform = dispatch => ({
fetchClaims: (uri, page) => dispatch(doFetchClaimsByChannel(uri, page)),
setAutoplay: value => dispatch(doSetClientSetting(settings.AUTOPLAY, value)),
search: query => dispatch(doSearch(query, 20)),
});

export default connect(
Expand Down
80 changes: 50 additions & 30 deletions src/renderer/component/recommendedContent/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,65 @@ import FileTile from 'component/fileTile';
import { FormRow, FormField } from 'component/common/form';
import ToolTip from 'component/common/tooltip';
import type { Claim } from 'types/claim';
import { buildURI, parseURI } from 'lbry-redux';

type Props = {
uri: string,
channelUri: ?string,
claimsInChannel: ?Array<Claim>,
claim: ?Claim,
autoplay: boolean,
recommendedContent: Array<string>,
search: string => void,
setAutoplay: boolean => void,
fetchClaims: (string, number) => void,
};

export default class RecommendedContent extends React.PureComponent<Props> {
type State = {
didSearch: boolean,
};

export default class RecommendedContent extends React.PureComponent<Props, State> {
constructor() {
super();

this.state = {
didSearch: false,
};
}

componentDidMount() {
const { channelUri, fetchClaims, claimsInChannel } = this.props;
if (channelUri && !claimsInChannel) {
fetchClaims(channelUri, 1);
}
this.getRecommendedContent();
}

render() {
const { claimsInChannel, autoplay, uri, setAutoplay } = this.props;
componentDidUpdate(prevProps: Props) {
const { claim, uri } = this.props;
const { didSearch } = this.state;

let recommendedContent;
if (claimsInChannel) {
recommendedContent = claimsInChannel.filter(claim => {
const { name, claim_id: claimId, channel_name: channelName, value } = claim;
const { isChannel } = parseURI(uri);
if (uri !== prevProps.uri) {
this.setState({ didSearch: false });
}

if (claim && !didSearch) {
this.getRecommendedContent();
}
}

// The uri may include the channel name
const recommendedUri =
isChannel && value && value.publisherSignature
? buildURI({
contentName: name,
claimName: channelName,
claimId: value.publisherSignature.certificateId,
})
: buildURI({ claimName: name, claimId });
getRecommendedContent() {
const { claim, search } = this.props;

return recommendedUri !== uri;
});
if (claim && claim.value && claim.value.stream && claim.value.stream.metadata) {
const {
value: {
stream: {
metadata: { title },
},
},
} = claim;
// console.log("search", title)
search(title);
this.setState({ didSearch: true });
}
}

render() {
const { autoplay, setAutoplay, recommendedContent } = this.props;

return (
<section className="card__list--recommended">
Expand All @@ -62,12 +80,14 @@ export default class RecommendedContent extends React.PureComponent<Props> {
</ToolTip>
</FormRow>
{recommendedContent &&
recommendedContent.map(({ permanent_url: permanentUrl }) => (
recommendedContent.length &&
recommendedContent.map(recommendedUri => (
<FileTile
small
hideNoResult
displayDescription={false}
key={permanentUrl}
uri={`lbry://${permanentUrl}`}
key={recommendedUri}
uri={recommendedUri}
/>
))}
</section>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/page/file/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class FilePage extends React.Component<Props> {
</div>
</div>
</section>
<RecommendedContent uri={uri} channelUri={`lbry://${subscriptionUri}`} />
<RecommendedContent uri={uri} />
</Page>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/scss/_gui.scss
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ p {
}

.credit-amount--free {
color: var(--color-secondary);
color: var(--color-credit-free);

&.credit-amount--file-page {
color: var(--color-dark-blue);
Expand All @@ -282,7 +282,7 @@ p {
}

.credit-amount--cost {
color: var(--color-yellow);
color: var(--color-credit-price);

&.credit-amount--file-page {
color: var(--color-black);
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/scss/_vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $large-breakpoint: 1921px;

:root {
/* Widths & spacings */
--side-nav-width: 190px;
--side-nav-width: 160px;
--side-nav-width-m: 240px;
--side-nav-width-l: 320px;
--font-size-subtext-multiple: 0.92;
Expand All @@ -31,7 +31,7 @@ $large-breakpoint: 1921px;
--color-dark-blue: #2f6f61;
--color-light-blue: #49b2e2;
--color-red: #e2495e;
--color-yellow: #fbd55e;
--color-yellow: #e8b414;
--color-green: #399483;
--color-green-light: #effbe4;
--color-green-blue: #2ec1a8;
Expand All @@ -49,6 +49,8 @@ $large-breakpoint: 1921px;
--color-bg-alt: var(--color-grey-light);
--color-placeholder: var(--color-grey);
--color-search-placeholder: var(--color-placeholder);
--color-credit-free: var(--color-dark-blue);
--color-credit-price: var(--color-yellow);

/* Shadows */
--box-shadow-layer: transparent; // 0 2px 4px rgba(0,0,0,0.25);
Expand Down
15 changes: 9 additions & 6 deletions src/renderer/scss/component/_card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@
font-size: 14px;
font-family: 'metropolis-medium';
color: var(--card-text-color);
display: flex;
align-items: center;

.icon {
margin: 0 0 0 $spacing-vertical * 1/3;
}
}

.card__subtitle--x-small {
Expand All @@ -170,6 +164,15 @@
padding-top: $spacing-vertical * 2/3;
}

.card__file-properties {
display: flex;
align-items: center;

.icon {
margin: 0 0 0 $spacing-vertical * 1/3;
}
}

// .card-media__internal__links should always be inside a card
.card {
.card-media__internal-links {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/scss/component/_nav.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.nav {
width: var(--side-nav-width);
min-width: var(--side-nav-width);
background-color: var(--nav-bg-color);
padding: $spacing-width * 1/3;
color: var(--nav-color);
Expand All @@ -13,11 +13,11 @@

@media (min-width: $medium-breakpoint) {
padding-left: $spacing-width;
width: calc(var(--side-nav-width) * 1.2);
width: calc(var(--side-nav-width) * 1.4);
}

@media (min-width: $large-breakpoint) {
width: calc(var(--side-nav-width) * 1.4);
width: calc(var(--side-nav-width) * 1.6);
}
}

Expand Down
1 change: 1 addition & 0 deletions static/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
--color-bg: var(--color-blue-grey);
--color-bg-alt: #2D3D56;
--color-placeholder: var(--color-bg-alt);
--color-credit-free: var(--color-secondary);

/* Text */
--text-color: #FFF;
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5515,9 +5515,9 @@ lazy-val@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/lazy-val/-/lazy-val-1.0.3.tgz#bb97b200ef00801d94c317e29dc6ed39e31c5edc"

lbry-redux@lbryio/lbry-redux#b4fffe863df316bc73183567ab978221ee623b8c:
lbry-redux@lbryio/lbry-redux#03c3354c12f7834e6ed63705ff19487669be32b9:
version "0.0.1"
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/b4fffe863df316bc73183567ab978221ee623b8c"
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/03c3354c12f7834e6ed63705ff19487669be32b9"
dependencies:
proxy-polyfill "0.1.6"
reselect "^3.0.0"
Expand Down

0 comments on commit a411a62

Please sign in to comment.