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

Navigation Refactoring #551

Merged
merged 20 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"baseUrl": "./src",
"checkJs": true,
"checkJs": false,
"jsx": "react"
},
"exclude": ["node_modules", "**/node_modules", "dist", "build"]
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "weverify-plugin",
"version": "0.81",
"version": "0.82",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Fake news debunker by InVID & WeVerify",
"version": "0.81",
"version": "0.82",
"description": "InVID WeVerify extension",
"short_name": "Verification Plugin",
"action": {
Expand Down
4 changes: 2 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React, { useEffect, useState } from "react";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import { HashRouter, Route, Routes } from "react-router-dom";
import PopUp from "./components/PopUp/PopUp";
import NavBar from "./components/NavBar/NavBar";
import useAuthenticationAPI from "./components/Shared/Authentication/useAuthenticationAPI";
import { useDispatch } from "react-redux";
import {
cleanErrorNetwork,
setErrorNetwork,
} from "redux/reducers/errorReducer";
import { i18nLoadNamespace } from "components/Shared/Languages/i18nLoadNamespace";
import ApplicationLayout from "./components/ApplicationLayout";

const theme = createTheme({
palette: {
Expand Down Expand Up @@ -103,7 +103,7 @@ const App = () => {
<ThemeProvider theme={theme}>
<Routes>
<Route index path="/" element={<PopUp />} />
<Route path={"/app/*"} element={<NavBar />} />
<Route path={"/app/*"} element={<ApplicationLayout />} />
</Routes>
</ThemeProvider>
</HashRouter>
Expand Down
8 changes: 4 additions & 4 deletions src/Hooks/useAnalytics.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useSelector } from "react-redux";
import { useEffect } from "react";
import {
trackPageView,
trackPageViewAnonymous,
trackEvent,
trackEventAnonymous,
trackPageView,
trackPageViewAnonymous,
} from "../components/Shared/GoogleAnalytics/MatomoAnalytics";
import { history } from "../components/Shared/History/History";

export const useTrackPageView = (path, client_id, uid, index) => {
export const useTrackPageView = (path, client_id, uid, toolName) => {
const analytics = useSelector((state) => state.cookies.analytics);
useEffect(() => {
//console.log("general page view");
Expand All @@ -18,7 +18,7 @@ export const useTrackPageView = (path, client_id, uid, index) => {
} else {
trackPageViewAnonymous(path, history);
}
}, [index]);
}, [toolName]);
};

export const useTrackEvent = (
Expand Down
93 changes: 93 additions & 0 deletions src/components/ApplicationLayout/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React, { useState } from "react";
import NotificationSnackbar from "../NotificationSnackbar";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import TopMenu from "../TopMenu";
import { TOP_MENU_ITEMS } from "../../constants/topMenuItems";
import SideMenu from "../SideMenu";
import { tools } from "../../constants/tools";
import MainContent from "../MainContent";
import useMyStyles from "../Shared/MaterialUiStyles/useMyStyles";

const ApplicationLayout = () => {
const theme = createTheme({
palette: {
primary: {
light: "#00926c",
main: "#00926c",
dark: "#00926c",
contrastText: "#fff",
},
},
components: {
MuiAppBar: {
styleOverrides: {
colorPrimary: {
backgroundColor: "#ffffff",
},
root: {
zIndex: 1300,
height: "87px",
boxShadow: "none",
paddingTop: "12px",
},
},
},
MuiListItem: {
styleOverrides: {
gutters: {
paddingLeft: "26px",
},
},
},
MuiAutocomplete: {
styleOverrides: {
popupIndicatorOpen: {
transform: "none!important",
},
popper: {
zIndex: 99999,
},
},
},
MuiCard: {
styleOverrides: {
root: {
borderRadius: "10px!important",
},
},
},
MuiIconButton: {
styleOverrides: {
root: {
padding: 0,
},
},
},
MuiTab: {
styleOverrides: {
root: {
minWidth: "160px",
},
},
},
},
});

// Used to display warning messages
const [openAlert, setOpenAlert] = useState(false);

const classes = useMyStyles();

return (
<div className={classes.flex}>
<NotificationSnackbar openAlert={openAlert} setOpenAlert={setOpenAlert} />
<ThemeProvider theme={theme}>
<SideMenu tools={tools} setOpenAlert={setOpenAlert} />
<TopMenu topMenuItems={TOP_MENU_ITEMS} />
<MainContent tools={tools} />
</ThemeProvider>
</div>
);
};

export default ApplicationLayout;
194 changes: 194 additions & 0 deletions src/components/MainContent/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import React from "react";
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";
import { KeyboardArrowUp } from "@mui/icons-material";
import MySnackbar from "../MySnackbar/MySnackbar";
import {
cleanError,
cleanErrorNetwork,
} from "../../redux/reducers/errorReducer";
import { setFalse, setTrue } from "../../redux/reducers/cookiesReducers";
import Feedback from "../Feedback/Feedback";
import useMyStyles from "../Shared/MaterialUiStyles/useMyStyles";
import { TOOL_STATUS_ICON } from "../../constants/tools";
import { useDispatch, useSelector } from "react-redux";
import { i18nLoadNamespace } from "../Shared/Languages/i18nLoadNamespace";
import { TOP_MENU_ITEMS } from "../../constants/topMenuItems";

/**
*
* @param tools {Tool[]}
* @returns {Element}
* @constructor
*/
const MainContent = ({ tools }) => {
const classes = useMyStyles();

const keyword = i18nLoadNamespace("components/NavBar");

const dispatch = useDispatch();

const currentLang = useSelector((state) => state.language);
const isCurrentLanguageLeftToRight = currentLang !== "ar";

const error = useSelector((state) => state.error.tools);
const errorNetwork = useSelector((state) => state.error.network);

const cookiesUsage = useSelector((state) => state.cookies);

const role = useSelector((state) => state.userSession.user.roles);

const toolsAllowedForRole = tools.filter((tool) => {
if (
!tool.rolesNeeded ||
tool.rolesNeeded.length === 0 ||
tool.rolesNeeded.includes(TOOL_STATUS_ICON.LOCK)
)
return true;
else if (tool.rolesNeeded.some((restriction) => role.includes(restriction)))
return true;
else return false;
});

const themeFab = createTheme({
palette: {
primary: {
light: "#00926c",
main: "#00926c",
dark: "#00926c",
contrastText: "#fff",
},
},
components: {
MuiAppBar: {
styleOverrides: {
colorPrimary: {
backgroundColor: "#ffffff",
},
root: {
zIndex: 1300,
height: "87px",
boxShadow: "none",
paddingTop: "12px",
},
},
},
MuiListItem: {
styleOverrides: {
gutters: {
paddingLeft: "26px",
},
},
},
MuiAutocomplete: {
styleOverrides: {
popupIndicatorOpen: {
transform: "none!important",
},
popper: {
zIndex: 99999,
},
},
},
MuiCard: {
styleOverrides: {
root: {
borderRadius: "10px!important",
},
},
},
MuiIconButton: {
styleOverrides: {
root: {
padding: 0,
},
},
},
MuiTab: {
styleOverrides: {
root: {
minWidth: "160px",
},
},
},
},
});

return (
<main className={classes.content}>
<div className={classes.toolbar} id="back-to-top-anchor" />
<MainContentMenuTopMenuItems
className={classes.noMargin}
topMenuItems={TOP_MENU_ITEMS}
tools={toolsAllowedForRole}
/>
<ScrollTop
{...{ isCurrentLanguageLeftToRight: isCurrentLanguageLeftToRight }}
>
<ThemeProvider theme={themeFab}>
<Fab
color="primary"
size="large"
aria-label="scroll back to top"
className={classes.fabTop}
>
<KeyboardArrowUp />
</Fab>
</ThemeProvider>
</ScrollTop>
{error !== null && (
<MySnackbar
variant="error"
message={error}
onClick={() => dispatch(cleanError())}
onClose={() => {}}
sx={{ mr: 8 }}
/>
)}
{errorNetwork !== null && (
<MySnackbar
variant="error"
message={errorNetwork}
onClick={() => dispatch(cleanErrorNetwork())}
onClose={() => {}}
sx={{ mr: 8 }}
/>
)}
{cookiesUsage.active === null && (
<Snackbar
anchorOrigin={{
vertical: "top",
horizontal: "center",
}}
open={true}
message={keyword("cookies_message")}
action={[
<Button
key={"cookies_decline"}
color={"secondary"}
size={"small"}
onClick={() => dispatch(setFalse())}
>
{" "}
{keyword("cookies_decline")}{" "}
</Button>,
<Button
key={"cookies_accept"}
color={"primary"}
size={"small"}
onClick={() => dispatch(setTrue())}
>
{" "}
{keyword("cookies_accept")}{" "}
</Button>,
]}
/>
)}
<Feedback />
</main>
);
};

export default MainContent;
Loading