From 245dffa33e77a2ccd1a28535b3809c02f78ccc66 Mon Sep 17 00:00:00 2001 From: deanchen Date: Wed, 26 Jan 2022 21:18:44 +0800 Subject: [PATCH] feat: refine UI for matching tool --- .../CaptureMatching/CandidateImages.js | 58 ++++++-- .../CaptureMatching/CaptureHeader.js | 2 +- .../CaptureMatching/CaptureImage.js | 130 ++++++++++-------- .../CaptureMatching/CaptureMatchingView.js | 68 +++++++-- .../CaptureMatching/CurrentCaptureNumber.js | 2 +- src/components/CaptureMatching/Grower.js | 37 ++--- 6 files changed, 200 insertions(+), 97 deletions(-) diff --git a/src/components/CaptureMatching/CandidateImages.js b/src/components/CaptureMatching/CandidateImages.js index dfd2930d1..b57651f14 100644 --- a/src/components/CaptureMatching/CandidateImages.js +++ b/src/components/CaptureMatching/CandidateImages.js @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; -import { Typography, Box, Button, Grid } from '@material-ui/core'; +import { Typography, Box, Button, Grid, Paper } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; import CheckIcon from '@material-ui/icons/Check'; import ClearIcon from '@material-ui/icons/Clear'; @@ -9,9 +9,7 @@ import theme from '../common/theme'; const useStyles = makeStyles({ containerBox: { marginTop: 0, - marginRight: theme.spacing(5), marginBottom: theme.spacing(5), - marginLeft: theme.spacing(5), paddingBottom: theme.spacing(2), background: '#fff', borderRadius: '4px', @@ -37,12 +35,37 @@ const useStyles = makeStyles({ }, imageScroll: { - height: '76vh', - overflow: 'scroll', + // height: '76vh', + // overflow: 'scroll', }, candidateImgBtn: { - marginTop: '10px', + padding: theme.spacing(5, 4), + display: 'flex', + gap: theme.spacing(2), + }, + button: { + fontSize: '16px', + }, + box2: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'baseline', + padding: '8px 16px', + }, + box3: { + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + }, + box1: { + width: '24px', + height: '24px', + backgroundColor: '#75B926', + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + color: 'white', }, }); @@ -70,20 +93,26 @@ function CandidateImages({ candidateImgData, sameTreeHandler }) { {candidateImgData && candidateImgData.map((tree, i) => { return ( - + showImgBox(tree.id)} > - + + + {++i} + Tree {tree.tree_id} + {/* button */} @@ -121,21 +150,22 @@ function CandidateImages({ candidateImgData, sameTreeHandler }) { - + + + USA + + {/* */} + + + + + @@ -128,7 +150,7 @@ function CaptureImage(props) { alt={`Capture ${capture.id}`} /> - + ); })} diff --git a/src/components/CaptureMatching/CaptureMatchingView.js b/src/components/CaptureMatching/CaptureMatchingView.js index b08c53229..c5d86f22d 100644 --- a/src/components/CaptureMatching/CaptureMatchingView.js +++ b/src/components/CaptureMatching/CaptureMatchingView.js @@ -6,32 +6,45 @@ import CandidateImages from './CandidateImages'; import Navbar from '../Navbar'; import { makeStyles } from '@material-ui/core/styles'; -import { Grid, Box, Paper } from '@material-ui/core'; +import { Grid, Box, Paper, Typography } from '@material-ui/core'; import NatureOutlinedIcon from '@material-ui/icons/NatureOutlined'; import theme from '../common/theme'; import { documentTitle } from '../../common/variables'; +import EditIcon from '@material-ui/icons/Edit'; +import Fab from '@material-ui/core/Fab'; -const useStyle = makeStyles({ +const useStyle = makeStyles((theme) => ({ container: { backgroundColor: '#E5E5E5', width: '100%', - height: 'auto', display: 'flex', - paddingBottom: '40px', + height: 'calc(100vh - 43px)', }, candidateImgIcon: { fontSize: '37px', }, - candidateIconBox: { - margin: theme.spacing(5), - }, + candidateIconBox: {}, box1: { backgroundColor: '#F0F0F0', + padding: theme.spacing(4, 4), + width: '50%', + height: '100%', + boxSizing: 'border-box', + }, + box2: { + padding: theme.spacing(4, 4), + width: '50%', + overflow: 'scroll', + }, + fab: { + color: 'white', + position: 'absolute', + right: '16px', + backgroundColor: 'rgba(118, 187, 35, .8)', }, - box2: {}, -}); +})); // Set API as a variable const CAPTURE_API = `${process.env.REACT_APP_TREETRACKER_API_ROOT}`; @@ -111,6 +124,28 @@ function CaptureMatchingView() { setImgCount(captureImages.length); }, [captureImages]); + // detect scroll + const refBox = React.useRef(null); + const [floatTreeIcon, setFloatTreeIcon] = useState(false); + useEffect(() => { + function checkPosition() { + const pos = refBox.current.scrollTop; + console.warn('ref:', pos); + if (parseInt(pos) > 144 && !floatTreeIcon) { + console.warn('show float icon'); + setFloatTreeIcon(true); + } + if (parseInt(pos) < 144 && floatTreeIcon) { + console.warn('close float icon'); + setFloatTreeIcon(false); + } + } + + refBox.current.addEventListener('scroll', checkPosition); + checkPosition(); + return () => window.removeEventListener('scroll', checkPosition); + }, []); + // Capture Image Pagination function const handleChange = (e, value) => { setCurrentPage(value); @@ -170,7 +205,19 @@ function CaptureMatchingView() { handleSkip={handleSkip} /> - + + {floatTreeIcon && ( + { + refBox.current.scrollTo(0, 0); + }} + > + {treesCount} + + )} + - + {props.cameraImg} diff --git a/src/components/CaptureMatching/Grower.js b/src/components/CaptureMatching/Grower.js index 6548c5d6e..1bc941215 100644 --- a/src/components/CaptureMatching/Grower.js +++ b/src/components/CaptureMatching/Grower.js @@ -1,25 +1,28 @@ import React from 'react'; -import { Typography, Box } from '@material-ui/core'; +import { makeStyles } from '@material-ui/core/styles'; +import { Avatar, Typography, Box } from '@material-ui/core'; +const useStyles = makeStyles((theme) => ({ + box1: { + display: 'flex', + flexDirection: 'row', + gap: 12, + }, + avatar: { + width: 72, + height: 72, + }, + box2: {}, +})); function Grower({ planter_photo_url, planter_username, status }) { + const classes = useStyles(); return ( - - - - - {planter_username} - - {status} + + + + {planter_username} + {/*status*/ 'Other info'} );