Skip to content

Commit

Permalink
refactor code, use better naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
Smith authored and Smith committed Jun 7, 2020
1 parent 44f03a4 commit e4c02c7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/api/filesApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ function downloadFiles(id) {
export {
getFilesByCourse,
getFilesByType,
downloadFiles,
};
downloadFiles
};
6 changes: 3 additions & 3 deletions src/components/coursecard/coursePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CoursePage extends Component {
this.addCourse = this.addCourse.bind(this);
this.deleteCourse = this.deleteCourse.bind(this);
this.sortFilesByYear = this.sortFilesByYear.bind(this);
this.updateFileDownloads = this.updateFileDownloads.bind(this);
this.updateFileState = this.updateFileState.bind(this);
}

componentDidMount() {
Expand All @@ -59,7 +59,7 @@ class CoursePage extends Component {
}
}

updateFileDownloads = (id, downloads) => {
updateFileState = (id, downloads) => {
this.state.files.forEach(file => (file.files.filter(file => file.id === id)[0].downloads = downloads));
this.setState({ files: this.state.files });
}
Expand Down Expand Up @@ -268,7 +268,7 @@ class CoursePage extends Component {
ext={file.fileext}
size={file.size}
date_modified={file.date_modified}
updateFileDownloads0={this.updateFileDownloads} />
updateFileState={this.updateFileState} />
)) : null}
<div className='coursepage--material_year' onClick={() => this.setState({ year: obj.year })}>
{obj.year}
Expand Down
25 changes: 17 additions & 8 deletions src/components/coursecard/materialCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ class MaterialCard extends Component {
}

/**
* Download the file
* Handle download button click
*/
downloadFile(id, url) {

const link = "https://drive.google.com/a/iitr.ac.in/uc?id=" + url + "&export=download";

//window.open(link, "_blank");
window.open(link, "_blank");
downloadFiles(id).then((res, err) => {
this.props.updateFileDownloads0(id, res[0].downloads);
if (err) {
//TODO handle error
} else {
this.props.updateFileState(id, res[0].downloads);
}
});
}

Expand All @@ -76,8 +78,15 @@ class MaterialCard extends Component {
</div>
<div className='material--sizemod'>
{this.state.queue === '1' ?
<div className='material--downloadicon-active' onMouseLeave={this.leave} onClick={() => this.downloadFile(this.props.id, this.props.url)}><img src={download1} alt='download' /></div> :
<div className='material--downloadicon-other' onMouseOver={this.hover} onClick={() => this.downloadFile(this.props.id, this.props.url)}><img src={download2} alt='download' /></div>}
<div className='material--downloadicon-active' onMouseLeave={this.leave} onClick={
() => this.downloadFile(this.props.id, this.props.url)}>
<img src={download1} alt='download' />
</div> :
<div className='material--downloadicon-other' onMouseOver={this.hover} onClick={
() => this.downloadFile(this.props.id, this.props.url)}>
<img src={download2} alt='download' />
</div>
}
<div className='material--size'>{this.props.size}</div>
<div className='material--datemodified'>{parseDate(this.props.date_modified)}</div>
</div>
Expand Down Expand Up @@ -106,5 +115,5 @@ MaterialCard.propTypes = {
/** Holds the id of the file */
id: PropTypes.number,
/** updates the downloads field in the state of material card */
updateFileDownloads0: PropTypes.func
updateFileState: PropTypes.func
};

0 comments on commit e4c02c7

Please sign in to comment.