Skip to content

Commit

Permalink
fetching title of protein on click now
Browse files Browse the repository at this point in the history
  • Loading branch information
akshatbhargava123 committed Jul 29, 2019
1 parent 091c3aa commit 25d8aea
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions src/RootContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class RootContainer extends React.Component {
selectedId: 0,
viewerMode: 'cartoon',
error: null,
searchedId: ''
searchedId: '',
hoveredId: null
};
this.initVisualizer = this.initVisualizer.bind(this);
this.handleSearch = this.handleSearch.bind(this);
this.fetchTitle = this.fetchTitle.bind(this);
}

componentDidMount() {
Expand All @@ -42,6 +44,7 @@ class RootContainer extends React.Component {
filteredPdbIds: ids
});
this.initVisualizer(ids);
this.fetchTitle(ids[0]);
})
.catch(error => {
error =
Expand Down Expand Up @@ -94,12 +97,32 @@ class RootContainer extends React.Component {
}

updateSelected(idIndex) {
this.setState({ selectedId: idIndex });
this.setState({
selectedId: idIndex,
focusedIdTitle: '',
detailsLoading: true
});

// fetch title for the `id` clicked
const id = this.state.filteredPdbIds[idIndex];
this.fetchTitle(id);

this.visualizer.current.innerHTML = '';
this.setState({ structureReady: false });
this.initVisualizer(null, idIndex);
}

fetchTitle(id) {
fetch(`https://www.rcsb.org/pdb/json/describePDB?structureId=${id}`)
.then(res => res.json())
.then(res =>
this.setState({
detailsLoading: false,
focusedIdTitle: res[0].title
})
);
}

changeMode(ev) {
this.setState({ viewerMode: ev.target.value }, () => {
this.visualizer.current.innerHTML = '';
Expand All @@ -121,12 +144,22 @@ class RootContainer extends React.Component {
const PdbIdList =
this.state.filteredPdbIds &&
this.state.filteredPdbIds.map((id, i) => (
<div
key={i}
className={`option ${this.state.selectedId == i && 'selected'}`}
onClick={() => this.updateSelected(i)}
>
{id}
<div key={i}>
<div
className={`option ${this.state.selectedId == i && 'selected'}`}
onClick={() => this.updateSelected(i)}
>
{id}
</div>
{this.state.selectedId === i && (
<div style={{ display: 'flex', justifyContent: 'center' }}>
{this.state.detailsLoading ? (
<Loading />
) : (
<h3>{this.state.focusedIdTitle}</h3>
)}
</div>
)}
</div>
));

Expand Down

0 comments on commit 25d8aea

Please sign in to comment.