Skip to content

Commit

Permalink
Merge pull request #25 from SheffieldMLtracking/fetch-image
Browse files Browse the repository at this point in the history
Fetch image
  • Loading branch information
Joe-Heffer-Shef authored Jun 17, 2024
2 parents f2f2337 + 8365f4d commit 8be22b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
1 change: 0 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ function App() {
return (
<div className="App">
<Sessions/> {/*It should be a component, which in turn have all the children component to fetch session, camera, device etc.*/}
<Image/>
</div>
);
}
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/components/Image.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import './Image.css'
import image from '../mockData/test.jpg'

import { useState, useRef, useEffect } from 'react'
import DrawRetrodetectMarkers from './DrawRetrodetectMarkers.jsx';
Expand All @@ -8,12 +7,14 @@ import SaveMarkers from './SaveMarkers.jsx';

/*
A bee tracking photo
*/
function Image () {
import image from '../mockData/test.jpg'
*/
function Image (props) {
//Ref for image
const imgRef = useRef(null);

console.log('IN IMAGE COMPONENT')
console.log(props.image)

//State for x, y coordinates based on the original image
const [coordinate, setCoordinate] = useState({
Expand Down Expand Up @@ -260,7 +261,7 @@ function Image () {
<SaveMarkers markerList={markerList}/>
<button onClick={RetrodetectController}>Show Retrodetect labels</button>
<div className='ImageContainer'>
<img ref={imgRef} src={image} onClick={clickHandler} alt='' style={{
<img ref={imgRef} src={props.image} onClick={clickHandler} alt='' style={{
height: `${imageSize.viewHeight}px`,
width: `${imageSize.viewWidth}px`,
top: `${imageNewPosition.top}px`,
Expand Down
19 changes: 9 additions & 10 deletions frontend/src/components/PhotoSelection.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {useState} from 'react'
import Image from './Image';

/*
Display a drop-down list of photos to be shown.
*/
function PhotoSelection (props) {
function PhotoSelection(props) {
const [currentPhoto, setCurrentPhoto] = useState('')
/*
List the photos for users to choose from
Expand All @@ -16,23 +17,20 @@ function PhotoSelection (props) {
*/
function photoFetcher(e) {
let selectedPhoto = e.target.value;
setCurrentPhoto(selectedPhoto);

console.log(selectedPhoto);

// Update the list of photo filenames available in that session
let url = `/api/${selectedPhoto}`;
url = url.replace("np","jpeg")
console.log(url)
fetch(url)
.then(response => response.json())
.then(data => setCurrentPhoto(data));
let urlJpeg = '/api/photos/' + selectedPhoto.replace("np", "jpeg");
setCurrentPhoto(urlJpeg);

console.log(currentPhoto)

}



return(
return (
<>
<select
name="photo"
Expand All @@ -42,9 +40,10 @@ function PhotoSelection (props) {
>
<option/>
{listDisplayed}</select>
<Image image={currentPhoto}/>

</>
)
}

export default PhotoSelection

0 comments on commit 8be22b1

Please sign in to comment.