fix channel tooltip styles / render issues

This commit is contained in:
btzr-io 2019-06-11 20:22:21 -06:00
parent 7d282d07af
commit ce7d488fd6
12 changed files with 80 additions and 95 deletions

View file

@ -164,7 +164,6 @@
"remark-attr": "^0.8.3", "remark-attr": "^0.8.3",
"remark-emoji": "^2.0.1", "remark-emoji": "^2.0.1",
"remark-react": "^4.0.3", "remark-react": "^4.0.3",
"remark-squeeze-paragraphs": "^3.0.3",
"render-media": "^3.1.0", "render-media": "^3.1.0",
"reselect": "^3.0.0", "reselect": "^3.0.0",
"sass-loader": "^7.1.0", "sass-loader": "^7.1.0",
@ -176,6 +175,7 @@
"three": "^0.93.0", "three": "^0.93.0",
"three-full": "^17.1.0", "three-full": "^17.1.0",
"tree-kill": "^1.1.0", "tree-kill": "^1.1.0",
"uniqid": "^5.0.3",
"unist-util-visit": "^1.4.1", "unist-util-visit": "^1.4.1",
"video.js": "^7.2.2", "video.js": "^7.2.2",
"villain": "btzr-io/Villain", "villain": "btzr-io/Villain",

View file

@ -7,6 +7,7 @@ import { formatLbryUriForWeb } from 'util/uri';
import { OutboundLink } from 'react-ga'; import { OutboundLink } from 'react-ga';
type Props = { type Props = {
id: ?string,
href: ?string, href: ?string,
title: ?string, title: ?string,
label: ?string, label: ?string,
@ -37,6 +38,7 @@ class Button extends React.PureComponent<Props> {
render() { render() {
const { const {
id,
onClick, onClick,
onMouseEnter, onMouseEnter,
onMouseLeave, onMouseLeave,
@ -109,6 +111,7 @@ class Button extends React.PureComponent<Props> {
return path ? ( return path ? (
<NavLink <NavLink
id={id}
exact exact
to={path} to={path}
title={title} title={title}
@ -128,6 +131,7 @@ class Button extends React.PureComponent<Props> {
</NavLink> </NavLink>
) : ( ) : (
<button <button
id={id}
title={title} title={title}
aria-label={description || label || title} aria-label={description || label || title}
className={combinedClassName} className={combinedClassName}

View file

@ -1,4 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { THEME } from 'constants/settings';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import { import {
doResolveUri, doResolveUri,
@ -21,6 +23,7 @@ const select = (state, props) => {
title: makeSelectTitleForUri(props.uri)(state), title: makeSelectTitleForUri(props.uri)(state),
thumbnail: makeSelectThumbnailForUri(props.uri)(state), thumbnail: makeSelectThumbnailForUri(props.uri)(state),
description: makeSelectMetadataItemForUri(props.uri, 'description')(state), description: makeSelectMetadataItemForUri(props.uri, 'description')(state),
currentTheme: makeSelectClientSetting(THEME)(state),
channelIsMine: makeSelectClaimIsMine(props.uri)(state), channelIsMine: makeSelectClaimIsMine(props.uri)(state),
isResolvingUri: makeSelectIsUriResolving(props.uri)(state), isResolvingUri: makeSelectIsUriResolving(props.uri)(state),
blackListedOutpoints: selectBlackListedOutpoints(state), blackListedOutpoints: selectBlackListedOutpoints(state),

View file

@ -1,8 +1,8 @@
// @flow // @flow
import * as React from 'react'; import * as React from 'react';
import { parseURI } from 'lbry-redux';
import Button from 'component/button'; import Button from 'component/button';
import ChannelTooltip from 'component/common/channel-tooltip'; import ChannelTooltip from 'component/common/channel-tooltip';
import uniqid from 'uniqid';
type Props = { type Props = {
uri: string, uri: string,
@ -11,6 +11,7 @@ type Props = {
children: React.Node, children: React.Node,
thumbnail: ?string, thumbnail: ?string,
description: ?string, description: ?string,
currentTheme: ?string,
isResolvingUri: boolean, isResolvingUri: boolean,
resolveUri: string => void, resolveUri: string => void,
blackListedOutpoints: Array<{ blackListedOutpoints: Array<{
@ -24,6 +25,7 @@ type State = {
}; };
class ChannelLink extends React.Component<Props, State> { class ChannelLink extends React.Component<Props, State> {
parentId: string;
buttonRef: { current: ?any }; buttonRef: { current: ?any };
static defaultProps = { static defaultProps = {
@ -34,28 +36,21 @@ class ChannelLink extends React.Component<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.state = { isTooltipActive: false }; this.state = { isTooltipActive: false };
(this: any).buttonRef = React.createRef();
// The tooltip component don't work very well with refs,
// so we need to use an unique id for each link:
// (this: any).buttonRef = React.createRef();
(this: any).parentId = uniqid.time('channnel-');
} }
showTooltip = () => { showTooltip = () => {
if (this.isTooltipReady()) { this.setState({ isTooltipActive: true });
setTimeout(() => this.setState({ isTooltipActive: true }), 500);
}
}; };
hideTooltip = () => { hideTooltip = () => {
if (this.isTooltipReady()) { this.setState({ isTooltipActive: false });
setTimeout(() => this.setState({ isTooltipActive: false }), 500);
}
}; };
isTooltipReady() {
const { claim, isResolvingUri } = this.props;
const blackListed = this.isClaimBlackListed();
const isReady = !blackListed && !isResolvingUri && claim !== null;
return isReady && this.buttonRef.current !== null;
}
isClaimBlackListed() { isClaimBlackListed() {
const { claim, blackListedOutpoints } = this.props; const { claim, blackListedOutpoints } = this.props;
@ -88,9 +83,7 @@ class ChannelLink extends React.Component<Props, State> {
} }
render() { render() {
const { uri, claim, title, description, thumbnail, children, isResolvingUri } = this.props; const { uri, claim, title, description, thumbnail, children, currentTheme, isResolvingUri } = this.props;
const { channelName, claimName, claimId } = parseURI(uri);
const tooltipReady = this.isTooltipReady();
const isUnresolved = (!isResolvingUri && !claim) || !claim; const isUnresolved = (!isResolvingUri && !claim) || !claim;
const isBlacklisted = this.isClaimBlackListed(); const isBlacklisted = this.isClaimBlackListed();
@ -98,29 +91,30 @@ class ChannelLink extends React.Component<Props, State> {
return <span className="channel-name">{children}</span>; return <span className="channel-name">{children}</span>;
} }
const { claim_id: claimId, name: channelName } = claim;
return ( return (
<React.Fragment> <React.Fragment>
<Button <Button
id={this.parentId}
className="button--uri-indicator" className="button--uri-indicator"
label={children} label={children}
navigate={uri} navigate={uri}
innerRef={this.buttonRef}
onMouseEnter={this.showTooltip} onMouseEnter={this.showTooltip}
onMouseLeave={this.hideTooltip} onMouseLeave={this.hideTooltip}
/> />
{tooltipReady && ( <ChannelTooltip
<ChannelTooltip uri={uri}
uri={uri} title={title}
title={title} claimId={claimId}
claimId={claimId} channelName={channelName}
claimName={claimName} currentTheme={currentTheme}
channelName={channelName} thumbnail={thumbnail}
thumbnail={thumbnail} description={description}
description={description} active={this.state.isTooltipActive}
active={this.state.isTooltipActive} parent={`#${this.parentId}`}
parent={this.buttonRef.current} group={'channel-tooltip'}
/> />
)}
</React.Fragment> </React.Fragment>
); );
} }

View file

@ -7,45 +7,55 @@ import ChannelThumbnail from 'component/common/channelThumbnail';
type TooltipProps = { type TooltipProps = {
uri: string, uri: string,
title: ?string, title: ?string,
group: ?string,
active: ?boolean, active: ?boolean,
parent: ?HTMLElement, parent: ?HTMLElement | ?string,
claimId: ?string, claimId: string,
thumbnail: ?string, thumbnail: ?string,
claimName: ?string, channelName: string,
channelName: ?string,
description: ?string, description: ?string,
currentTheme: ?string,
}; };
const ChannelTooltip = (props: TooltipProps) => { const ChannelTooltip = (props: TooltipProps) => {
const { uri, title, active, parent, claimId, thumbnail, claimName, channelName, description } = props; const { uri, group, title, active, parent, claimId, thumbnail, description, channelName, currentTheme } = props;
const bgColor = '#32373b'; let bgColor = 'var(--lbry-white)';
if (currentTheme === 'dark') {
// Background color of the tooltip component,
// taken from the header component:
// mix($lbry-black, $lbry-gray-3, 90%);
bgColor = '#32373b';
}
const style = { const style = {
style: { background: bgColor }, style: { background: bgColor, padding: 0 },
arrowStyle: { color: bgColor }, arrowStyle: { color: bgColor, borderColor: false },
}; };
const channelUrl = `${channelName}#${claimId}`;
const formatedName = channelName.replace('@', '');
return ( return (
<ToolTip <ToolTip
align="left" align="left"
arrow="left" arrow="left"
group="channel-tooltip" active={parent && active}
active={active} group={group}
style={style} style={style}
parent={parent} parent={parent}
position="bottom" position="bottom"
tooltipTimeout={0}
> >
<div className={'channel-tooltip'}> <div className={'channel-tooltip'}>
<div className={'media-tile media-tile--small card--link'}> <div className={'channel-tooltip__profile'}>
<ChannelThumbnail uri={uri} thumbnail={thumbnail} /> <ChannelThumbnail uri={uri} thumbnail={thumbnail} />
<div className={'channel-tooltip__info'}> <div className={'channel-tooltip__info'}>
<h2 className={'channel-tooltip__title'}> <h2 className={'channel-tooltip__title'}>
<TruncatedText lines={1}>{title || channelName}</TruncatedText> <TruncatedText lines={1}>{title || formatedName}</TruncatedText>
</h2> </h2>
<h3 className={'channel-tooltip__url'}> <h3 className={'channel-tooltip__url'}>
<TruncatedText lines={1}>{claimName + (claimId ? `#${claimId}` : '')}</TruncatedText> <TruncatedText lines={1}>{channelUrl}</TruncatedText>
</h3> </h3>
</div> </div>
</div> </div>
@ -62,4 +72,4 @@ const ChannelTooltip = (props: TooltipProps) => {
); );
}; };
export default ChannelTooltip; export default React.memo<TooltipProps>(ChannelTooltip);

View file

@ -7,11 +7,10 @@ import Gerbil from './gerbil.png';
type Props = { type Props = {
uri: string, uri: string,
thumbnail: ?string, thumbnail: ?string,
className?: string,
}; };
function ChannelThumbnail(props: Props) { function ChannelThumbnail(props: Props) {
const { className, thumbnail, uri } = props; const { thumbnail, uri } = props;
// Generate a random color class based on the first letter of the channel name // Generate a random color class based on the first letter of the channel name
const { channelName } = parseURI(uri); const { channelName } = parseURI(uri);
@ -22,7 +21,6 @@ function ChannelThumbnail(props: Props) {
<div <div
className={classnames('channel-thumbnail', { className={classnames('channel-thumbnail', {
[thumbnailClass]: !thumbnail, [thumbnailClass]: !thumbnail,
[className]: className,
})} })}
> >
{!thumbnail && <img className="channel-thumbnail__default" src={Gerbil} />} {!thumbnail && <img className="channel-thumbnail__default" src={Gerbil} />}

View file

@ -62,6 +62,7 @@ const MarkdownPreview = (props: MarkdownProps) => {
scope: 'extended', scope: 'extended',
elements: ['link'], elements: ['link'],
extend: { link: ['data-preview'] }, extend: { link: ['data-preview'] },
defaultValue: true,
}; };
// Strip all content and just render text // Strip all content and just render text

View file

@ -52,4 +52,4 @@ const PreviewLink = (props: Props) => {
); );
}; };
export default withRouter(PreviewLink); export default withRouter(React.memo(PreviewLink));

View file

@ -45,6 +45,7 @@ class ExternalLink extends React.PureComponent<Props> {
if (protocol && protocol[0] === 'lbry:' && isURIValid(href)) { if (protocol && protocol[0] === 'lbry:' && isURIValid(href)) {
try { try {
const uri = parseURI(href); const uri = parseURI(href);
if (uri.isChannel && !uri.path) { if (uri.isChannel && !uri.path) {
element = ( element = (
<ChannelLink uri={href} link> <ChannelLink uri={href} link>

View file

@ -94,33 +94,33 @@ $metadata-z-index: 1;
.channel-thumbnail { .channel-thumbnail {
left: 0; left: 0;
position: relative; position: relative;
margin-right: 0;
flex-shrink: 0; flex-shrink: 0;
text-align: center; text-align: center;
display: flex; display: flex;
max-width: 5rem; max-width: 5rem;
max-height: 5rem; max-height: 5rem;
margin-right: 1rem;
box-shadow: 0px 2px 10px -2px $lbry-black;
} }
} }
.channel-tooltip .media-tile { .channel-tooltip__profile {
display: flex;
align-items: center; align-items: center;
padding: 1rem;
} }
.channel-tooltip__description { .channel-tooltip__description {
padding: 8px; padding: 1rem;
margin: 4px 0;
border-top: 1px solid rgba(0, 0, 0, 0.2);
border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}
.channel-tooltip__description {
visibility: visible; visibility: visible;
border-top: 1px solid rgba($lbry-gray-4, 0.4);
html[data-mode='dark'] & {
border-top: 1px solid rgba($lbry-black, 0.8);
}
} }
.channel-tooltip__info { .channel-tooltip__info {
padding: 8px;
margin: 4px 0;
align-items: center; align-items: center;
visibility: visible; visibility: visible;
} }
@ -129,13 +129,8 @@ $metadata-z-index: 1;
font-weight: bold; font-weight: bold;
font-size: 1.4rem; font-size: 1.4rem;
line-height: 1.5em; line-height: 1.5em;
margin: 0;
margin-left: 4px;
color: $lbry-white;
} }
.channel-tooltip__url { .channel-tooltip__url {
font-size: 1rem; font-size: 1rem;
margin-left: 4px;
padding: 0;
} }

View file

@ -12,7 +12,7 @@ html {
background-color: $lbry-white; background-color: $lbry-white;
font-size: 12px; font-size: 12px;
height: 100%; height: 100%;
overflow-x: hidden; overflow: hidden;
} }
body { body {

View file

@ -7078,13 +7078,6 @@ md5@^2.2.1:
crypt "~0.0.1" crypt "~0.0.1"
is-buffer "~1.1.1" is-buffer "~1.1.1"
mdast-squeeze-paragraphs@^3.0.0:
version "3.0.5"
resolved "https://registry.yarnpkg.com/mdast-squeeze-paragraphs/-/mdast-squeeze-paragraphs-3.0.5.tgz#f428b6b944f8faef454db9b58f170c4183cb2e61"
integrity sha512-xX6Vbe348Y/rukQlG4W3xH+7v4ZlzUbSY4HUIQCuYrF2DrkcHx584mCaFxkWoDZKNUfyLZItHC9VAqX3kIP7XA==
dependencies:
unist-util-remove "^1.0.0"
mdast-util-compact@^1.0.0: mdast-util-compact@^1.0.0:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/mdast-util-compact/-/mdast-util-compact-1.0.2.tgz#c12ebe16fffc84573d3e19767726de226e95f649" resolved "https://registry.yarnpkg.com/mdast-util-compact/-/mdast-util-compact-1.0.2.tgz#c12ebe16fffc84573d3e19767726de226e95f649"
@ -9838,13 +9831,6 @@ remark-react@^4.0.3:
hast-util-sanitize "^1.0.0" hast-util-sanitize "^1.0.0"
mdast-util-to-hast "^3.0.0" mdast-util-to-hast "^3.0.0"
remark-squeeze-paragraphs@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/remark-squeeze-paragraphs/-/remark-squeeze-paragraphs-3.0.3.tgz#299d8db7d44008c9ae240dbf6d1f55b8b0f924ce"
integrity sha512-eDvjtwFa9eClqb7XgdF/1H9Pfs2LPnf/P3eRs9ucYAWUuv4WO8ZOVAUeT/1h66rQvghnfctz9au+HEmoKcdoqA==
dependencies:
mdast-squeeze-paragraphs "^3.0.0"
remark-stringify@^5.0.0: remark-stringify@^5.0.0:
version "5.0.0" version "5.0.0"
resolved "https://registry.yarnpkg.com/remark-stringify/-/remark-stringify-5.0.0.tgz#336d3a4d4a6a3390d933eeba62e8de4bd280afba" resolved "https://registry.yarnpkg.com/remark-stringify/-/remark-stringify-5.0.0.tgz#336d3a4d4a6a3390d933eeba62e8de4bd280afba"
@ -11467,6 +11453,11 @@ uniq@^1.0.1:
resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff" resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"
integrity sha1-sxxa6CVIRKOoKBVBzisEuGWnNP8= integrity sha1-sxxa6CVIRKOoKBVBzisEuGWnNP8=
uniqid@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/uniqid/-/uniqid-5.0.3.tgz#917968310edc868d50df6c44f783f32c7d80fac1"
integrity sha512-R2qx3X/LYWSdGRaluio4dYrPXAJACTqyUjuyXHoJLBUOIfmMcnYOyY2d6Y4clZcIz5lK6ZaI0Zzmm0cPfsIqzQ==
uniqs@^2.0.0: uniqs@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/uniqs/-/uniqs-2.0.0.tgz#ffede4b36b25290696e6e165d4a59edb998e6b02" resolved "https://registry.yarnpkg.com/uniqs/-/uniqs-2.0.0.tgz#ffede4b36b25290696e6e165d4a59edb998e6b02"
@ -11510,11 +11501,6 @@ unist-util-is@^2.0.0, unist-util-is@^2.1.2:
resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-2.1.2.tgz#1193fa8f2bfbbb82150633f3a8d2eb9a1c1d55db" resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-2.1.2.tgz#1193fa8f2bfbbb82150633f3a8d2eb9a1c1d55db"
integrity sha512-YkXBK/H9raAmG7KXck+UUpnKiNmUdB+aBGrknfQ4EreE1banuzrKABx3jP6Z5Z3fMSPMQQmeXBlKpCbMwBkxVw== integrity sha512-YkXBK/H9raAmG7KXck+UUpnKiNmUdB+aBGrknfQ4EreE1banuzrKABx3jP6Z5Z3fMSPMQQmeXBlKpCbMwBkxVw==
unist-util-is@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-3.0.0.tgz#d9e84381c2468e82629e4a5be9d7d05a2dd324cd"
integrity sha512-sVZZX3+kspVNmLWBPAB6r+7D9ZgAFPNWm66f7YNb420RlQSbn+n8rG8dGZSkrER7ZIXGQYNm5pqC3v3HopH24A==
unist-util-position@^3.0.0: unist-util-position@^3.0.0:
version "3.0.2" version "3.0.2"
resolved "https://registry.yarnpkg.com/unist-util-position/-/unist-util-position-3.0.2.tgz#80ad4a05efc4ab01a66886cc70493893ba73c5eb" resolved "https://registry.yarnpkg.com/unist-util-position/-/unist-util-position-3.0.2.tgz#80ad4a05efc4ab01a66886cc70493893ba73c5eb"
@ -11527,13 +11513,6 @@ unist-util-remove-position@^1.0.0:
dependencies: dependencies:
unist-util-visit "^1.1.0" unist-util-visit "^1.1.0"
unist-util-remove@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/unist-util-remove/-/unist-util-remove-1.0.3.tgz#58ec193dfa84b52d5a055ffbc58e5444eb8031a3"
integrity sha512-mB6nCHCQK0pQffUAcCVmKgIWzG/AXs/V8qpS8K72tMPtOSCMSjDeMc5yN+Ye8rB0FhcE+JvW++o1xRNc0R+++g==
dependencies:
unist-util-is "^3.0.0"
unist-util-stringify-position@^1.0.0, unist-util-stringify-position@^1.1.1: unist-util-stringify-position@^1.0.0, unist-util-stringify-position@^1.1.1:
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/unist-util-stringify-position/-/unist-util-stringify-position-1.1.2.tgz#3f37fcf351279dcbca7480ab5889bb8a832ee1c6" resolved "https://registry.yarnpkg.com/unist-util-stringify-position/-/unist-util-stringify-position-1.1.2.tgz#3f37fcf351279dcbca7480ab5889bb8a832ee1c6"