Skip to content

Commit

Permalink
Merge pull request #104 from Spiderpig02/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
jmnorheim authored Sep 9, 2024
2 parents 503876d + 0e6ef09 commit 9f23135
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 25 deletions.
7 changes: 5 additions & 2 deletions backend/galacticPathFinder/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "templates")],
"DIRS": [os.path.join(BASE_DIR, 'frontend', 'build')],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down Expand Up @@ -132,7 +132,10 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_URL = "static/"
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'frontend', 'build', 'static'),
]

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
Expand Down
5 changes: 4 additions & 1 deletion backend/galacticPathFinder/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""
from django.contrib import admin
from django.urls import path, re_path, include
from django.views.generic import TemplateView
from rest_framework.schemas import get_schema_view
from rest_framework import permissions
from drf_yasg.views import get_schema_view
Expand Down Expand Up @@ -46,5 +47,7 @@
schema_view.with_ui("swagger", cache_timeout=0),
name="schema-swagger-ui",
),
path("redoc/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc")
path("redoc/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"),
# Catch-all route to serve the React app's index.html
re_path(r"^(?!admin|graphtraversal|swagger|redoc).*", TemplateView.as_view(template_name="index.html")),
]
24 changes: 24 additions & 0 deletions frontend/src/components/mapGrid/MapGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,30 @@ const MapGrid = () => {
?.isExplored;
};

// Handle scroll to adjust grid size
const handleScroll = (event: Event) => {
const wheelEvent = event as WheelEvent;
if (wheelEvent.deltaY < 0) {
// Scrolling up - zooming in
mapSizeSliderSignal.value = Math.max(20, mapSizeSliderSignal.value - 2);
} else {
// Scrolling down - zooming out
mapSizeSliderSignal.value = Math.min(70, mapSizeSliderSignal.value + 2);
}
};

useEffect(() => {
const gridContainer = document.querySelector(".grid-container");
if (gridContainer) {
gridContainer.addEventListener("wheel", handleScroll);
}
return () => {
if (gridContainer) {
gridContainer.removeEventListener("wheel", handleScroll);
}
};
}, []);

return (
<div
className="grid-container"
Expand Down
22 changes: 8 additions & 14 deletions frontend/src/components/mapSizeSlider/MapSizeSlider.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
import React, { useState } from "react";
import React from "react";
import "./MapSizeSlider.css";
import { mapSizeSliderSignal } from "../../pages/homePage/HomePage";
import { useSignal } from "@preact/signals-react";

const MapSizeSlider = () => {
const [size, setSize] = useState<number>(mapSizeSliderSignal.value);
const size = useSignal(mapSizeSliderSignal);

const handleSliderChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setSize(parseInt(e.target.value));
};

const handleCommitChange = () => {
console.log("Size = ", size);
mapSizeSliderSignal.value = size;
mapSizeSliderSignal.value = parseInt(e.target.value);
};

return (
<div className="map-size-slider-container">
<label htmlFor="myRange" className="slider-label">
Adjust map size
Adjust map size ({size.value}x{size.value})
</label>
<input
type="range"
min="20"
max="80"
value={size}
min={20}
max={70}
value={size.value.toString()}
className="slider"
id="myRange"
onChange={handleSliderChange}
onMouseUp={handleCommitChange}
onKeyUp={handleCommitChange}
/>
</div>
);
Expand Down
24 changes: 21 additions & 3 deletions frontend/src/components/navbar/Navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,31 @@
}

.navbar-links a {
position: relative;
margin: 0 1rem;
text-decoration: none;
color: inherit;
font-size: 1.2rem;
/* background-color: green; */
}

.navbar-links a:hover {
text-decoration: underline;
.navbar-links a::after {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: -2px;
left: 0;
background-color: white;
transform: scaleX(0);
transform-origin: left;
transition: transform 0.3s ease-in-out;
}

.navbar-links a:hover::after {
transform: scaleX(1);
}

.navbar-links a.active::after {
transform: scaleX(1);
transform-origin: left;
}
22 changes: 18 additions & 4 deletions frontend/src/components/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import React from "react";
import { Link } from "react-router-dom";
import { Link, useLocation } from "react-router-dom";
import "./Navbar.css";

const Navbar: React.FC = () => {
const location = useLocation();

return (
<nav className="navbar">
<div className="navbar-logo" onClick={() => (window.location.href = "/")}>
GalacticPathFinder
</div>
<div className="navbar-links">
<Link to="/">Home</Link>
<Link to="/tutorial">Tutorial</Link>
<Link to="/about-us">About Us</Link>
<Link to="/" className={location.pathname === "/" ? "active" : ""}>
Home
</Link>
<Link
to="/tutorial"
className={location.pathname === "/tutorial" ? "active" : ""}
>
Tutorial
</Link>
<Link
to="/about-us"
className={location.pathname === "/about-us" ? "active" : ""}
>
About Us
</Link>
</div>
</nav>
);
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/services/mapHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export const downloadMap = () => {
function parseNodes(map: Node[]): string {
let csvText = "";
for (const node of map) {
csvText += `${node.x},${node.y},${node.weight},${node.isPath}\n`;
// Exclude nodes with isPath = true
if (!node.isPath) {
csvText += `${node.x},${node.y},${node.weight},${node.isPath}\n`;
}
}
return csvText;
}

0 comments on commit 9f23135

Please sign in to comment.