Advertisement
Guest User

FileIndividual.jsx

a guest
Aug 19th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2.  
  3. export default class FileIndividual extends Component {
  4.  
  5.   propTypes: {
  6.     fileName: React.PropTypes.string.isRequired,
  7.     fileSize: React.PropTypes.number.isRequired,
  8.     fileUrl: React.PropTypes.string,
  9.     fileId: React.PropTypes.string.isRequired
  10.   }
  11.  
  12.   removeFile = () => {
  13.     "use strict";
  14.     let conf = confirm('Are you sure you want to delete the file?') || false;
  15.     if (conf == true) {
  16.       Meteor.call('RemoveFile', this.props.fileId, function (err, res) {
  17.         if (err)
  18.           console.log(err);
  19.       });
  20.     }
  21.   }
  22.  
  23.   renameFile = () => {
  24.     "use strict";
  25.  
  26.     let validName = /[^a-zA-Z0-9 \.:\+()\-_%!&]/gi;
  27.     let prompt    = window.prompt('New file name?', this.props.fileName);
  28.  
  29.     // Replace any non valid characters, also do this on the server
  30.     if (prompt) {
  31.       prompt = prompt.replace(validName, '-');
  32.       prompt.trim();
  33.     }
  34.  
  35.     if (!_.isEmpty(prompt)) {
  36.       Meteor.call('RenameFile', this.props.fileId, prompt, function (err, res) {
  37.         if (err)
  38.           console.log(err);
  39.       });
  40.     }
  41.   }
  42.  
  43.  
  44.   render() {
  45.     return <div className="m-t-sm">
  46.       <div className="row">
  47.         <div className="col-md-12">
  48.           <strong>{this.props.fileName}</strong>
  49.           <div className="m-b-sm">
  50.           </div>
  51.         </div>
  52.       </div>
  53.  
  54.       <div className="row">
  55.         <div className="col-md-3">
  56.           <button onClick={this.renameFile} className="btn btn-outline btn-primary btn-sm">
  57.             Rename
  58.           </button>
  59.         </div>
  60.  
  61.  
  62.         <div className="col-md-3">
  63.           <a href={this.props.fileUrl} className="btn btn-outline btn-primary btn-sm"
  64.              target="_blank">View</a>
  65.         </div>
  66.  
  67.         <div className="col-md-2">
  68.           <button onClick={this.removeFile} className="btn btn-outline btn-danger btn-sm">
  69.             Delete
  70.           </button>
  71.         </div>
  72.  
  73.         <div className="col-md-4">
  74.           Size: {this.props.fileSize}
  75.         </div>
  76.       </div>
  77.     </div>
  78.   }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement