Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reporting images added #147

Merged
merged 6 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/ResponsiveAppBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const ResponsiveAppBar = () => {
<Button
color="inherit"
onClick={handleCloseNavMenu}
sx={{ my: 2, display: "block" }}
sx={{ my: 2 }}
component={Link}
to={`/settings`}
data-welcome-tour="settings"
Expand Down
39 changes: 36 additions & 3 deletions src/pages/questions/ProductInformation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell";
import TableRow from "@mui/material/TableRow";

import OutlinedFlagIcon from "@mui/icons-material/OutlinedFlag";
import FlagIcon from "@mui/icons-material/Flag";
import Zoom from "react-medium-image-zoom";
import "react-medium-image-zoom/dist/styles.css";

import { useTranslation } from "react-i18next";
import { NO_QUESTION_LEFT } from "../../const";
import offService from "../../off";
import { updateFlagImage, removeFlagImage } from "../../utils";

import {
localSettings,
Expand All @@ -42,6 +43,21 @@ const ProductInformation = ({ question }) => {
const { t } = useTranslation();
const [productData, setProductData] = React.useState({});
const [hideImages, setHideImages] = React.useState(getHideImages);
const [flagged, setFlagged] = React.useState([]);

const flagImage = (src, barcode, index) => {
const response = updateFlagImage(barcode, src);
sumana2001 marked this conversation as resolved.
Show resolved Hide resolved
const updatedImageArray = [...flagged];
updatedImageArray[index] = true;
setFlagged(updatedImageArray);
};

const deleteFlagImage = (src, barcode, index) => {
const response = removeFlagImage(barcode, src);
const updatedImageArray = [...flagged];
updatedImageArray[index] = false;
setFlagged(updatedImageArray);
};

React.useEffect(() => {
if (!question?.barcode) {
Expand Down Expand Up @@ -121,7 +137,11 @@ const ProductInformation = ({ question }) => {
{!hideImages && productData?.images && (
<Grid container rowSpacing={1.5} spacing={1}>
{getImagesUrls(productData.images, question.barcode).map((src) => (
<Grid item key={src}>
<Grid
item
key={src}
style={{ display: "inline-flex", alignItems: "flex-start" }}
>
<Zoom>
<img
src={src}
Expand All @@ -130,6 +150,19 @@ const ProductInformation = ({ question }) => {
style={{ maxWidth: 300, maxHeight: 300 }}
/>
</Zoom>
{flagged[src[src.length - 5]] ? (
<FlagIcon
onClick={() =>
deleteFlagImage(src, question.barcode, src[src.length - 5])
sumana2001 marked this conversation as resolved.
Show resolved Hide resolved
}
/>
) : (
<OutlinedFlagIcon
onClick={() =>
sumana2001 marked this conversation as resolved.
Show resolved Hide resolved
flagImage(src, question.barcode, src[src.length - 5])
}
/>
)}
</Grid>
))}
</Grid>
Expand Down
25 changes: 25 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import axios from "axios";

const reformatTagMapping = {
" ": "-",
"'": "-",
Expand Down Expand Up @@ -41,3 +43,26 @@ export const removeEmptyKeys = (obj) => {
export function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

export const updateFlagImage = (barcode, src) => {
sumana2001 marked this conversation as resolved.
Show resolved Hide resolved
return axios.put(
`https://amathjourney.com/api/off-annotation/flag-image/${barcode}`,
{
mode: "no-cors",
imgid: Number(src[src.length - 5]),
sumana2001 marked this conversation as resolved.
Show resolved Hide resolved
url: src,
}
);
};

export const removeFlagImage = (barcode, src) => {
sumana2001 marked this conversation as resolved.
Show resolved Hide resolved
return axios.delete(
`https://amathjourney.com/api/off-annotation/flag-image/${barcode}`,
{
mode: "no-cors",
data: {
imgid: Number(src[src.length - 5]),
},
}
);
};