Skip to content

Commit

Permalink
Refactoring + fixed opening drawer when opening tool from URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Sallaa committed Jun 28, 2024
1 parent 9e5afe8 commit 1c33562
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 149 deletions.
8 changes: 4 additions & 4 deletions src/components/MainContent/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import MainContentMenuTabItems from "../NavBar/MainContentMenuTabItems/MainContentMenuTabItems";
import MainContentMenuTopMenuItems from "../NavBar/MainContentMenuTabItems/MainContentMenuTopMenuItems";
import ScrollTop from "../Shared/ScrollTop/ScrollTop";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import { Button, Fab, Snackbar } from "@mui/material";
Expand Down Expand Up @@ -119,10 +119,10 @@ const MainContent = ({ tools }) => {
return (
<main className={classes.content}>
<div className={classes.toolbar} id="back-to-top-anchor" />
<MainContentMenuTabItems
<MainContentMenuTopMenuItems
className={classes.noMargin}
tabItems={TOP_MENU_ITEMS}
toolsList={toolsAllowedForRole}
topMenuItems={TOP_MENU_ITEMS}
tools={toolsAllowedForRole}
/>
<ScrollTop
{...{ isCurrentLanguageLeftToRight: isCurrentLanguageLeftToRight }}
Expand Down
6 changes: 3 additions & 3 deletions src/components/NavBar/DrawerItem/DrawerItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useMyStyles from "../../Shared/MaterialUiStyles/useMyStyles";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import { getclientId } from "../../Shared/GoogleAnalytics/MatomoAnalytics";
import { useTrackPageView } from "../../../Hooks/useAnalytics";
import { selectPage } from "../../../redux/reducers/navReducer";
import { selectTopMenuItem } from "../../../redux/reducers/navReducer";
import { TOP_MENU_ITEMS } from "../../../constants/topMenuItems";
import { selectTool } from "../../../redux/reducers/tools/toolReducer";
import { TOOL_GROUPS } from "../../../constants/tools";
Expand Down Expand Up @@ -105,10 +105,10 @@ const DrawerItemContent = ({ tool }) => {

const handleToolChange = (tool) => {
if (tool.toolGroup === TOOL_GROUPS.VERIFICATION)
dispatch(selectPage(TOP_MENU_ITEMS[0].title));
dispatch(selectTopMenuItem(TOP_MENU_ITEMS[0].title));

if (tool.toolGroup === TOOL_GROUPS.MORE)
dispatch(selectPage(TOP_MENU_ITEMS[5].title));
dispatch(selectTopMenuItem(TOP_MENU_ITEMS[5].title));

dispatch(selectTool(tool.titleKeyword));
};
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { Route, Routes, useLocation } from "react-router-dom";
import { Container } from "@mui/material";
import Fade from "@mui/material/Fade";
import React, { useEffect } from "react";
import DrawerItem from "../DrawerItem/DrawerItem";
import { useDispatch, useSelector } from "react-redux";
import { useTrackPageView } from "../../../Hooks/useAnalytics";
import { toolsHome } from "../../../constants/tools";
import { TOP_MENU_ITEMS } from "../../../constants/topMenuItems";
import { selectTopMenuItem } from "../../../redux/reducers/navReducer";

/**
* Represents the group of tools to display and their tabs in the ToolsMenu
*
* @param topMenuItems An array with the list of top menu items
* @param tools {Tool[]} An array with the list of tools
* @returns {React.JSX.Element|null}
*
*/
const MainContentMenuTopMenuItems = ({ topMenuItems, tools }) => {
if (!topMenuItems || topMenuItems.length === 0) return null;

return (
<Routes>
{topMenuItems.map((topMenuItem, index) => {
return (
<Route
key={index}
path={topMenuItem.path + "/*"}
element={
<TabContent
index={index}
topMenuItem={topMenuItem}
topMenuItems={topMenuItems}
tools={tools}
/>
}
/>
);
})}
</Routes>
);
};

const TabContent = ({ index, topMenuItem, tools, topMenuItems }) => {
const dispatch = useDispatch();

useEffect(() => {
const topMenuItemSelected = TOP_MENU_ITEMS.find(
(t) => t.title === topMenuItem.title,
);

dispatch(selectTopMenuItem(topMenuItemSelected.title));
}, []);

switch (topMenuItem.path) {
case toolsHome.path:
return <DrawerItem toolsList={tools} />;
case "assistant":
return (
<Routes>
<Route path={"*"}>
<Route
index
element={
<ContentContainer topMenuItems={topMenuItems} index={index} />
}
/>
<Route
path={":url"}
element={
<ContentContainer topMenuItems={topMenuItems} index={index} />
}
/>
</Route>
</Routes>
);
default:
return <ContentContainer topMenuItems={topMenuItems} index={index} />;
}
};

const ContentContainer = ({ topMenuItems, index }) => {
let path = useLocation();
// const cookies = useSelector((state) => state.cookies);
// const clientId = cookies !== null ? cookies.id : null;

const session = useSelector((state) => state.userSession);

const uid = session && session.user ? session.user.id : null;
const clientId = uid;
useTrackPageView(path, clientId, uid);
useEffect(() => {
// trackPageView(path, clientId, uid);
}, []);

return (
<Container key={index}>
<Fade in={true}>
<div>
{topMenuItems[index].content}
{topMenuItems[index].footer}
</div>
</Fade>
</Container>
);
};

export default MainContentMenuTopMenuItems;
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const AssistantMediaResult = () => {
const imageList = useSelector((state) => state.assistant.imageList);
const videoList = useSelector((state) => state.assistant.videoList);

// third party tool states
// third party topMenuItem states
//const ocrLoading = useSelector(state=>state.assistant.ocrLoading)
const dbkfMediaMatchLoading = useSelector(
(state) => state.assistant.dbkfMediaMatchLoading,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useEffect, useState, useRef } from "react";
import React, { useEffect, useRef, useState } from "react";
import Box from "@mui/material/Box";
import useMyStyles from "../../../../Shared/MaterialUiStyles/useMyStyles";
import Card from "@mui/material/Card";
import CardHeader from "@mui/material/CardHeader";
import { Grid, Typography, Stack, IconButton, Tooltip } from "@mui/material";
import { Grid, IconButton, Stack, Tooltip, Typography } from "@mui/material";
import { i18nLoadNamespace } from "components/Shared/Languages/i18nLoadNamespace";
import { LinearProgressWithLabel } from "../../../../Shared/LinearProgressWithLabel/LinearProgressWithLabel";
import { Close, Help } from "@mui/icons-material";
Expand All @@ -15,6 +15,7 @@ import { useTrackEvent } from "Hooks/useAnalytics";
const DeepfakeResultsImage = (props) => {
const classes = useMyStyles();
const keyword = i18nLoadNamespace("components/NavItems/tools/Deepfake");

class DeepfakeResult {
constructor(methodName, predictionScore) {
(this.methodName = methodName), (this.predictionScore = predictionScore);
Expand Down Expand Up @@ -250,7 +251,7 @@ const DeepfakeResultsImage = (props) => {

<img
src={url}
alt={"Displays the results of the deepfake tool"}
alt={"Displays the results of the deepfake topMenuItem"}
style={{
maxWidth: "100%",
maxHeight: "60vh",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ const SyntheticImageDetectionResults = (props) => {
>
<img
src={url}
alt={"Displays the results of the deepfake tool"}
alt={"Displays the results of the deepfake topMenuItem"}
style={{
maxWidth: "100%",
maxHeight: "60vh",
Expand Down
Loading

0 comments on commit 1c33562

Please sign in to comment.