added sensitive info toggle
parent
fea35bab90
commit
3e9e9534e1
|
@ -0,0 +1,25 @@
|
||||||
|
import React from "react";
|
||||||
|
import { IconButton } from "@material-ui/core";
|
||||||
|
import {
|
||||||
|
Visibility as VisibilityIcon,
|
||||||
|
VisibilityOff as VisibilityOffIcon
|
||||||
|
} from "@material-ui/icons";
|
||||||
|
import { useSensitiveInfo } from "../../hooks";
|
||||||
|
|
||||||
|
const SensitiveInfoToggle = () => {
|
||||||
|
const { enabled, onSensitiveInfoEnabled } = useSensitiveInfo();
|
||||||
|
|
||||||
|
const handleChange = () => onSensitiveInfoEnabled(!enabled);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IconButton
|
||||||
|
aria-label="sensitive-info-toggle"
|
||||||
|
color="inherit"
|
||||||
|
onClick={handleChange}
|
||||||
|
>
|
||||||
|
{enabled ? <VisibilityOffIcon /> : <VisibilityIcon />}
|
||||||
|
</IconButton>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SensitiveInfoToggle;
|
|
@ -6,6 +6,7 @@ import { AppBar, Toolbar, Typography, IconButton } from "@material-ui/core";
|
||||||
import MenuIcon from "@material-ui/icons/Menu";
|
import MenuIcon from "@material-ui/icons/Menu";
|
||||||
import ProfileButton from "./ProfileButton";
|
import ProfileButton from "./ProfileButton";
|
||||||
import LightDarkToggle from "./LightDarkToggle";
|
import LightDarkToggle from "./LightDarkToggle";
|
||||||
|
import SensitiveInfoToggle from "./SensitiveInfoToggle";
|
||||||
import styles from "./styles";
|
import styles from "./styles";
|
||||||
|
|
||||||
const useStyles = makeStyles(styles);
|
const useStyles = makeStyles(styles);
|
||||||
|
@ -35,6 +36,7 @@ const TopBar = ({ open, handleDrawerOpen }) => {
|
||||||
<Typography variant="h6" noWrap className={classes.title}>
|
<Typography variant="h6" noWrap className={classes.title}>
|
||||||
Network resurrector
|
Network resurrector
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<SensitiveInfoToggle />
|
||||||
<LightDarkToggle />
|
<LightDarkToggle />
|
||||||
<ProfileButton />
|
<ProfileButton />
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
|
|
|
@ -1 +1,4 @@
|
||||||
export { useToast } from "./useToast";
|
import { useToast } from "./useToast";
|
||||||
|
import { useSensitiveInfo } from "../providers/SensitiveInfoProvider";
|
||||||
|
|
||||||
|
export { useToast, useSensitiveInfo };
|
||||||
|
|
|
@ -6,20 +6,23 @@ import App from "./components/App";
|
||||||
import { TuitioProvider } from "@flare/tuitio-client-react";
|
import { TuitioProvider } from "@flare/tuitio-client-react";
|
||||||
import ApplicationStateProvider from "./providers/ApplicationStateProvider";
|
import ApplicationStateProvider from "./providers/ApplicationStateProvider";
|
||||||
import ToastProvider from "./providers/ToastProvider";
|
import ToastProvider from "./providers/ToastProvider";
|
||||||
|
import SensitiveInfoProvider from "./providers/SensitiveInfoProvider";
|
||||||
import "./utils/i18n";
|
import "./utils/i18n";
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<TuitioProvider tuitioUrl={process.env.REACT_APP_TUITIO_URL}>
|
<TuitioProvider tuitioUrl={process.env.REACT_APP_TUITIO_URL}>
|
||||||
<ApplicationStateProvider>
|
|
||||||
<ThemeProvider>
|
<ThemeProvider>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
|
<SensitiveInfoProvider>
|
||||||
|
<ApplicationStateProvider>
|
||||||
<Suspense fallback={<div>Loading...</div>}>
|
<Suspense fallback={<div>Loading...</div>}>
|
||||||
<ToastProvider>
|
<ToastProvider>
|
||||||
<App />
|
<App />
|
||||||
</ToastProvider>
|
</ToastProvider>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</ThemeProvider>
|
|
||||||
</ApplicationStateProvider>
|
</ApplicationStateProvider>
|
||||||
|
</SensitiveInfoProvider>
|
||||||
|
</ThemeProvider>
|
||||||
</TuitioProvider>,
|
</TuitioProvider>,
|
||||||
document.getElementById("root")
|
document.getElementById("root")
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
import React, { useReducer, useMemo, useContext } from "react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const SensitiveInfoContext = React.createContext();
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
enabled: false
|
||||||
|
};
|
||||||
|
|
||||||
|
const reducer = (state = initialState, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case "onSensitiveInfoEnabled": {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
enabled: action.payload.enabled
|
||||||
|
};
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const dispatchActions = dispatch => ({
|
||||||
|
onSensitiveInfoEnabled: enabled =>
|
||||||
|
dispatch({ type: "onSensitiveInfoEnabled", payload: { enabled } })
|
||||||
|
});
|
||||||
|
|
||||||
|
const useSensitiveInfo = () => {
|
||||||
|
const { state, actions } = useContext(SensitiveInfoContext);
|
||||||
|
const { enabled } = state;
|
||||||
|
const { onSensitiveInfoEnabled } = actions;
|
||||||
|
|
||||||
|
return { enabled, onSensitiveInfoEnabled };
|
||||||
|
};
|
||||||
|
|
||||||
|
const SensitiveInfoProvider = ({ children }) => {
|
||||||
|
const [state, dispatch] = useReducer(reducer, initialState);
|
||||||
|
const actions = useMemo(() => dispatchActions(dispatch), [dispatch]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SensitiveInfoContext.Provider
|
||||||
|
value={{
|
||||||
|
state,
|
||||||
|
actions
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</SensitiveInfoContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
SensitiveInfoProvider.propTypes = {
|
||||||
|
children: PropTypes.node.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
export { SensitiveInfoProvider, useSensitiveInfo };
|
||||||
|
export default SensitiveInfoProvider;
|
Loading…
Reference in New Issue