Skip to content
Snippets Groups Projects
Commit c917880d authored by Anthony's avatar Anthony
Browse files

Fetching data is okay

parent f13d254d
No related branches found
No related tags found
2 merge requests!13Manifest side to side,!11Draft: 33 8 open an other manifest side by side from an annotation
Pipeline #1292 passed
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
Card, CardActionArea, CardActions, CardContent, CardMedia, Fab, Card, CardActionArea, CardActions, CardContent, CardMedia, Fab,
} from '@material-ui/core'; } from '@material-ui/core';
import Button from '@material-ui/core/Button'; import Button from '@material-ui/core/Button';
import async from 'async';
/** /**
* AnnotationManifestsAccordion * AnnotationManifestsAccordion
...@@ -50,46 +51,31 @@ export class AnnotationManifestsAccordion extends Component { ...@@ -50,46 +51,31 @@ export class AnnotationManifestsAccordion extends Component {
/** */ /** */
// eslint-disable-next-line class-methods-use-this,require-jsdoc // eslint-disable-next-line class-methods-use-this,require-jsdoc
async handleOpenAccordion(e, manifestClicked) { handleOpenAccordion(e) {
const { annotation } = this.state;
const manifestFound = annotation.manifests.find(manifest => manifest.id === manifestClicked.id);
const fetchResult = await fetch(manifestFound.id)
.then((response) => response.json())
.then((jsonData) => {
if (jsonData.type === 'Manifest') {
return jsonData;
}
return null;
}).then((jsonStr) => {
console.log(this.annotation.id);
});
e.stopPropagation(); e.stopPropagation();
} }
/** */
componentDidMount() {
const { annotation } = this.state;
/** */
async function loadManifest(manifests) { async function loadManifest(manifests) {
return Promise.all(requestsArray.map((request) => { return Promise.all(manifests.map((manifest) => fetch(manifest.id)
return fetch(request).then((response) => { .then((response) => response.json())
return response.json(); .then((data) => {
}).then((data) => {
if (data.type === 'Manifest') { if (data.type === 'Manifest') {
return data; return data;
} }
return null; return null;
}); })));
}));
} }
/** */ loadManifest(annotation.manifests)
componentDidMount() {
const { annotation } = this.state;
searchManifestAndAddButton(annotation.manifests)
.then((values) => { .then((values) => {
if (values) { if (values) {
this.setState({ annotation.manifests = values;
manifests: valuesFlat, this.setState({ annotation });
});
} }
}); });
} }
...@@ -97,9 +83,11 @@ export class AnnotationManifestsAccordion extends Component { ...@@ -97,9 +83,11 @@ export class AnnotationManifestsAccordion extends Component {
/** */ /** */
render() { render() {
const { const {
classes, t, classes, t, i18n,
} = this.props; } = this.props;
const language = i18n.language;
const { annotation } = this.state; const { annotation } = this.state;
if (annotation.manifests === null) { if (annotation.manifests === null) {
...@@ -108,11 +96,11 @@ export class AnnotationManifestsAccordion extends Component { ...@@ -108,11 +96,11 @@ export class AnnotationManifestsAccordion extends Component {
return ( return (
<div> <div>
{annotation.manifests.map(manifestId => ( {annotation.manifests.map(manifest => (
<Accordion> <Accordion>
<AccordionSummary <AccordionSummary
expandIcon={<ExpandMoreIcon />} expandIcon={<ExpandMoreIcon />}
onClick={(e) => this.handleOpenAccordion(e, manifestId)} onClick={(e) => this.handleOpenAccordion(e)}
> >
<Typography className={classes.heading}>Manifests found:</Typography> <Typography className={classes.heading}>Manifests found:</Typography>
</AccordionSummary> </AccordionSummary>
...@@ -130,10 +118,7 @@ export class AnnotationManifestsAccordion extends Component { ...@@ -130,10 +118,7 @@ export class AnnotationManifestsAccordion extends Component {
/> />
<CardContent> <CardContent>
<Typography gutterBottom variant="h5" component="h2"> <Typography gutterBottom variant="h5" component="h2">
Label de mon manifest {manifest.label ? manifest.label.en : manifest.id}
</Typography>
<Typography variant="body2" color="textSecondary" component="p">
Description de mon manifest
</Typography> </Typography>
</CardContent> </CardContent>
</CardActionArea> </CardActionArea>
...@@ -142,7 +127,7 @@ export class AnnotationManifestsAccordion extends Component { ...@@ -142,7 +127,7 @@ export class AnnotationManifestsAccordion extends Component {
size="small" size="small"
color="primary" color="primary"
onClick={(e) => { onClick={(e) => {
this.handleOpenManifestSideToSide(e, manifestId); this.handleOpenManifestSideToSide(e, manifest.id);
}} }}
> >
Open in new panel Open in new panel
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment