Skip to content

Commit

Permalink
#464 Change layer params, vector-conf, colorpickers, start tools tab
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Apr 23, 2024
1 parent 15b6cad commit 703d1d0
Show file tree
Hide file tree
Showing 15 changed files with 910 additions and 101 deletions.
55 changes: 55 additions & 0 deletions configure/package-lock.json

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

2 changes: 2 additions & 0 deletions configure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"clsx": "^2.0.0",
"html2pug": "^4.0.0",
"immutable": "^5.0.0-beta.4",
"leaflet": "^1.9.4",
"react": "^17.0.2",
"react-color": "^2.19.3",
"react-dom": "^17.0.2",
"react-redux": "^8.1.3",
"react-router-dom": "^6.22.3",
Expand Down
81 changes: 81 additions & 0 deletions configure/src/components/ColorButton/ColorButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React, { useCallback, useRef, useState } from "react";
import { ChromePicker } from "react-color";

import useClickOutside from "./useClickOutside";

import { makeStyles } from "@mui/styles";

const useStyles = makeStyles((theme) => ({
ColorButton: {
width: "100%",
height: "100%",
},
item: {
width: "100%",
height: "100%",
display: "flex",
},
swatch: {
width: "30px",
height: "30px",
margin: "10px",
border: `1px solid black`,
borderRadius: "3px",
boxShadow: "0px 2px 5px 0px rgba(0,0,0,0.2)",
},
label: {
flex: 1,
lineHeight: "40px",
margin: "5px",
},
popover: {
height: 0,
zIndex: 999,
position: "relative",
"& > div": {
fontFamily: "Roboto !important",
},
},
}));

const ColorButton = ({ label, color, onChange }) => {
const popover = useRef();
const [isOpen, toggle] = useState(false);

const c = useStyles();

const close = useCallback(() => {
toggle(false);
}, []);
useClickOutside(popover, close);

let timeout = null;

return (
<div className={c.ColorButton}>
<div className={c.item}>
<div
className={c.swatch}
style={{ backgroundColor: color }}
onClick={() => toggle(true)}
/>
<div className={c.label}>{label}</div>
</div>
{isOpen && (
<div className={c.popover} ref={popover}>
<ChromePicker
color={color}
onChangeComplete={(c) => {
clearTimeout(timeout);
timeout = setTimeout(() => {
onChange(c);
}, 50);
}}
/>
</div>
)}
</div>
);
};

export default ColorButton;
35 changes: 35 additions & 0 deletions configure/src/components/ColorButton/useClickOutside.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useEffect } from "react";

// Improved version of https://usehooks.com/useOnClickOutside/
const useClickOutside = (ref, handler) => {
useEffect(() => {
let startedInside = false;
let startedWhenMounted = false;

const listener = (event) => {
// Do nothing if `mousedown` or `touchstart` started inside ref element
if (startedInside || !startedWhenMounted) return;
// Do nothing if clicking ref's element or descendent elements
if (!ref.current || ref.current.contains(event.target)) return;

handler(event);
};

const validateEventStart = (event) => {
startedWhenMounted = ref.current;
startedInside = ref.current && ref.current.contains(event.target);
};

document.addEventListener("mousedown", validateEventStart);
document.addEventListener("touchstart", validateEventStart);
document.addEventListener("click", listener);

return () => {
document.removeEventListener("mousedown", validateEventStart);
document.removeEventListener("touchstart", validateEventStart);
document.removeEventListener("click", listener);
};
}, [ref, handler]);
};

export default useClickOutside;
103 changes: 76 additions & 27 deletions configure/src/components/Main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { setConfiguration, setSnackBarText } from "../../core/ConfigureStore";

import Home from "../Tabs/Home/Home";
import Layers from "../Tabs/Layers/Layers";
import Tools from "../Tabs/Tools/Tools";
import UserInterface from "../Tabs/UserInterface/UserInterface";

const useStyles = makeStyles((theme) => ({
Expand Down Expand Up @@ -67,6 +68,28 @@ const useStyles = makeStyles((theme) => ({
background: theme.palette.swatches.p[0],
},
},
introWrapper: {
width: "100%",
height: "100%",
},
intro: {
position: "absolute",
left: "50%",
top: "50%",
textAlign: "center",
transform: "translateX(-50%) translateY(-50%)",
},
title: {
fontSize: "30px",
fontWeight: "bold",
lineHeight: "22px",
opacity: 0.65,
},
subtitle: { letterSpacing: "1px", textTransform: "uppercase", opacity: 0.5 },
message: {
fontSize: "13px",
opacity: 0.6,
},
}));

export default function Main() {
Expand Down Expand Up @@ -105,6 +128,8 @@ export default function Main() {
TabPage = <Layers />;
break;
case 2:
TabPage = <Tools />;
break;
case 3:
case 4:
TabPage = (
Expand All @@ -121,34 +146,58 @@ export default function Main() {

return (
<div className={c.Main}>
<div className={c.topbar}>
<div className={c.tabs}>
<Tabs
variant="scrollable"
value={tabValue}
onChange={(e, val) => {
setTabValue(val);
}}
sx={{ borderRight: 1, borderColor: "divider" }}
>
<Tab icon={<HomeIcon />} iconPosition="start" label="Home" />
<Tab icon={<LayersIcon />} iconPosition="start" label="Layers" />
<Tab icon={<HandymanIcon />} iconPosition="start" label="Tools" />
<Tab
icon={<ExploreIcon />}
iconPosition="start"
label="Coordinates"
/>
<Tab icon={<AccessTimeIcon />} iconPosition="start" label="Time" />
<Tab
icon={<ViewQuiltIcon />}
iconPosition="start"
label="User Interface"
/>
</Tabs>
{mission == null ? (
<div className={c.introWrapper}>
<div className={c.intro}>
<div className={c.title}>MMGIS</div>
<div className={c.subtitle}>Configuration</div>
<div className={c.message}>Create or Select a Mission</div>
</div>
</div>
</div>
<div className={c.tabPage}>{TabPage}</div>
) : (
<>
<div className={c.topbar}>
<div className={c.tabs}>
<Tabs
variant="scrollable"
value={tabValue}
onChange={(e, val) => {
setTabValue(val);
}}
sx={{ borderRight: 1, borderColor: "divider" }}
>
<Tab icon={<HomeIcon />} iconPosition="start" label="Home" />
<Tab
icon={<LayersIcon />}
iconPosition="start"
label="Layers"
/>
<Tab
icon={<HandymanIcon />}
iconPosition="start"
label="Tools"
/>
<Tab
icon={<ExploreIcon />}
iconPosition="start"
label="Coordinates"
/>
<Tab
icon={<AccessTimeIcon />}
iconPosition="start"
label="Time"
/>
<Tab
icon={<ViewQuiltIcon />}
iconPosition="start"
label="User Interface"
/>
</Tabs>
</div>
</div>
<div className={c.tabPage}>{TabPage}</div>
</>
)}
</div>
);
}
3 changes: 1 addition & 2 deletions configure/src/components/Tabs/Layers/Layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ export default function Layers() {
const configuration = useSelector((state) => state.core.configuration);

const handleClick = (layer) => {
console.log(layer);
dispatch(
setModal({
name: "layer",
on: true,
layer: JSON.stringify(layer),
layerUUID: layer.uuid,
onClose: () => {
console.log("closed");
},
Expand Down
Loading

0 comments on commit 703d1d0

Please sign in to comment.