1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/components/ascribe_detail/piece_container.js

86 lines
2.9 KiB
JavaScript
Raw Normal View History

2015-07-08 22:54:07 +02:00
'use strict';
import React from 'react';
import PieceActions from '../../actions/piece_actions';
import PieceStore from '../../stores/piece_store';
import Piece from './piece';
import CollapsibleParagraph from './../ascribe_collapsible/collapsible_paragraph';
import FurtherDetails from './further_details';
2015-07-08 22:54:07 +02:00
import AppConstants from '../../constants/application_constants';
2015-07-08 22:54:07 +02:00
/**
* This is the component that implements resource/data specific functionality
*/
let PieceContainer = React.createClass({
getInitialState() {
return PieceStore.getState();
},
onChange(state) {
this.setState(state);
2015-07-15 18:00:43 +02:00
if (!state.piece.digital_work) {
return;
}
let isEncoding = state.piece.digital_work.isEncoding;
if (state.piece.digital_work.mime === 'video' && typeof isEncoding === 'number' && isEncoding !== 100 && !this.state.timerId) {
2015-07-15 17:13:45 +02:00
let timerId = window.setInterval(() => PieceActions.fetchOne(this.props.params.pieceId), 10000);
this.setState({timerId: timerId});
}
2015-07-08 22:54:07 +02:00
},
componentDidMount() {
PieceStore.listen(this.onChange);
PieceActions.fetchOne(this.props.params.pieceId);
},
componentWillUnmount() {
// Every time we're leaving the piece detail page,
// just reset the piece that is saved in the piece store
// as it will otherwise display wrong/old data once the user loads
// the piece detail a second time
PieceActions.updatePiece({});
2015-07-15 17:13:45 +02:00
window.clearInterval(this.state.timerId);
2015-07-08 22:54:07 +02:00
PieceStore.unlisten(this.onChange);
},
loadPiece() {
PieceActions.fetchOne(this.props.params.pieceId);
},
render() {
if('title' in this.state.piece) {
return (
<Piece
piece={this.state.piece}
loadPiece={this.loadPiece}>
<CollapsibleParagraph
title="Further Details"
show={this.state.piece.acl.acl_edit
|| Object.keys(this.state.piece.extra_data).length > 0
|| this.state.piece.other_data !== null}
defaultExpanded={true}>
<FurtherDetails
editable={this.state.piece.acl.acl_edit}
pieceId={this.state.piece.id}
extraData={this.state.piece.extra_data}
otherData={this.state.piece.other_data}
handleSuccess={this.loadPiece}/>
</CollapsibleParagraph>
</Piece>
2015-07-08 22:54:07 +02:00
);
} else {
return (
2015-07-13 15:00:12 +02:00
<div className="fullpage-spinner">
<img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />
2015-07-13 15:00:12 +02:00
</div>
2015-07-08 22:54:07 +02:00
);
}
}
});
export default PieceContainer;