Add Navbar and remove some element
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Nontouch Mukleemart 2025-03-04 23:28:28 +07:00
parent 64cc990e19
commit 792b6279b9
8 changed files with 99 additions and 85 deletions

View file

@ -15,14 +15,21 @@ export const MemoryUsage = () => {
} }
} }
const interval = setInterval(updateMemoryUsage, 1000); const interval = setInterval(updateMemoryUsage, 500);
return () => clearInterval(interval); // Cleanup on unmount return () => clearInterval(interval); // Cleanup on unmount
}, []); }, []);
return ( return (
<Typography color="textPrimary" component="div"> <div style={{ padding: "10px" }}> {/* Added padding here */}
<h2>Client-Side Memory Usage</h2> <Typography color="textPrimary" component="div">
<p style={{ fontSize: "1.2em", fontWeight: "bold" }}>{memoryUsage}</p> <Typography color="textSecondary" component="div">
</Typography> Client-Side Memory Usage
</Typography>
<Typography color="textSecondary" component="div" style={{ fontSize: "1.2em", fontWeight: "bold" }}>
{memoryUsage}
</Typography>
</Typography>
</div>
); );
}; };

View file

@ -6,6 +6,7 @@ import { MenuSolverControls } from "./MenuSolverControls";
import { MenuMetrics } from "./MenuMetrics"; import { MenuMetrics } from "./MenuMetrics";
import { MenuPointControls } from "./MenuPointControls"; import { MenuPointControls } from "./MenuPointControls";
import { OtherControls } from "./OtherControls"; import { OtherControls } from "./OtherControls";
import { MemoryUsage } from "./MemoryUsage";
const useStyles = makeStyles(theme => ({ const useStyles = makeStyles(theme => ({
wrapper: { wrapper: {
@ -34,10 +35,19 @@ export const Menu = ({
const classes = useStyles(); const classes = useStyles();
return ( return (
<Paper classes={{ root: classes.wrapper }}> <Paper classes={{ root: classes.wrapper }} style={{
<MenuHeader /> position: "fixed",
width: "550px",
height: "500px",
top: "80px",
left: "20px",
color: "black",
padding: "15px",
borderRadius: "8px",
boxShadow: "2px 2px 10px rgba(0, 0, 0, 0.3)",
}}>
<Divider /> <Divider />
<MenuMetrics />
<MenuSolverControls <MenuSolverControls
onStart={onStart} onStart={onStart}
onPause={onPause} onPause={onPause}
@ -46,7 +56,7 @@ export const Menu = ({
onFullSpeed={onFullSpeed} onFullSpeed={onFullSpeed}
/> />
<Divider /> <Divider />
<MenuPointControls onRandomizePoints={onRandomizePoints} /> <MemoryUsage />
<Divider /> <Divider />
<OtherControls /> <OtherControls />
</Paper> </Paper>

View file

@ -17,7 +17,6 @@ import {
faPlay, faPlay,
faStop, faStop,
faRedo, faRedo,
faQuestion,
faFastForward, faFastForward,
faPause faPause
} from "@fortawesome/free-solid-svg-icons"; } from "@fortawesome/free-solid-svg-icons";
@ -112,13 +111,6 @@ export const MenuSolverControls = ({
))} ))}
</Select> </Select>
</Grid> </Grid>
<Grid item xs={1}>
<Typography align="right" color="textSecondary">
<IconButton edge="end" onClick={onShowAlgInfo}>
<FontAwesomeIcon icon={faQuestion} size="xs" />
</IconButton>
</Typography>
</Grid>
</Grid> </Grid>
</MenuItem> </MenuItem>
@ -139,15 +131,6 @@ export const MenuSolverControls = ({
/> />
</Button> </Button>
<Button
onClick={paused ? onStop : onFullSpeed}
disabled={(!running && !paused) || definingPoints || fullSpeed}
>
<FontAwesomeIcon
icon={paused ? faStop : faFastForward}
width="0"
/>
</Button>
<Button onClick={onReset} disabled={running || definingPoints}> <Button onClick={onReset} disabled={running || definingPoints}>
<FontAwesomeIcon icon={faRedo} width="0" /> <FontAwesomeIcon icon={faRedo} width="0" />
@ -167,62 +150,7 @@ export const MenuSolverControls = ({
/> />
</MenuItem> </MenuItem>
</MenuSection> </MenuSection>
<MenuSection>
<MenuItem row>
<Grid item xs={10}>
<Typography variant="button" color="textSecondary" component="div">
Show Best Path
</Typography>
</Grid>
<Grid item xs={2}>
<Switch
checked={showBestPath}
onChange={onShowBestPathChange}
color="secondary"
disabled={definingPoints || fullSpeed}
id="show-best-path"
/>
</Grid>
<Grid item xs={10}>
<Typography variant="button" color="textSecondary" component="div">
Show Evaluated Paths
</Typography>
</Grid>
<Grid item xs={2}>
<Switch
checked={evaluatingDetailLevel > 0}
onChange={onEvaluatingDetailLevelChange(1, 0)}
color="secondary"
disabled={definingPoints || fullSpeed}
id="show-evaluating-paths"
/>
</Grid>
{maxEvaluatingDetailLevel > 1 && (
<>
<Grid item xs={10}>
<Typography
variant="button"
color="textSecondary"
component="div"
>
Show Evaluated Steps
</Typography>
</Grid>
<Grid item xs={2}>
<Switch
checked={evaluatingDetailLevel > 1}
onChange={onEvaluatingDetailLevelChange(2, 1)}
color="secondary"
disabled={definingPoints || fullSpeed}
id="show-evaluating-steps"
/>
</Grid>
</>
)}
</MenuItem>
</MenuSection>
</> </>
); );
}; };

65
src/components/Navbar.jsx Normal file
View file

@ -0,0 +1,65 @@
import React from 'react';
import { Link } from "gatsby";
export const Navbar = () => {
const navbarStyle = {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
padding: '10px 20px',
backgroundColor: '#333',
color: 'white',
position: 'fixed', // Ensures the navbar stays at the top
top: 0,
left: 0,
width: '100%',
zIndex: 1000, // Makes sure the navbar stays on top
};
const leftStyle = {
fontSize: '20px',
fontWeight: 'bold',
};
const rightStyle = {
display: 'flex',
gap: '20px',
};
const linkStyle = {
color: 'white',
textDecoration: 'none',
fontSize: '16px',
};
const linkHoverStyle = {
textDecoration: 'underline',
};
return (
<nav style={navbarStyle}>
<div style={leftStyle}>
{/* Make the "TSP Visualization" clickable */}
<Link to="/" style={linkStyle}>
TSP Visualization
</Link>
</div>
<div style={rightStyle}>
<Link
to="/about"
style={linkStyle}
onMouseOver={(e) => e.target.style.textDecoration = 'underline'}
onMouseOut={(e) => e.target.style.textDecoration = 'none'}>
About
</Link>
<Link
to="/source-code"
style={linkStyle}
onMouseOver={(e) => e.target.style.textDecoration = 'underline'}
onMouseOut={(e) => e.target.style.textDecoration = 'none'}>
Source Code
</Link>
</div>
</nav>
);
};

View file

@ -3,7 +3,7 @@ import { Grid, Typography } from "@material-ui/core";
import { MenuItem } from "./MenuItem"; import { MenuItem } from "./MenuItem";
import { MenuSection } from "./MenuSection"; import { MenuSection } from "./MenuSection";
import { ThemeToggle } from "./ThemeToggle"; import { ThemeToggle } from "./ThemeToggle";
import { MemoryUsage } from "./MemoryUsage";
export const OtherControls = props => { export const OtherControls = props => {
return ( return (
@ -18,7 +18,7 @@ export const OtherControls = props => {
<ThemeToggle /> <ThemeToggle />
</Grid> </Grid>
</MenuItem> </MenuItem>
<MemoryUsage />
</MenuSection> </MenuSection>
); );
}; };

View file

@ -13,3 +13,4 @@ export * from "./MenuSolverControls";
export * from "../context/PreSetTheme"; export * from "../context/PreSetTheme";
export * from "./SEO"; export * from "./SEO";
export * from "./ThemeToggle"; export * from "./ThemeToggle";
export * from "./Navbar";

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before After
Before After

View file

@ -13,12 +13,14 @@ import {
MapPlot, MapPlot,
Menu, Menu,
SEO, SEO,
ThemeToggle ThemeToggle,
Navbar
} from "../components"; } from "../components";
import { useSolverWorker, useAlgorithmInfo } from "../hooks"; import { useSolverWorker, useAlgorithmInfo } from "../hooks";
import * as selectors from "../store/selectors"; import * as selectors from "../store/selectors";
import * as actions from "../store/actions"; import * as actions from "../store/actions";
const IndexPage = () => { const IndexPage = () => {
const mapRef = useRef(null); const mapRef = useRef(null);
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -87,6 +89,7 @@ const IndexPage = () => {
<SEO subtitle={algTitle} /> <SEO subtitle={algTitle} />
<IntroductionModal /> <IntroductionModal />
<AlgorithmModals /> <AlgorithmModals />
<Navbar />
<Menu <Menu
onStart={start} onStart={start}
onPause={pause} onPause={pause}