Skip to content

Commit

Permalink
added actions for setting url
Browse files Browse the repository at this point in the history
  • Loading branch information
rosannamilner committed Oct 7, 2024
1 parent 2ff4960 commit ad41e6a
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { useSelector } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { useNavigate } from "react-router-dom";

import Avatar from "@mui/material/Avatar";
import Box from "@mui/material/Box";
Expand All @@ -14,12 +15,16 @@ import { i18nLoadNamespace } from "components/Shared/Languages/i18nLoadNamespace
import useMyStyles from "../../../Shared/MaterialUiStyles/useMyStyles";
import Divider from "@mui/material/Divider";
import { KNOWN_LINKS } from "../AssistantRuleBook";
import { useNavigate } from "react-router-dom";

import { setDeepfakeUrlImage } from "../../../../redux/actions/tools/deepfakeImageActions";
import { setDeepfakeUrlVideo } from "../../../../redux/actions/tools/deepfakeVideoActions";
import { setSyntheticImageDetectionUrl } from "../../../../redux/actions/tools/syntheticImageDetectionActions";

const AssistantProcessUrlActions = () => {
const classes = useMyStyles();
const navigate = useNavigate();
const keyword = i18nLoadNamespace("components/NavItems/tools/Assistant");
const dispatch = useDispatch();

const inputUrl = useSelector((state) => state.assistant.inputUrl);
const processUrl = useSelector((state) => state.assistant.processUrl);
Expand All @@ -30,6 +35,18 @@ const AssistantProcessUrlActions = () => {

const handleClick = (action) => {
const resultUrl = action.useInputUrl ? inputUrl : processUrl;

// deepfake and synthetic image detection set URL actions
if (action.path === "tools/deepfakeImage") {
dispatch(setDeepfakeUrlImage({ url: resultUrl }));
}
if (action.path === "tools/deepfakeVideo") {
dispatch(setDeepfakeUrlVideo({ url: resultUrl }));
}
if (action.path === "tools/syntheticImageDetection") {
dispatch(setSyntheticImageDetectionUrl({ url: resultUrl }));
}

if (action.download) {
// Creates an A tag for downloading the video
let dl = document.createElement("a");
Expand Down
3 changes: 1 addition & 2 deletions src/components/NavItems/tools/Deepfake/DeepfakeImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ const Deepfake = () => {
//const dispatch = useDispatch();
const isLoading = useSelector((state) => state.deepfakeImage.loading);
const result = useSelector((state) => state.deepfakeImage.result);
//const url = useSelector((state) => state.deepfakeImage.url);
const { url } = useParams();
const url = useSelector((state) => state.deepfakeImage.url);
const role = useSelector((state) => state.userSession.user.roles);
const [input, setInput] = useState(url ? url : "");
const [type, setType] = useState("");
Expand Down
4 changes: 1 addition & 3 deletions src/components/NavItems/tools/Deepfake/DeepfakeVideo.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { useParams } from "react-router-dom";
import LinearProgress from "@mui/material/LinearProgress";
import Box from "@mui/material/Box";
import useMyStyles from "../../../Shared/MaterialUiStyles/useMyStyles";
Expand Down Expand Up @@ -28,8 +27,7 @@ const Deepfake = () => {

const isLoading = useSelector((state) => state.deepfakeVideo.loading);
const result = useSelector((state) => state.deepfakeVideo.result);
//const url = useSelector((state) => state.deepfakeVideo.url);
const { url } = useParams();
const url = useSelector((state) => state.deepfakeVideo.url);
const role = useSelector((state) => state.userSession.user.roles);
const [input, setInput] = useState(url ? url : "");
const [type, setType] = useState("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ const SyntheticImageDetection = () => {
(state) => state.syntheticImageDetection.loading,
);
const result = useSelector((state) => state.syntheticImageDetection.result);
//const url = useSelector((state) => state.syntheticImageDetection.url);
const { url } = useParams();
const url = useSelector((state) => state.syntheticImageDetection.url);
const nd = useSelector((state) => state.syntheticImageDetection.duplicates);
const [input, setInput] = useState(url ? url : "");
const [imageFile, setImageFile] = useState(undefined);
Expand Down
2 changes: 2 additions & 0 deletions src/redux/actions/tools/deepfakeImageActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export const setDeepfakeLoadingImage = createAction(
);

export const setDeepfakeResultImage = createAction("SET_DEEPFAKE_IMAGE_RESULT");

export const setDeepfakeUrlImage = createAction("SET_DEEPFAKE_IMAGE_URL");
2 changes: 2 additions & 0 deletions src/redux/actions/tools/deepfakeVideoActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ export const setDeepfakeResultVideo = createAction("SET_DEEPFAKE_VIDEO_RESULT");
}
}
};*/

export const setDeepfakeUrlVideo = createAction("SET_DEEPFAKE_VIDEO_URL");
4 changes: 4 additions & 0 deletions src/redux/actions/tools/syntheticImageDetectionActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export const setSyntheticImageDetectionResult = createAction(
export const setSyntheticImageDetectionNearDuplicates = createAction(
"SET_SYNTHETIC_IMAGE_DETECTION_NEAR_DUPLICATES",
);

export const setSyntheticImageDetectionUrl = createAction(
"SET_SYNTHETIC_IMAGE_DETECTION_URL",
);
5 changes: 5 additions & 0 deletions src/redux/reducers/tools/deepfakeImageReducer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ const deepfakeImageReducer = (state = defaultState, action) => {
result: action.payload.result,
loading: false,
};
case "SET_DEEPFAKE_IMAGE_URL":
return {
...state,
url: action.payload.url,
};
default:
return state;
}
Expand Down
5 changes: 5 additions & 0 deletions src/redux/reducers/tools/deepfakeVideoReducer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ const deepfakeVideoReducer = (state = defaultState, action) => {
result: action.payload.result,
loading: false,
};
case "SET_DEEPFAKE_VIDEO_URL":
return {
...state,
url: action.payload.url,
};
default:
return state;
}
Expand Down
5 changes: 5 additions & 0 deletions src/redux/reducers/tools/syntheticImageDetectionReducer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const syntheticImageDetectionReducer = (state = defaultState, action) => {
duplicates: action.payload,
loading: false,
};
case "SET_SYNTHETIC_IMAGE_DETECTION_URL":
return {
...state,
url: action.payload.url,
};
default:
return state;
}
Expand Down

0 comments on commit ad41e6a

Please sign in to comment.