improve file page ux

This commit is contained in:
Sean Yesmunt 2018-06-19 23:55:25 -04:00 committed by seanyesmunt
parent 6be2388620
commit da96f28794
8 changed files with 182 additions and 147 deletions

View file

@ -5,10 +5,10 @@ import classnames from 'classnames';
type Props = { type Props = {
body: string, body: string,
label?: string, label?: string,
children: ?React.Node, children?: React.Node,
icon: ?boolean, icon?: boolean,
direction: string, direction: string,
onFormField?: boolean, onComponent?: boolean, // extra padding to account for button/form field size
}; };
class ToolTip extends React.PureComponent<Props> { class ToolTip extends React.PureComponent<Props> {
@ -17,9 +17,11 @@ class ToolTip extends React.PureComponent<Props> {
}; };
render() { render() {
const { children, label, body, icon, direction, onFormField } = this.props; const { children, label, body, icon, direction, onComponent } = this.props;
const tooltipContent = children || label; const tooltipContent = children || label;
const bodyLength = body.length;
const isShortDescription = bodyLength < 30;
return ( return (
<span <span
@ -30,11 +32,17 @@ class ToolTip extends React.PureComponent<Props> {
'tooltip--right': direction === 'right', 'tooltip--right': direction === 'right',
'tooltip--bottom': direction === 'bottom', 'tooltip--bottom': direction === 'bottom',
'tooltip--left': direction === 'left', 'tooltip--left': direction === 'left',
'tooltip--on-formfield': onFormField, 'tooltip--on-component': onComponent,
})} })}
> >
{tooltipContent} {tooltipContent}
<span className="tooltip__body">{body}</span> <span
className={classnames('tooltip__body', {
'tooltip__body--short': isShortDescription,
})}
>
{body}
</span>
</span> </span>
); );
} }

View file

@ -1,9 +1,9 @@
// @flow // @flow
import React from 'react'; import * as React from 'react';
import Button from 'component/button'; import Button from 'component/button';
import { MODALS } from 'lbry-redux'; import { MODALS } from 'lbry-redux';
import classnames from 'classnames';
import * as icons from 'constants/icons'; import * as icons from 'constants/icons';
import Tooltip from 'component/common/tooltip';
type FileInfo = { type FileInfo = {
claim_id: string, claim_id: string,
@ -15,34 +15,35 @@ type Props = {
openModal: ({ id: string }, { uri: string }) => void, openModal: ({ id: string }, { uri: string }) => void,
claimIsMine: boolean, claimIsMine: boolean,
fileInfo: FileInfo, fileInfo: FileInfo,
vertical?: boolean, // should the buttons be stacked vertically?
}; };
class FileActions extends React.PureComponent<Props> { class FileActions extends React.PureComponent<Props> {
render() { render() {
const { fileInfo, uri, openModal, claimIsMine, vertical, claimId } = this.props; const { fileInfo, uri, openModal, claimIsMine, claimId } = this.props;
const showDelete = fileInfo && Object.keys(fileInfo).length > 0; const showDelete = fileInfo && Object.keys(fileInfo).length > 0;
return ( return (
<section className={classnames('card__actions', { 'card__actions--vertical': vertical })}> <React.Fragment>
{showDelete && ( {showDelete && (
<Button <Tooltip onComponent body={__('Delete this file')}>
button="alt" <Button
icon={icons.TRASH} button="alt"
iconColor="red" icon={icons.TRASH}
label={__('Delete')} description={__('Delete')}
onClick={() => openModal({ id: MODALS.CONFIRM_FILE_REMOVE }, { uri })} onClick={() => openModal({ id: MODALS.CONFIRM_FILE_REMOVE }, { uri })}
/> />
</Tooltip>
)} )}
{!claimIsMine && ( {!claimIsMine && (
<Button <Tooltip onComponent body={__('Report content')}>
button="alt" <Button
icon={icons.REPORT} button="alt"
href={`https://lbry.io/dmca?claim_id=${claimId}`} icon={icons.REPORT}
label={__('Report content')} href={`https://lbry.io/dmca?claim_id=${claimId}`}
/> />
</Tooltip>
)} )}
</section> </React.Fragment>
); );
} }
} }

View file

@ -2,6 +2,7 @@
import React from 'react'; import React from 'react';
import Button from 'component/button'; import Button from 'component/button';
import * as icons from 'constants/icons'; import * as icons from 'constants/icons';
import ToolTip from 'component/common/tooltip';
type Props = { type Props = {
uri: string, uri: string,
@ -59,7 +60,7 @@ class FileDownloadLink extends React.PureComponent<Props> {
if (loading || downloading) { if (loading || downloading) {
const progress = const progress =
fileInfo && fileInfo.written_bytes fileInfo && fileInfo.written_bytes
? fileInfo.written_bytes / fileInfo.total_bytes * 100 ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100
: 0; : 0;
const label = fileInfo const label = fileInfo
? __('Downloading: ') + progress.toFixed(0) + __('% complete') ? __('Downloading: ') + progress.toFixed(0) + __('% complete')
@ -72,25 +73,22 @@ class FileDownloadLink extends React.PureComponent<Props> {
} }
return ( return (
<Button <ToolTip onComponent body={__('Download')}>
button="alt" <Button
label={__('Download')} button="alt"
icon={icons.DOWNLOAD} icon={icons.DOWNLOAD}
iconColor="purple" iconColor="purple"
onClick={() => { onClick={() => {
purchaseUri(uri); purchaseUri(uri);
}} }}
/> />
</ToolTip>
); );
} else if (fileInfo && fileInfo.download_path) { } else if (fileInfo && fileInfo.download_path) {
return ( return (
<Button <ToolTip onComponent body={__('Open file')}>
button="alt" <Button button="alt" iconColor="purple" icon={icons.LOCAL} onClick={() => openFile()} />
iconColor="purple" </ToolTip>
label={__('Open File')}
icon={icons.OPEN}
onClick={() => openFile()}
/>
); );
} }

View file

@ -3,8 +3,6 @@ import {
selectSearchState as selectSearch, selectSearchState as selectSearch,
selectWunderBarAddress, selectWunderBarAddress,
doUpdateSearchQuery, doUpdateSearchQuery,
doNotify,
MODALS,
doFocusSearchInput, doFocusSearchInput,
doBlurSearchInput, doBlurSearchInput,
doSearch, doSearch,
@ -37,4 +35,7 @@ const perform = dispatch => ({
doBlur: () => dispatch(doBlurSearchInput()), doBlur: () => dispatch(doBlurSearchInput()),
}); });
export default connect(select, perform)(Wunderbar); export default connect(
select,
perform
)(Wunderbar);

View file

@ -167,10 +167,10 @@ class FilePage extends React.Component<Props> {
<div className="card__title-identity--file"> <div className="card__title-identity--file">
<h1 className="card__title card__title--file">{title}</h1> <h1 className="card__title card__title--file">{title}</h1>
<div className="card__title-identity-icons"> <div className="card__title-identity-icons">
<FilePrice uri={normalizeURI(uri)} />
{isRewardContent && ( {isRewardContent && (
<Icon iconColor="red" tooltip="bottom" icon={icons.FEATURED} /> <Icon iconColor="red" tooltip="bottom" icon={icons.FEATURED} />
)} )}
<FilePrice uri={normalizeURI(uri)} />
</div> </div>
</div> </div>
<span className="card__subtitle card__subtitle--file"> <span className="card__subtitle card__subtitle--file">
@ -180,60 +180,55 @@ class FilePage extends React.Component<Props> {
{metadata.nsfw && <div>NSFW</div>} {metadata.nsfw && <div>NSFW</div>}
<div className="card__channel-info"> <div className="card__channel-info">
<UriIndicator uri={uri} link /> <UriIndicator uri={uri} link />
<div className="card__actions card__actions--no-margin"> </div>
{claimIsMine ? ( <div className="card__actions card__actions--between">
<Button {(claimIsMine || subscriptionUri || speechSharable) && (
button="primary" <div className="card__actions">
icon={icons.EDIT} {claimIsMine ? (
label={__('Edit')} <Button
onClick={() => { button="primary"
prepareEdit(claim, editUri); icon={icons.EDIT}
navigate('/publish'); label={__('Edit')}
}} onClick={() => {
/> prepareEdit(claim, editUri);
) : ( navigate('/publish');
<SubscribeButton uri={subscriptionUri} channelName={channelName} /> }}
)} />
) : (
<SubscribeButton uri={subscriptionUri} channelName={channelName} />
)}
{!claimIsMine && (
<Button
button="alt"
icon="Send"
label={__('Enjoy this? Send a tip')}
onClick={() => openModal({ id: MODALS.SEND_TIP }, { uri })}
/>
)}
{speechSharable && (
<ViewOnWebButton claimId={claim.claim_id} claimName={claim.name} />
)}
</div>
)}
<div className="card__actions">
<FileDownloadLink uri={uri} />
<FileActions uri={uri} claimId={claim.claim_id} />
</div> </div>
</div> </div>
{(!claimIsMine || speechSharable) && ( <FormRow padded>
<div className="card__actions card__actions--end"> <ToolTip onComponent body={__('Automatically download and play free content.')}>
{!claimIsMine && ( <FormField
<Button useToggle
button="alt" name="autoplay"
icon="Send" type="checkbox"
label={__('Enjoy this? Send a tip')} postfix={__('Autoplay')}
onClick={() => openModal({ id: MODALS.SEND_TIP }, { uri })} checked={autoplay}
/> onChange={this.onAutoplayChange}
)} />
{speechSharable && ( </ToolTip>
<ViewOnWebButton claimId={claim.claim_id} claimName={claim.name} />
)}
</div>
)}
<FormRow alignRight padded>
<FormField
useToggle
name="autoplay"
type="checkbox"
checked={autoplay}
onChange={this.onAutoplayChange}
postfix={
<ToolTip
onFormField
label={__('Autoplay')}
body={__('Automatically download and play free content.')}
/>
}
/>
</FormRow> </FormRow>
</div> </div>
<div className="card__content">
<FileDownloadLink uri={uri} />
<FileActions uri={uri} claimId={claim.claim_id} />
</div>
<div className="card__content--extra-padding"> <div className="card__content--extra-padding">
<FileDetails uri={uri} /> <FileDetails uri={uri} />
</div> </div>

View file

@ -93,9 +93,9 @@
.card__title-identity--file { .card__title-identity--file {
display: flex; display: flex;
align-items: center; align-items: center;
.credit-amount,
.icon { .icon {
margin: $spacing-vertical * 1/3; margin: 0 $spacing-vertical * 1/3;
} }
} }
@ -198,7 +198,7 @@
.card__subtext-title { .card__subtext-title {
color: var(--text-color); color: var(--text-color);
font-size: calc(var(--font-size-subtext-multiple) * 1.5em); font-size: calc(var(--font-size-subtext-multiple) * 1.2em);
&:not(:first-of-type) { &:not(:first-of-type) {
margin-top: $spacing-vertical * 3/2; margin-top: $spacing-vertical * 3/2;
@ -220,8 +220,12 @@
margin-top: $spacing-vertical * 2/3; margin-top: $spacing-vertical * 2/3;
display: flex; display: flex;
&:not(.card__actions--vertical) .btn:nth-child(n + 2) { &:not(.card__actions--vertical) {
margin-left: $spacing-vertical / 3; .btn:nth-child(n + 2),
// For buttons wrapped in a tooltip
.tooltip:nth-child(n + 2) {
margin-left: $spacing-vertical / 3;
}
} }
} }
@ -258,6 +262,11 @@
justify-content: flex-end; justify-content: flex-end;
} }
.card__actions--between {
justify-content: space-between;
flex-wrap: wrap;
}
/* /*
.card-row is used on the discover page .card-row is used on the discover page
It is a list of cards that extend past the right edge of the screen It is a list of cards that extend past the right edge of the screen

View file

@ -1,3 +1,4 @@
.file-download { .file-download {
font-size: 0.8em; font-size: 0.8em;
align-self: center;
} }

View file

@ -13,43 +13,57 @@
} }
} }
.tooltip--on-formfield {
padding: 0;
}
.tooltip--icon { .tooltip--icon {
margin-top: 5px; margin-top: 5px;
} }
/* Tooltip text */ /* Tooltip text */
.tooltip .tooltip__body { .tooltip {
background-color: var(--tooltip-bg); .tooltip__body {
font-family: 'metropolis-medium'; background-color: var(--tooltip-bg);
font-size: 12px; font-family: 'metropolis-medium';
color: var(--tooltip-color); font-size: 12px;
border-radius: 8px; color: var(--tooltip-color);
position: absolute; border-radius: 8px;
z-index: 1; position: absolute;
width: 200px; z-index: 1;
text-align: center; width: 200px;
white-space: pre-wrap; text-align: center;
padding: $spacing-vertical * 1/3; white-space: pre-wrap;
visibility: hidden; padding: $spacing-vertical * 1/3;
visibility: hidden;
}
.tooltip__body--short {
width: 130px;
}
.tooltip__body::after {
content: ' ';
width: 0;
height: 0;
position: absolute;
border-width: 5px;
border-style: solid;
}
&.tooltip--on-component {
.tooltip__body {
margin-top: 10px;
}
}
} }
.tooltip .tooltip__body::after { .tooltip--top {
content: ' '; .tooltip__body {
width: 0; bottom: 100%;
height: 0; left: 50%;
position: absolute; margin-left: -100px;
border-width: 5px;
border-style: solid;
}
.tooltip--top .tooltip__body { &.tooltip__body--short {
bottom: 100%; margin-left: -65px;
left: 50%; }
margin-left: -100px; }
&::after { &::after {
top: 100%; top: 100%;
@ -59,28 +73,36 @@
} }
} }
.tooltip--right .tooltip__body { .tooltip--right {
margin-top: -5px; .tooltip__body {
margin-left: 10px;
&::after {
top: 17px;
right: 100%; /* To the left of the tooltip */
margin-top: -5px; margin-top: -5px;
border-color: transparent var(--tooltip-bg) transparent transparent; margin-left: 10px;
&::after {
top: 17px;
right: 100%; /* To the left of the tooltip */
margin-top: -5px;
border-color: transparent var(--tooltip-bg) transparent transparent;
}
} }
} }
.tooltip--bottom .tooltip__body { .tooltip--bottom {
top: 90%; .tooltip__body {
left: 50%; top: 90%;
margin-left: -100px;
&::after {
bottom: 100%;
left: 50%; left: 50%;
margin-left: -5px; margin-left: -100px;
border-color: transparent transparent var(--tooltip-bg) transparent;
&.tooltip__body--short {
margin-left: -65px;
}
&::after {
bottom: 100%;
left: 50%;
margin-left: -5px;
border-color: transparent transparent var(--tooltip-bg) transparent;
}
} }
} }