fix select/unselect
This commit is contained in:
parent
a782f817f1
commit
4108e7fdcf
7 changed files with 57 additions and 32 deletions
|
@ -24,6 +24,9 @@ type Props = {
|
||||||
stretch?: boolean,
|
stretch?: boolean,
|
||||||
affixClass?: string, // class applied to prefix/postfix label
|
affixClass?: string, // class applied to prefix/postfix label
|
||||||
firstInList?: boolean, // at the top of a list, no padding top
|
firstInList?: boolean, // at the top of a list, no padding top
|
||||||
|
inputProps: {
|
||||||
|
disabled?: boolean,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export class FormField extends React.PureComponent<Props> {
|
export class FormField extends React.PureComponent<Props> {
|
||||||
|
@ -76,8 +79,8 @@ export class FormField extends React.PureComponent<Props> {
|
||||||
);
|
);
|
||||||
} else if (type === 'textarea') {
|
} else if (type === 'textarea') {
|
||||||
input = <textarea type={type} id={name} {...inputProps} />;
|
input = <textarea type={type} id={name} {...inputProps} />;
|
||||||
// } else if (type === 'checkbox') {
|
} else if (type === 'checkbox') {
|
||||||
// input = <Toggle id={name} {...inputProps} />;
|
input = <Toggle id={name} {...inputProps} />;
|
||||||
} else {
|
} else {
|
||||||
input = <input type={type} id={name} {...inputProps} />;
|
input = <input type={type} id={name} {...inputProps} />;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ type Props = {
|
||||||
verticallyCentered?: boolean,
|
verticallyCentered?: boolean,
|
||||||
stretch?: boolean,
|
stretch?: boolean,
|
||||||
alignRight?: boolean,
|
alignRight?: boolean,
|
||||||
|
centered?: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
export class FormRow extends React.PureComponent<Props> {
|
export class FormRow extends React.PureComponent<Props> {
|
||||||
|
@ -17,7 +18,7 @@ export class FormRow extends React.PureComponent<Props> {
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { children, padded, verticallyCentered, stretch, alignRight } = this.props;
|
const { children, padded, verticallyCentered, stretch, alignRight, centered } = this.props;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classnames('form-row', {
|
className={classnames('form-row', {
|
||||||
|
@ -25,6 +26,7 @@ export class FormRow extends React.PureComponent<Props> {
|
||||||
'form-row--vertically-centered': verticallyCentered,
|
'form-row--vertically-centered': verticallyCentered,
|
||||||
'form-row--stretch': stretch,
|
'form-row--stretch': stretch,
|
||||||
'form-row--right': alignRight,
|
'form-row--right': alignRight,
|
||||||
|
'form-row--centered': centered,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import * as React from 'react';
|
||||||
import FileCard from 'component/fileCard';
|
|
||||||
import Page from 'component/page';
|
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
import { FormField, FormRow } from 'component/common/form';
|
import { FormField, FormRow } from 'component/common/form';
|
||||||
import ReactPaginate from 'react-paginate';
|
import ReactPaginate from 'react-paginate';
|
||||||
|
@ -16,11 +14,16 @@ type Props = {
|
||||||
history: Array<HistoryItem>,
|
history: Array<HistoryItem>,
|
||||||
page: number,
|
page: number,
|
||||||
pageCount: number,
|
pageCount: number,
|
||||||
navigate: string => void,
|
navigate: (string, {}) => void,
|
||||||
|
clearHistoryUri: string => void,
|
||||||
params: { page: number },
|
params: { page: number },
|
||||||
};
|
};
|
||||||
|
|
||||||
class UserHistoryPage extends React.PureComponent<Props> {
|
type State = {
|
||||||
|
itemsSelected: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
class UserHistoryPage extends React.PureComponent<Props, State> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
@ -28,9 +31,24 @@ class UserHistoryPage extends React.PureComponent<Props> {
|
||||||
itemsSelected: {},
|
itemsSelected: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
this.selectAll = this.selectAll.bind(this);
|
(this: any).selectAll = this.selectAll.bind(this);
|
||||||
this.unselectAll = this.unselectAll.bind(this);
|
(this: any).unselectAll = this.unselectAll.bind(this);
|
||||||
this.removeSelected = this.removeSelected.bind(this);
|
(this: any).removeSelected = this.removeSelected.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelect(uri: string) {
|
||||||
|
const { itemsSelected } = this.state;
|
||||||
|
|
||||||
|
const newItemsSelected = { ...itemsSelected };
|
||||||
|
if (itemsSelected[uri]) {
|
||||||
|
delete newItemsSelected[uri];
|
||||||
|
} else {
|
||||||
|
newItemsSelected[uri] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
itemsSelected: { ...newItemsSelected },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
changePage(pageNumber: number) {
|
changePage(pageNumber: number) {
|
||||||
|
@ -52,12 +70,6 @@ class UserHistoryPage extends React.PureComponent<Props> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelect(uri: string) {
|
|
||||||
this.setState({
|
|
||||||
itemsSelected: { ...this.state.itemsSelected, [uri]: !this.state.itemsSelected[uri] },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
selectAll() {
|
selectAll() {
|
||||||
const { history } = this.props;
|
const { history } = this.props;
|
||||||
const newSelectedState = {};
|
const newSelectedState = {};
|
||||||
|
@ -82,7 +94,7 @@ class UserHistoryPage extends React.PureComponent<Props> {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { history, page, pageCount, navigate } = this.props;
|
const { history, page, pageCount } = this.props;
|
||||||
const { itemsSelected } = this.state;
|
const { itemsSelected } = this.state;
|
||||||
|
|
||||||
const allSelected = Object.keys(itemsSelected).length === history.length;
|
const allSelected = Object.keys(itemsSelected).length === history.length;
|
||||||
|
@ -90,10 +102,12 @@ class UserHistoryPage extends React.PureComponent<Props> {
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<div className="card__actions card__actions--between">
|
<div className="card__actions card__actions--between">
|
||||||
{!!Object.keys(itemsSelected).length ? (
|
{Object.keys(itemsSelected).length ? (
|
||||||
<Button button="link" label={__('Delete')} onClick={this.removeSelected} />
|
<Button button="link" label={__('Delete')} onClick={this.removeSelected} />
|
||||||
) : (
|
) : (
|
||||||
<span />
|
<span>
|
||||||
|
{/* Using an empty span so spacing stays the same if the button isn't rendered */}
|
||||||
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
@ -120,7 +134,7 @@ class UserHistoryPage extends React.PureComponent<Props> {
|
||||||
</table>
|
</table>
|
||||||
)}
|
)}
|
||||||
{pageCount > 1 && (
|
{pageCount > 1 && (
|
||||||
<FormRow verticallyCentered centered>
|
<FormRow padded verticallyCentered centered>
|
||||||
<ReactPaginate
|
<ReactPaginate
|
||||||
pageCount={pageCount}
|
pageCount={pageCount}
|
||||||
pageRangeDisplayed={2}
|
pageRangeDisplayed={2}
|
||||||
|
|
|
@ -3,13 +3,15 @@ import React from 'react';
|
||||||
import type { Claim } from 'types/claim';
|
import type { Claim } from 'types/claim';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import { FormRow, FormField } from 'component/common/form';
|
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
lastViewed: number,
|
lastViewed: number,
|
||||||
uri: string,
|
uri: string,
|
||||||
claim: ?{},
|
claim: ?Claim,
|
||||||
|
selected: boolean,
|
||||||
|
onSelect: () => void,
|
||||||
|
resolveUri: string => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
class UserHistoryItem extends React.PureComponent<Props> {
|
class UserHistoryItem extends React.PureComponent<Props> {
|
||||||
|
@ -27,7 +29,7 @@ class UserHistoryItem extends React.PureComponent<Props> {
|
||||||
let name;
|
let name;
|
||||||
let title;
|
let title;
|
||||||
let uri;
|
let uri;
|
||||||
if (claim) {
|
if (claim && claim.value && claim.value.stream) {
|
||||||
({ name } = claim);
|
({ name } = claim);
|
||||||
({ title } = claim.value.stream.metadata);
|
({ title } = claim.value.stream.metadata);
|
||||||
uri = claim.permanent_url;
|
uri = claim.permanent_url;
|
||||||
|
@ -44,16 +46,16 @@ class UserHistoryItem extends React.PureComponent<Props> {
|
||||||
<input checked={selected} type="checkbox" onClick={onSelect} />
|
<input checked={selected} type="checkbox" onClick={onSelect} />
|
||||||
</td>
|
</td>
|
||||||
<td>{moment(lastViewed).from(moment())}</td>
|
<td>{moment(lastViewed).from(moment())}</td>
|
||||||
|
<td>{title}</td>
|
||||||
<td>
|
<td>
|
||||||
<Button
|
<Button
|
||||||
tourniquet
|
tourniquet
|
||||||
button="link"
|
button="link"
|
||||||
label={`lbry://${name}`}
|
label={name ? `lbry://${name}` : `lbry://...`}
|
||||||
navigate="/show"
|
navigate="/show"
|
||||||
navigateParams={{ uri }}
|
navigateParams={{ uri }}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>{title}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
export const HISTORY_ITEMS_PER_PAGE = 30;
|
export const HISTORY_ITEMS_PER_PAGE = 50;
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.form-row--centered {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
&.form-row--stretch {
|
&.form-row--stretch {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,15 +133,15 @@ table.table--history {
|
||||||
width: 7.5%;
|
width: 7.5%;
|
||||||
}
|
}
|
||||||
td:nth-of-type(2) {
|
td:nth-of-type(2) {
|
||||||
width: 20%;
|
width: 17.5%;
|
||||||
}
|
}
|
||||||
td:nth-of-type(3) {
|
td:nth-of-type(3) {
|
||||||
width: 30%;
|
width: 40%;
|
||||||
padding-right: 10px;
|
max-width: 30vw;
|
||||||
|
padding-right: $spacing-vertical * 2/3;
|
||||||
}
|
}
|
||||||
td:nth-of-type(4) {
|
td:nth-of-type(4) {
|
||||||
width: 42.5%;
|
width: 30%;
|
||||||
max-width: 30vw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
td:nth-of-type(3),
|
td:nth-of-type(3),
|
||||||
|
|
Loading…
Add table
Reference in a new issue