mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Add getInitialState and source pattern for PieceStore
This commit is contained in:
parent
a5442e5acd
commit
7136f2ce6c
@ -1,28 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
import { alt } from '../alt';
|
||||
import PieceFetcher from '../fetchers/piece_fetcher';
|
||||
|
||||
|
||||
class PieceActions {
|
||||
constructor() {
|
||||
this.generateActions(
|
||||
'fetchPiece',
|
||||
'successFetchPiece',
|
||||
'errorPiece',
|
||||
'flushPiece',
|
||||
'updatePiece',
|
||||
'updateProperty',
|
||||
'pieceFailed'
|
||||
'updateProperty'
|
||||
);
|
||||
}
|
||||
|
||||
fetchOne(pieceId) {
|
||||
PieceFetcher.fetchOne(pieceId)
|
||||
.then((res) => {
|
||||
this.actions.updatePiece(res.piece);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.logGlobal(err);
|
||||
this.actions.pieceFailed(err.json);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default alt.createActions(PieceActions);
|
||||
|
@ -52,6 +52,7 @@ let EditionContainer = React.createClass({
|
||||
// button to update the URL parameter (and therefore to switch pieces)
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if(this.props.params.editionId !== nextProps.params.editionId) {
|
||||
EditionActions.flushEdition();
|
||||
this.loadEdition(nextProps.params.editionId);
|
||||
}
|
||||
},
|
||||
|
@ -28,7 +28,7 @@ let Piece = React.createClass({
|
||||
|
||||
|
||||
updateObject() {
|
||||
return PieceActions.fetchOne(this.props.piece.id);
|
||||
return PieceActions.fetchPiece(this.props.piece.id);
|
||||
},
|
||||
|
||||
render() {
|
||||
|
@ -69,7 +69,7 @@ let PieceContainer = React.createClass({
|
||||
return mergeOptions(
|
||||
UserStore.getState(),
|
||||
PieceListStore.getState(),
|
||||
PieceStore.getState(),
|
||||
PieceStore.getInitialState(),
|
||||
{
|
||||
showCreateEditionsDialog: false
|
||||
}
|
||||
@ -81,19 +81,24 @@ let PieceContainer = React.createClass({
|
||||
PieceListStore.listen(this.onChange);
|
||||
PieceStore.listen(this.onChange);
|
||||
|
||||
// Every time we enter the piece detail page, just reset the piece
|
||||
// store as it will otherwise display wrong/old data once the user loads
|
||||
// the piece detail a second time
|
||||
PieceActions.updatePiece({});
|
||||
|
||||
this.loadPiece();
|
||||
UserActions.fetchCurrentUser();
|
||||
},
|
||||
|
||||
componentDidUpdate() {
|
||||
const { pieceError } = this.state;
|
||||
// This is done to update the container when the user clicks on the prev or next
|
||||
// button to update the URL parameter (and therefore to switch pieces) or
|
||||
// when the user clicks on a notification while being in another piece view
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (this.props.params.pieceId !== nextProps.params.pieceId) {
|
||||
PieceActions.flushPiece();
|
||||
this.loadPiece(nextProps.params.pieceId);
|
||||
}
|
||||
},
|
||||
|
||||
if (pieceError && pieceError.status === 404) {
|
||||
componentDidUpdate() {
|
||||
const { pieceMeta: { err: pieceErr } } = this.state;
|
||||
|
||||
if (pieceErr && pieceErr.status === 404) {
|
||||
this.throws(new ResourceNotFoundError(getLangText("Oops, the piece you're looking for doesn't exist.")));
|
||||
}
|
||||
},
|
||||
@ -116,8 +121,7 @@ let PieceContainer = React.createClass({
|
||||
ALSO, WE ENABLED THE LOAN BUTTON FOR IKONOTV TO LET THEM LOAN ON A PIECE LEVEL
|
||||
|
||||
*/
|
||||
if(state && state.piece && state.piece.acl && typeof state.piece.acl.acl_loan !== 'undefined') {
|
||||
|
||||
if (state && state.piece && state.piece.acl && typeof state.piece.acl.acl_loan !== 'undefined') {
|
||||
let pieceState = mergeOptions({}, state.piece);
|
||||
pieceState.acl.acl_loan = false;
|
||||
this.setState({
|
||||
@ -129,11 +133,10 @@ let PieceContainer = React.createClass({
|
||||
}
|
||||
},
|
||||
|
||||
loadPiece() {
|
||||
PieceActions.fetchOne(this.props.params.pieceId);
|
||||
loadPiece(pieceId = this.props.params.pieceId) {
|
||||
PieceActions.fetchPiece(pieceId);
|
||||
},
|
||||
|
||||
|
||||
toggleCreateEditionsDialog() {
|
||||
this.setState({
|
||||
showCreateEditionsDialog: !this.state.showCreateEditionsDialog
|
||||
@ -141,7 +144,7 @@ let PieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
handleEditionCreationSuccess() {
|
||||
PieceActions.updateProperty({key: 'num_editions', value: 0});
|
||||
PieceActions.updateProperty({ key: 'num_editions', value: 0 });
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
this.toggleCreateEditionsDialog();
|
||||
@ -156,29 +159,28 @@ let PieceContainer = React.createClass({
|
||||
EditionListActions.closeAllEditionLists();
|
||||
EditionListActions.clearAllEditionSelections();
|
||||
|
||||
let notification = new GlobalNotificationModel(response.notification, 'success');
|
||||
const notification = new GlobalNotificationModel(response.notification, 'success');
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
||||
this.history.push('/collection');
|
||||
},
|
||||
|
||||
getCreateEditionsDialog() {
|
||||
if(this.state.piece.num_editions < 1 && this.state.showCreateEditionsDialog) {
|
||||
if (this.state.piece.num_editions < 1 && this.state.showCreateEditionsDialog) {
|
||||
return (
|
||||
<div style={{marginTop: '1em'}}>
|
||||
<CreateEditionsForm
|
||||
pieceId={this.state.piece.id}
|
||||
handleSuccess={this.handleEditionCreationSuccess} />
|
||||
<hr/>
|
||||
<hr />
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (<hr/>);
|
||||
return (<hr />);
|
||||
}
|
||||
},
|
||||
|
||||
handlePollingSuccess(pieceId, numEditions) {
|
||||
|
||||
// we need to refresh the num_editions property of the actual piece we're looking at
|
||||
PieceActions.updateProperty({
|
||||
key: 'num_editions',
|
||||
@ -192,24 +194,24 @@ let PieceContainer = React.createClass({
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
|
||||
let notification = new GlobalNotificationModel('Editions successfully created', 'success', 10000);
|
||||
const notification = new GlobalNotificationModel('Editions successfully created', 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
},
|
||||
|
||||
getId() {
|
||||
return {'id': this.state.piece.id};
|
||||
return { 'id': this.state.piece.id };
|
||||
},
|
||||
|
||||
getActions() {
|
||||
const { piece, currentUser } = this.state;
|
||||
|
||||
if (piece && piece.notifications && piece.notifications.length > 0) {
|
||||
if (piece.notifications && piece.notifications.length > 0) {
|
||||
return (
|
||||
<ListRequestActions
|
||||
pieceOrEditions={piece}
|
||||
currentUser={currentUser}
|
||||
handleSuccess={this.loadPiece}
|
||||
notifications={piece.notifications}/>);
|
||||
notifications={piece.notifications} />);
|
||||
} else {
|
||||
return (
|
||||
<AclProxy
|
||||
@ -235,12 +237,12 @@ let PieceContainer = React.createClass({
|
||||
onPollingSuccess={this.handlePollingSuccess}/>
|
||||
<DeleteButton
|
||||
handleSuccess={this.handleDeleteSuccess}
|
||||
piece={piece}/>
|
||||
piece={piece} />
|
||||
<AclInformation
|
||||
aim="button"
|
||||
verbs={['acl_share', 'acl_transfer', 'acl_create_editions', 'acl_loan', 'acl_delete',
|
||||
'acl_consign']}
|
||||
aclObject={piece.acl}/>
|
||||
aclObject={piece.acl} />
|
||||
</AclButtonList>
|
||||
</DetailProperty>
|
||||
</AclProxy>
|
||||
@ -252,7 +254,7 @@ let PieceContainer = React.createClass({
|
||||
const { furtherDetailsType: FurtherDetailsType } = this.props;
|
||||
const { currentUser, piece } = this.state;
|
||||
|
||||
if (piece && piece.id) {
|
||||
if (piece.id) {
|
||||
setDocumentTitle([piece.artist_name, piece.title].join(', '));
|
||||
|
||||
return (
|
||||
@ -296,7 +298,7 @@ let PieceContainer = React.createClass({
|
||||
editable={true}
|
||||
successMessage={getLangText('Private note saved')}
|
||||
url={ApiUrls.note_private_piece}
|
||||
currentUser={currentUser}/>
|
||||
currentUser={currentUser} />
|
||||
<Note
|
||||
id={this.getId}
|
||||
label={getLangText('Personal note (public)')}
|
||||
@ -306,7 +308,7 @@ let PieceContainer = React.createClass({
|
||||
show={!!(piece.public_note || piece.acl.acl_edit)}
|
||||
successMessage={getLangText('Public note saved')}
|
||||
url={ApiUrls.note_public_piece}
|
||||
currentUser={currentUser}/>
|
||||
currentUser={currentUser} />
|
||||
</CollapsibleParagraph>
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Further Details')}
|
||||
|
@ -60,16 +60,10 @@ let PrizePieceContainer = React.createClass({
|
||||
mixins: [ReactError],
|
||||
|
||||
getInitialState() {
|
||||
//FIXME: this component uses the PieceStore, but we avoid using the getState() here since it may contain stale data
|
||||
// It should instead use something like getInitialState() where that call also resets the state.
|
||||
return UserStore.getState();
|
||||
},
|
||||
|
||||
componentWillMount() {
|
||||
// Every time we enter the piece detail page, just reset the piece
|
||||
// store as it will otherwise display wrong/old data once the user loads
|
||||
// the piece detail a second time
|
||||
PieceActions.updatePiece({});
|
||||
return mergeOptions(
|
||||
PieceStore.getInitialState(),
|
||||
UserStore.getState()
|
||||
);
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
@ -81,18 +75,19 @@ let PrizePieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
// This is done to update the container when the user clicks on the prev or next
|
||||
// button to update the URL parameter (and therefore to switch pieces)
|
||||
// button to update the URL parameter (and therefore to switch pieces) or
|
||||
// when the user clicks on a notification while being in another piece view
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (this.props.params.pieceId !== nextProps.params.pieceId) {
|
||||
PieceActions.updatePiece({});
|
||||
PieceActions.flushPiece();
|
||||
this.loadPiece(nextProps.params.pieceId);
|
||||
}
|
||||
},
|
||||
|
||||
componentDidUpdate() {
|
||||
const { pieceError } = this.state;
|
||||
const { pieceMeta: { err: pieceErr } } = this.state;
|
||||
|
||||
if (pieceError && pieceError.status === 404) {
|
||||
if (pieceErr && pieceErr.status === 404) {
|
||||
this.throws(new ResourceNotFoundError(getLangText("Oops, the piece you're looking for doesn't exist.")));
|
||||
}
|
||||
},
|
||||
@ -109,25 +104,25 @@ let PrizePieceContainer = React.createClass({
|
||||
getActions() {
|
||||
const { currentUser, piece } = this.state;
|
||||
|
||||
if (piece && piece.notifications && piece.notifications.length > 0) {
|
||||
if (piece.notifications && piece.notifications.length > 0) {
|
||||
return (
|
||||
<ListRequestActions
|
||||
pieceOrEditions={piece}
|
||||
currentUser={currentUser}
|
||||
handleSuccess={this.loadPiece}
|
||||
notifications={piece.notifications}/>);
|
||||
notifications={piece.notifications} />);
|
||||
}
|
||||
},
|
||||
|
||||
loadPiece(pieceId = this.props.params.pieceId) {
|
||||
PieceActions.fetchOne(pieceId);
|
||||
PieceActions.fetchPiece(pieceId);
|
||||
},
|
||||
|
||||
render() {
|
||||
const { selectedPrizeActionButton } = this.props;
|
||||
const { currentUser, piece } = this.state;
|
||||
|
||||
if (piece && piece.id) {
|
||||
if (piece.id) {
|
||||
/*
|
||||
|
||||
This really needs a refactor!
|
||||
@ -138,7 +133,7 @@ let PrizePieceContainer = React.createClass({
|
||||
// Only show the artist name if you are the participant or if you are a judge and the piece is shortlisted
|
||||
let artistName;
|
||||
if ((currentUser.is_jury && !currentUser.is_judge) || (currentUser.is_judge && !piece.selected )) {
|
||||
artistName = <span className="glyphicon glyphicon-eye-close" aria-hidden="true"/>;
|
||||
artistName = <span className="glyphicon glyphicon-eye-close" aria-hidden="true" />;
|
||||
setDocumentTitle(piece.title);
|
||||
} else {
|
||||
artistName = piece.artist_name;
|
||||
@ -146,8 +141,11 @@ let PrizePieceContainer = React.createClass({
|
||||
}
|
||||
|
||||
// Only show the artist email if you are a judge and the piece is shortlisted
|
||||
const artistEmail = (currentUser.is_judge && piece.selected ) ?
|
||||
<DetailProperty label={getLangText('REGISTREE')} value={ piece.user_registered } /> : null;
|
||||
const artistEmail = (currentUser.is_judge && piece.selected ) ? (
|
||||
<DetailProperty
|
||||
label={getLangText('REGISTREE')}
|
||||
value={piece.user_registered} />
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<Piece
|
||||
@ -157,16 +155,16 @@ let PrizePieceContainer = React.createClass({
|
||||
<div className="ascribe-detail-header">
|
||||
<NavigationHeader
|
||||
piece={piece}
|
||||
currentUser={currentUser}/>
|
||||
currentUser={currentUser} />
|
||||
|
||||
<h1 className="ascribe-detail-title">{piece.title}</h1>
|
||||
<DetailProperty label={getLangText('BY')} value={artistName} />
|
||||
<DetailProperty label={getLangText('DATE')} value={Moment(piece.date_created, 'YYYY-MM-DD').year()} />
|
||||
{artistEmail}
|
||||
{this.getActions()}
|
||||
<hr/>
|
||||
<hr />
|
||||
</div>
|
||||
}
|
||||
}
|
||||
subheader={
|
||||
<PrizePieceRatings
|
||||
loadPiece={this.loadPiece}
|
||||
@ -196,9 +194,8 @@ let NavigationHeader = React.createClass({
|
||||
render() {
|
||||
const { currentUser, piece } = this.props;
|
||||
|
||||
if (currentUser && currentUser.email && currentUser.is_judge && currentUser.is_jury &&
|
||||
!currentUser.is_admin && piece && piece.navigation) {
|
||||
let nav = piece.navigation;
|
||||
if (currentUser.email && currentUser.is_judge && currentUser.is_jury && !currentUser.is_admin && piece.navigation) {
|
||||
const nav = piece.navigation;
|
||||
|
||||
return (
|
||||
<div style={{marginBottom: '1em'}}>
|
||||
@ -218,8 +215,9 @@ let NavigationHeader = React.createClass({
|
||||
<hr/>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@ -322,7 +320,7 @@ let PrizePieceRatings = React.createClass({
|
||||
},
|
||||
|
||||
render() {
|
||||
if (this.props.piece && this.props.currentUser && this.props.currentUser.is_judge && this.state.average) {
|
||||
if (this.props.piece.id && this.props.currentUser.is_judge && this.state.average) {
|
||||
// Judge sees shortlisting, average and per-jury notes
|
||||
return (
|
||||
<div>
|
||||
@ -354,7 +352,7 @@ let PrizePieceRatings = React.createClass({
|
||||
size='md'
|
||||
step={0.5}
|
||||
rating={this.state.average}
|
||||
ratingAmount={5}/>
|
||||
ratingAmount={5} />
|
||||
</div>
|
||||
<hr />
|
||||
{this.state.ratings.map((item, i) => {
|
||||
@ -379,7 +377,7 @@ let PrizePieceRatings = React.createClass({
|
||||
size='sm'
|
||||
step={0.5}
|
||||
rating={item.rating}
|
||||
ratingAmount={5}/>
|
||||
ratingAmount={5} />
|
||||
</span>
|
||||
<span> {item.user}</span>
|
||||
{note}
|
||||
@ -390,7 +388,7 @@ let PrizePieceRatings = React.createClass({
|
||||
<hr />
|
||||
</CollapsibleParagraph>
|
||||
</div>);
|
||||
} else if (this.props.currentUser && this.props.currentUser.is_jury) {
|
||||
} else if (this.props.currentUser.is_jury) {
|
||||
// Jury can set rating and note
|
||||
return (
|
||||
<CollapsibleParagraph
|
||||
@ -408,14 +406,14 @@ let PrizePieceRatings = React.createClass({
|
||||
ratingAmount={5} />
|
||||
</div>
|
||||
<Note
|
||||
id={() => {return {'piece_id': this.props.piece.id}; }}
|
||||
id={() => { return { 'piece_id': this.props.piece.id }; }}
|
||||
label={getLangText('Jury note')}
|
||||
defaultValue={this.props.piece && this.props.piece.note_from_user ? this.props.piece.note_from_user.note : null}
|
||||
defaultValue={this.props.piece.note_from_user || null}
|
||||
placeholder={getLangText('Enter your comments ...')}
|
||||
editable={true}
|
||||
successMessage={getLangText('Jury note saved')}
|
||||
url={ApiUrls.notes}
|
||||
currentUser={this.props.currentUser}/>
|
||||
currentUser={this.props.currentUser} />
|
||||
</CollapsibleParagraph>);
|
||||
} else {
|
||||
return null;
|
||||
@ -432,33 +430,34 @@ let PrizePieceDetails = React.createClass({
|
||||
render() {
|
||||
const { piece } = this.props;
|
||||
|
||||
if (piece &&
|
||||
piece.prize &&
|
||||
piece.prize.name &&
|
||||
Object.keys(piece.extra_data).length !== 0) {
|
||||
if (piece.prize && piece.prize.name && Object.keys(piece.extra_data).length) {
|
||||
return (
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Prize Details')}
|
||||
defaultExpanded={true}>
|
||||
<Form ref='form'>
|
||||
{Object.keys(piece.extra_data).sort().map((data) => {
|
||||
// Remove leading number (for sorting), if any, and underscores with spaces
|
||||
let label = data.replace(/^\d-/, '').replace(/_/g, ' ');
|
||||
const value = piece.extra_data[data] || 'N/A';
|
||||
<Form>
|
||||
{Object
|
||||
.keys(piece.extra_data)
|
||||
.sort()
|
||||
.map((data) => {
|
||||
// Remove leading number (for sorting), if any, and underscores with spaces
|
||||
const label = data.replace(/^\d-/, '').replace(/_/g, ' ');
|
||||
const value = piece.extra_data[data] || 'N/A';
|
||||
|
||||
return (
|
||||
<Property
|
||||
key={label}
|
||||
name={data}
|
||||
label={label}
|
||||
editable={false}
|
||||
overrideForm={true}>
|
||||
<InputTextAreaToggable
|
||||
rows={1}
|
||||
defaultValue={value}/>
|
||||
</Property>
|
||||
);
|
||||
})}
|
||||
return (
|
||||
<Property
|
||||
key={label}
|
||||
name={data}
|
||||
label={label}
|
||||
editable={false}
|
||||
overrideForm={true}>
|
||||
<InputTextAreaToggable
|
||||
rows={1}
|
||||
defaultValue={value} />
|
||||
</Property>
|
||||
);
|
||||
})
|
||||
}
|
||||
<FurtherDetailsFileuploader
|
||||
submitFile={() => {}}
|
||||
setIsUploadReady={() => {}}
|
||||
@ -471,8 +470,9 @@ let PrizePieceDetails = React.createClass({
|
||||
</Form>
|
||||
</CollapsibleParagraph>
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -40,7 +40,7 @@ let CylandPieceContainer = React.createClass({
|
||||
|
||||
getInitialState() {
|
||||
return mergeOptions(
|
||||
PieceStore.getState(),
|
||||
PieceStore.getInitialState(),
|
||||
UserStore.getState(),
|
||||
PieceListStore.getState()
|
||||
);
|
||||
@ -51,14 +51,17 @@ let CylandPieceContainer = React.createClass({
|
||||
UserStore.listen(this.onChange);
|
||||
PieceListStore.listen(this.onChange);
|
||||
|
||||
// Every time we enter the piece detail page, just reset the piece
|
||||
// store as it will otherwise display wrong/old data once the user loads
|
||||
// the piece detail a second time
|
||||
PieceActions.updatePiece({});
|
||||
|
||||
this.loadPiece();
|
||||
},
|
||||
|
||||
// We need this for when the user clicks on a notification while being in another piece view
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (this.props.params.pieceId !== nextProps.params.pieceId) {
|
||||
PieceActions.flushPiece();
|
||||
this.loadPiece();
|
||||
}
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
PieceStore.unlisten(this.onChange);
|
||||
UserStore.unlisten(this.onChange);
|
||||
@ -70,7 +73,7 @@ let CylandPieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
loadPiece() {
|
||||
PieceActions.fetchOne(this.props.params.pieceId);
|
||||
PieceActions.fetchPiece(this.props.params.pieceId);
|
||||
},
|
||||
|
||||
handleDeleteSuccess(response) {
|
||||
@ -82,19 +85,21 @@ let CylandPieceContainer = React.createClass({
|
||||
EditionListActions.closeAllEditionLists();
|
||||
EditionListActions.clearAllEditionSelections();
|
||||
|
||||
let notification = new GlobalNotificationModel(response.notification, 'success');
|
||||
const notification = new GlobalNotificationModel(response.notification, 'success');
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
||||
this.history.push('/collection');
|
||||
},
|
||||
|
||||
render() {
|
||||
if(this.state.piece && this.state.piece.id) {
|
||||
setDocumentTitle([this.state.piece.artist_name, this.state.piece.title].join(', '));
|
||||
const { piece } = this.state;
|
||||
|
||||
if (piece.id) {
|
||||
setDocumentTitle([piece.artist_name, piece.title].join(', '));
|
||||
|
||||
return (
|
||||
<WalletPieceContainer
|
||||
piece={this.state.piece}
|
||||
piece={piece}
|
||||
currentUser={this.state.currentUser}
|
||||
loadPiece={this.loadPiece}
|
||||
handleDeleteSuccess={this.handleDeleteSuccess}
|
||||
@ -103,14 +108,13 @@ let CylandPieceContainer = React.createClass({
|
||||
title={getLangText('Further Details')}
|
||||
defaultExpanded={true}>
|
||||
<CylandAdditionalDataForm
|
||||
piece={this.state.piece}
|
||||
disabled={!this.state.piece.acl.acl_edit}
|
||||
piece={piece}
|
||||
disabled={!piece.acl.acl_edit}
|
||||
isInline={true} />
|
||||
</CollapsibleParagraph>
|
||||
</WalletPieceContainer>
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return (
|
||||
<div className="fullpage-spinner">
|
||||
<AscribeSpinner color='dark-blue' size='lg' />
|
||||
|
@ -52,7 +52,7 @@ let CylandRegisterPiece = React.createClass({
|
||||
return mergeOptions(
|
||||
UserStore.getState(),
|
||||
PieceListStore.getState(),
|
||||
PieceStore.getState(),
|
||||
PieceStore.getInitialState(),
|
||||
WhitelabelStore.getState(),
|
||||
{
|
||||
step: 0
|
||||
@ -67,7 +67,7 @@ let CylandRegisterPiece = React.createClass({
|
||||
UserActions.fetchCurrentUser();
|
||||
WhitelabelActions.fetchWhitelabel();
|
||||
|
||||
let queryParams = this.props.location.query;
|
||||
const queryParams = this.props.location.query;
|
||||
|
||||
// Since every step of this register process is atomic,
|
||||
// we may need to enter the process at step 1 or 2.
|
||||
@ -76,8 +76,8 @@ let CylandRegisterPiece = React.createClass({
|
||||
//
|
||||
// We're using 'in' here as we want to know if 'piece_id' is present in the url,
|
||||
// we don't care about the value.
|
||||
if(queryParams && 'piece_id' in queryParams) {
|
||||
PieceActions.fetchOne(queryParams.piece_id);
|
||||
if ('piece_id' in queryParams) {
|
||||
PieceActions.fetchPiece(queryParams.piece_id);
|
||||
}
|
||||
},
|
||||
|
||||
@ -92,53 +92,44 @@ let CylandRegisterPiece = React.createClass({
|
||||
this.setState(state);
|
||||
},
|
||||
|
||||
handleRegisterSuccess(response){
|
||||
|
||||
handleRegisterSuccess(response) {
|
||||
this.refreshPieceList();
|
||||
|
||||
// also start loading the piece for the next step
|
||||
if(response && response.piece) {
|
||||
PieceActions.updatePiece({});
|
||||
// Also load the newly registered piece for the next step
|
||||
if (response && response.piece) {
|
||||
PieceActions.updatePiece(response.piece);
|
||||
}
|
||||
|
||||
this.incrementStep();
|
||||
|
||||
this.refs.slidesContainer.nextSlide({ piece_id: response.piece.id });
|
||||
this.nextSlide({ piece_id: response.piece.id });
|
||||
},
|
||||
|
||||
handleAdditionalDataSuccess() {
|
||||
|
||||
// We need to refetch the piece again after submitting the additional data
|
||||
// since we want it's otherData to be displayed when the user choses to click
|
||||
// since we want its otherData to be displayed when the user choses to click
|
||||
// on the browsers back button.
|
||||
PieceActions.fetchOne(this.state.piece.id);
|
||||
PieceActions.fetchPiece(this.state.piece.id);
|
||||
|
||||
this.refreshPieceList();
|
||||
|
||||
this.incrementStep();
|
||||
|
||||
this.refs.slidesContainer.nextSlide();
|
||||
this.nextSlide();
|
||||
},
|
||||
|
||||
handleLoanSuccess(response) {
|
||||
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
const notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
||||
this.refreshPieceList();
|
||||
|
||||
PieceActions.fetchOne(this.state.piece.id);
|
||||
|
||||
this.history.push(`/pieces/${this.state.piece.id}`);
|
||||
},
|
||||
|
||||
// We need to increase the step to lock the forms that are already filled out
|
||||
incrementStep() {
|
||||
// also increase step
|
||||
let newStep = this.state.step + 1;
|
||||
nextSlide(queryParams) {
|
||||
// We need to increase the step to lock the forms that are already filled out
|
||||
this.setState({
|
||||
step: newStep
|
||||
step: this.state.step + 1
|
||||
});
|
||||
|
||||
this.refs.slidesContainer.nextSlide(queryParams);
|
||||
},
|
||||
|
||||
refreshPieceList() {
|
||||
@ -157,8 +148,7 @@ let CylandRegisterPiece = React.createClass({
|
||||
const { currentUser, piece, step, whitelabel } = this.state;
|
||||
|
||||
const today = new Moment();
|
||||
const datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain = new Moment();
|
||||
datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain.add(1000, 'years');
|
||||
const datetimeWhenWeAllWillBeFlyingCoolHoverboardsAndDinosaursWillLiveAgain = new Moment().add(1000, 'years');
|
||||
|
||||
const loanHeading = getLangText('Loan to Cyland archive');
|
||||
const loanButtons = (
|
||||
@ -201,7 +191,7 @@ let CylandRegisterPiece = React.createClass({
|
||||
submitMessage={getLangText('Submit')}
|
||||
isFineUploaderActive={true}
|
||||
handleSuccess={this.handleRegisterSuccess}
|
||||
location={location}/>
|
||||
location={location} />
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
|
@ -41,7 +41,7 @@ let IkonotvPieceContainer = React.createClass({
|
||||
|
||||
getInitialState() {
|
||||
return mergeOptions(
|
||||
PieceStore.getState(),
|
||||
PieceStore.getInitialState(),
|
||||
UserStore.getState(),
|
||||
PieceListStore.getState()
|
||||
);
|
||||
@ -52,19 +52,14 @@ let IkonotvPieceContainer = React.createClass({
|
||||
UserStore.listen(this.onChange);
|
||||
PieceListStore.listen(this.onChange);
|
||||
|
||||
// Every time we enter the piece detail page, just reset the piece
|
||||
// store as it will otherwise display wrong/old data once the user loads
|
||||
// the piece detail a second time
|
||||
PieceActions.updatePiece({});
|
||||
|
||||
this.loadPiece();
|
||||
},
|
||||
|
||||
// We need this for when the user clicks on a notification while being in another piece view
|
||||
// We need this for when the user clicks on a notification while being in another piece view
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if(this.props.params.pieceId !== nextProps.params.pieceId) {
|
||||
PieceActions.updatePiece({});
|
||||
PieceActions.fetchOne(nextProps.params.pieceId);
|
||||
if (this.props.params.pieceId !== nextProps.params.pieceId) {
|
||||
PieceActions.flushPiece();
|
||||
this.loadPiece();
|
||||
}
|
||||
},
|
||||
|
||||
@ -79,7 +74,7 @@ let IkonotvPieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
loadPiece() {
|
||||
PieceActions.fetchOne(this.props.params.pieceId);
|
||||
PieceActions.fetchPiece(this.props.params.pieceId);
|
||||
},
|
||||
|
||||
handleDeleteSuccess(response) {
|
||||
@ -91,13 +86,15 @@ let IkonotvPieceContainer = React.createClass({
|
||||
EditionListActions.closeAllEditionLists();
|
||||
EditionListActions.clearAllEditionSelections();
|
||||
|
||||
let notification = new GlobalNotificationModel(response.notification, 'success');
|
||||
const notification = new GlobalNotificationModel(response.notification, 'success');
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
||||
this.history.push('/collection');
|
||||
},
|
||||
|
||||
render() {
|
||||
const { piece } = this.state;
|
||||
|
||||
let furtherDetails = (
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Further Details')}
|
||||
@ -106,28 +103,28 @@ let IkonotvPieceContainer = React.createClass({
|
||||
</CollapsibleParagraph>
|
||||
);
|
||||
|
||||
if(this.state.piece.extra_data && Object.keys(this.state.piece.extra_data).length > 0 && this.state.piece.acl) {
|
||||
if (piece.extra_data && Object.keys(piece.extra_data).length && piece.acl) {
|
||||
furtherDetails = (
|
||||
<CollapsibleParagraph
|
||||
title={getLangText('Further Details')}
|
||||
defaultExpanded={true}>
|
||||
<IkonotvArtistDetailsForm
|
||||
piece={this.state.piece}
|
||||
piece={piece}
|
||||
isInline={true}
|
||||
disabled={!this.state.piece.acl.acl_edit} />
|
||||
disabled={!piece.acl.acl_edit} />
|
||||
<IkonotvArtworkDetailsForm
|
||||
piece={this.state.piece}
|
||||
piece={piece}
|
||||
isInline={true}
|
||||
disabled={!this.state.piece.acl.acl_edit} />
|
||||
disabled={!piece.acl.acl_edit} />
|
||||
</CollapsibleParagraph>
|
||||
);
|
||||
}
|
||||
|
||||
if(this.state.piece && this.state.piece.id) {
|
||||
setDocumentTitle([this.state.piece.artist_name, this.state.piece.title].join(', '));
|
||||
if (piece.id) {
|
||||
setDocumentTitle([piece.artist_name, piece.title].join(', '));
|
||||
return (
|
||||
<WalletPieceContainer
|
||||
piece={this.state.piece}
|
||||
piece={piece}
|
||||
currentUser={this.state.currentUser}
|
||||
loadPiece={this.loadPiece}
|
||||
handleDeleteSuccess={this.handleDeleteSuccess}
|
||||
@ -135,8 +132,7 @@ let IkonotvPieceContainer = React.createClass({
|
||||
{furtherDetails}
|
||||
</WalletPieceContainer>
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return (
|
||||
<div className="fullpage-spinner">
|
||||
<AscribeSpinner color='dark-blue' size='lg' />
|
||||
|
@ -49,7 +49,7 @@ let IkonotvRegisterPiece = React.createClass({
|
||||
return mergeOptions(
|
||||
UserStore.getState(),
|
||||
PieceListStore.getState(),
|
||||
PieceStore.getState(),
|
||||
PieceStore.getInitialState(),
|
||||
WhitelabelStore.getState(),
|
||||
{
|
||||
step: 0,
|
||||
@ -65,11 +65,7 @@ let IkonotvRegisterPiece = React.createClass({
|
||||
UserActions.fetchCurrentUser();
|
||||
WhitelabelActions.fetchWhitelabel();
|
||||
|
||||
// Before we load the new piece, we reset the piece store to delete old data that we do
|
||||
// not want to display to the user.
|
||||
PieceActions.updatePiece({});
|
||||
|
||||
let queryParams = this.props.location.query;
|
||||
const queryParams = this.props.location.query;
|
||||
|
||||
// Since every step of this register process is atomic,
|
||||
// we may need to enter the process at step 1 or 2.
|
||||
@ -78,8 +74,8 @@ let IkonotvRegisterPiece = React.createClass({
|
||||
//
|
||||
// We're using 'in' here as we want to know if 'piece_id' is present in the url,
|
||||
// we don't care about the value.
|
||||
if (queryParams && 'piece_id' in queryParams) {
|
||||
PieceActions.fetchOne(queryParams.piece_id);
|
||||
if ('piece_id' in queryParams) {
|
||||
PieceActions.fetchPiece(queryParams.piece_id);
|
||||
}
|
||||
},
|
||||
|
||||
@ -95,55 +91,50 @@ let IkonotvRegisterPiece = React.createClass({
|
||||
},
|
||||
|
||||
|
||||
handleRegisterSuccess(response){
|
||||
handleRegisterSuccess(response) {
|
||||
this.refreshPieceList();
|
||||
|
||||
// also start loading the piece for the next step
|
||||
if(response && response.piece) {
|
||||
// Also load the newly registered piece for the next step
|
||||
if (response && response.piece) {
|
||||
PieceActions.updatePiece(response.piece);
|
||||
}
|
||||
|
||||
if (!this.canSubmit()) {
|
||||
this.history.push('/collection');
|
||||
}
|
||||
else {
|
||||
this.incrementStep();
|
||||
this.refs.slidesContainer.nextSlide();
|
||||
} else {
|
||||
this.nextSlide({ piece_id: response.piece.id });
|
||||
}
|
||||
},
|
||||
|
||||
handleAdditionalDataSuccess() {
|
||||
|
||||
// We need to refetch the piece again after submitting the additional data
|
||||
// since we want it's otherData to be displayed when the user choses to click
|
||||
// on the browsers back button.
|
||||
PieceActions.fetchOne(this.state.piece.id);
|
||||
PieceActions.fetchPiece(this.state.piece.id);
|
||||
|
||||
this.refreshPieceList();
|
||||
|
||||
this.incrementStep();
|
||||
|
||||
this.refs.slidesContainer.nextSlide();
|
||||
this.nextSlide();
|
||||
},
|
||||
|
||||
handleLoanSuccess(response) {
|
||||
this.setState({ pageExitWarning: null });
|
||||
|
||||
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
const notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
||||
this.refreshPieceList();
|
||||
|
||||
PieceActions.fetchOne(this.state.piece.id);
|
||||
this.history.push(`/pieces/${this.state.piece.id}`);
|
||||
},
|
||||
|
||||
// We need to increase the step to lock the forms that are already filled out
|
||||
incrementStep() {
|
||||
// also increase step
|
||||
let newStep = this.state.step + 1;
|
||||
nextSlide(queryParams) {
|
||||
// We need to increase the step to lock the forms that are already filled out
|
||||
this.setState({
|
||||
step: newStep
|
||||
step: this.state.step + 1
|
||||
});
|
||||
|
||||
this.refs.slidesContainer.nextSlide(queryParams);
|
||||
},
|
||||
|
||||
refreshPieceList() {
|
||||
@ -160,7 +151,7 @@ let IkonotvRegisterPiece = React.createClass({
|
||||
canSubmit() {
|
||||
let currentUser = this.state.currentUser;
|
||||
let whitelabel = this.state.whitelabel;
|
||||
return currentUser && currentUser.acl && currentUser.acl.acl_wallet_submit && whitelabel && whitelabel.user;
|
||||
return currentUser.acl && currentUser.acl.acl_wallet_submit && whitelabel.user;
|
||||
},
|
||||
|
||||
getSlideArtistDetails() {
|
||||
@ -171,13 +162,14 @@ let IkonotvRegisterPiece = React.createClass({
|
||||
<Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}>
|
||||
<IkonotvArtistDetailsForm
|
||||
handleSuccess={this.handleAdditionalDataSuccess}
|
||||
piece={this.state.piece}/>
|
||||
piece={this.state.piece} />
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
getSlideArtworkDetails() {
|
||||
@ -188,21 +180,21 @@ let IkonotvRegisterPiece = React.createClass({
|
||||
<Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}>
|
||||
<IkonotvArtworkDetailsForm
|
||||
handleSuccess={this.handleAdditionalDataSuccess}
|
||||
piece={this.state.piece}/>
|
||||
piece={this.state.piece} />
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
getSlideLoan() {
|
||||
if (this.canSubmit()) {
|
||||
const { piece, whitelabel } = this.state;
|
||||
let today = new Moment();
|
||||
let endDate = new Moment();
|
||||
endDate.add(2, 'years');
|
||||
const today = new Moment();
|
||||
const endDate = new Moment().add(2, 'years');
|
||||
|
||||
return (
|
||||
<div data-slide-title={getLangText('Loan')}>
|
||||
@ -225,8 +217,9 @@ let IkonotvRegisterPiece = React.createClass({
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
render() {
|
||||
@ -252,7 +245,7 @@ let IkonotvRegisterPiece = React.createClass({
|
||||
submitMessage={getLangText('Register')}
|
||||
isFineUploaderActive={true}
|
||||
handleSuccess={this.handleRegisterSuccess}
|
||||
location={this.props.location}/>
|
||||
location={this.props.location} />
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
|
@ -84,7 +84,7 @@ let MarketSubmitButton = React.createClass({
|
||||
|
||||
handleAdditionalDataSuccess(pieceId) {
|
||||
// Fetch newly updated piece to update the views
|
||||
PieceActions.fetchOne(pieceId);
|
||||
PieceActions.fetchPiece(pieceId);
|
||||
|
||||
this.refs.consignModal.show();
|
||||
},
|
||||
|
@ -63,7 +63,7 @@ let MarketAdditionalDataForm = React.createClass({
|
||||
PieceStore.listen(this.onChange);
|
||||
|
||||
if (this.props.pieceId) {
|
||||
PieceActions.fetchOne(this.props.pieceId);
|
||||
PieceActions.fetchPiece(this.props.pieceId);
|
||||
}
|
||||
},
|
||||
|
||||
@ -115,7 +115,7 @@ let MarketAdditionalDataForm = React.createClass({
|
||||
this.props.handleSuccess();
|
||||
}
|
||||
|
||||
let notification = new GlobalNotificationModel(getLangText('Further details successfully updated'), 'success', 10000);
|
||||
const notification = new GlobalNotificationModel(getLangText('Further details successfully updated'), 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
},
|
||||
|
||||
@ -159,7 +159,7 @@ let MarketAdditionalDataForm = React.createClass({
|
||||
) : null;
|
||||
}
|
||||
|
||||
if (piece && piece.id) {
|
||||
if (piece.id) {
|
||||
return (
|
||||
<Form
|
||||
className="ascribe-form-bordered"
|
||||
|
@ -1,15 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
import requests from '../utils/requests';
|
||||
|
||||
|
||||
let PieceFetcher = {
|
||||
/**
|
||||
* Fetch a piece from the API.
|
||||
*/
|
||||
fetchOne(id) {
|
||||
return requests.get('piece', {'piece_id': id});
|
||||
}
|
||||
};
|
||||
|
||||
export default PieceFetcher;
|
19
js/sources/piece_source.js
Normal file
19
js/sources/piece_source.js
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
import requests from '../utils/requests';
|
||||
|
||||
import PieceActions from '../actions/edition_actions';
|
||||
|
||||
|
||||
const PieceSource = {
|
||||
lookupPiece: {
|
||||
remote(state) {
|
||||
return requests.get('piece', { piece_id: state.pieceMeta.idToFetch });
|
||||
},
|
||||
|
||||
success: PieceActions.successFetchPiece,
|
||||
error: PieceActions.errorPiece
|
||||
}
|
||||
};
|
||||
|
||||
export default PieceSource;
|
@ -1,32 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
import { alt } from '../alt';
|
||||
|
||||
import PieceActions from '../actions/piece_actions';
|
||||
|
||||
import PieceSource from '../sources/piece_source';
|
||||
|
||||
|
||||
class PieceStore {
|
||||
constructor() {
|
||||
this.piece = {};
|
||||
this.pieceError = null;
|
||||
this.getInitialState();
|
||||
|
||||
this.bindActions(PieceActions);
|
||||
this.registerAsync(PieceSource);
|
||||
this.exportPublicMethods({
|
||||
getInitialState: this.getInitialState.bind(this)
|
||||
});
|
||||
}
|
||||
|
||||
getInitialState() {
|
||||
this.piece = {};
|
||||
this.pieceMeta = {
|
||||
err: null,
|
||||
idToFetch: null
|
||||
};
|
||||
|
||||
return {
|
||||
piece: this.piece,
|
||||
pieceMeta: this.pieceMeta
|
||||
}
|
||||
}
|
||||
|
||||
onFetchPiece(idToFetch) {
|
||||
this.pieceMeta.idToFetch = idToFetch;
|
||||
|
||||
this.getInstance.lookupPiece();
|
||||
}
|
||||
|
||||
onSuccessFetchPiece({ piece }) {
|
||||
if (piece) {
|
||||
this.onUpdatePiece(piece);
|
||||
} else {
|
||||
this.pieceMeta.err = new Error('Problem fetching the piece');
|
||||
}
|
||||
}
|
||||
|
||||
onErrorPiece(err) {
|
||||
this.pieceMeta.err = err;
|
||||
}
|
||||
|
||||
onFlushPiece() {
|
||||
this.getInitialState();
|
||||
}
|
||||
|
||||
onUpdatePiece(piece) {
|
||||
this.piece = piece;
|
||||
this.pieceError = null;
|
||||
this.pieceMeta.err = null;
|
||||
this.pieceMeta.idToFetch = null;
|
||||
}
|
||||
|
||||
onUpdateProperty({key, value}) {
|
||||
onUpdateProperty({ key, value }) {
|
||||
if(this.piece && key in this.piece) {
|
||||
this.piece[key] = value;
|
||||
} else {
|
||||
throw new Error('There is no piece defined in PieceStore or the piece object does not have the property you\'re looking for.');
|
||||
}
|
||||
}
|
||||
|
||||
onPieceFailed(err) {
|
||||
this.pieceError = err;
|
||||
}
|
||||
}
|
||||
|
||||
export default alt.createStore(PieceStore, 'PieceStore');
|
||||
|
Loading…
Reference in New Issue
Block a user