diff --git a/resq/.idea/.gitignore b/resq/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/resq/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/resq/.idea/misc.xml b/resq/.idea/misc.xml new file mode 100644 index 00000000..bcb5da6c --- /dev/null +++ b/resq/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/resq/.idea/modules.xml b/resq/.idea/modules.xml new file mode 100644 index 00000000..2610f480 --- /dev/null +++ b/resq/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/resq/.idea/resq.iml b/resq/.idea/resq.iml new file mode 100644 index 00000000..d6ebd480 --- /dev/null +++ b/resq/.idea/resq.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/resq/.idea/vcs.xml b/resq/.idea/vcs.xml new file mode 100644 index 00000000..6c0b8635 --- /dev/null +++ b/resq/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/resq/frontend/src/components/AnnotationCard.js b/resq/frontend/src/components/AnnotationCard.js index f567cbae..17bd1bc4 100644 --- a/resq/frontend/src/components/AnnotationCard.js +++ b/resq/frontend/src/components/AnnotationCard.js @@ -13,18 +13,21 @@ const AnnotationCard = ({ annotation }) => { .then((name) => setLocationName(name)) .catch((error) => console.error('Error fetching location name:', error)); } - }, [annotation.latitude, annotation.longitude]); + console.log(annotation); - const handleViewMore = () => { setLongDescription(annotation.long_description || 'Long description not available.'); + }, [annotation]); + + const handleViewMore = () => { + setLongDescription(item.long_description || 'Long description not available.'); setOpen(true); }; - const handleClose = () => { setOpen(false); }; + const LongDescriptionDialog = () => ( {annotation.title} @@ -70,11 +73,10 @@ const AnnotationCard = ({ annotation }) => { )} - handleViewMore(annotation)}> + View More - {/* Long Description Dialog */} ); diff --git a/resq/frontend/src/components/Cards/AnnotationCard.js b/resq/frontend/src/components/Cards/AnnotationCard.js index da3a7c15..ae4ef302 100644 --- a/resq/frontend/src/components/Cards/AnnotationCard.js +++ b/resq/frontend/src/components/Cards/AnnotationCard.js @@ -4,8 +4,8 @@ import reverseGeocode from '../Geolocation'; const AnnotationCard = ({ item }) => { const [locationName, setLocationName] = useState('Unknown Location'); - const [open, setOpen] = useState(false); // Added for Dialog control - const [longDescription, setLongDescription] = useState(''); // State to hold long description + const [open, setOpen] = useState(false); + const [longDescription, setLongDescription] = useState(''); useEffect(() => { if (item.latitude && item.longitude) { @@ -13,30 +13,18 @@ const AnnotationCard = ({ item }) => { .then((name) => setLocationName(name)) .catch((error) => console.error('Error fetching location name:', error)); } - }, [item.latitude, item.longitude]); - - const handleViewMore = () => { setLongDescription(item.long_description || 'Long description not available.'); - setOpen(true); // Open the dialog - }; + }, [item]); + const handleViewMore = (e) => { + e.stopPropagation(); + setOpen(true); + }; const handleClose = () => { - setOpen(false); // Close the dialog + setOpen(false); }; - // Dialog component to show long description - const LongDescriptionDialog = () => ( - - {item.title} - - - {longDescription || 'Long description not available.'} - - - - ); - return ( { )} - handleViewMore(item)}> + View More - {/* Long Description Dialog */} - + + {item.title} + + + {longDescription} + + + ); }; diff --git a/resq/frontend/src/components/Resource/ResourceAddress.js b/resq/frontend/src/components/Resource/ResourceAddress.js index 3bfad2da..236cd8cc 100644 --- a/resq/frontend/src/components/Resource/ResourceAddress.js +++ b/resq/frontend/src/components/Resource/ResourceAddress.js @@ -1,15 +1,15 @@ -import React, {useState, useEffect} from 'react'; -import {TextField, Button, FormControl, InputLabel, Select, MenuItem, Box} from '@mui/material'; +import React, { useState, useEffect } from 'react'; +import { TextField, Button, FormControl, InputLabel, Select, MenuItem, Box } from '@mui/material'; import '@fontsource/inter'; import Grid from '@mui/material/Grid'; import Typography from '@mui/material/Typography'; import FormControlLabel from '@mui/material/FormControlLabel'; import Checkbox from '@mui/material/Checkbox'; -import {createTheme, ThemeProvider} from '@mui/material/styles'; +import { createTheme, ThemeProvider } from '@mui/material/styles'; import CssBaseline from '@mui/material/CssBaseline'; import Container from '@mui/material/Container'; -import {ResourceContext} from './ResourceContext'; -import {useContext} from 'react'; +import { ResourceContext } from './ResourceContext'; +import { useContext } from 'react'; const customTheme = createTheme({ palette: { @@ -19,7 +19,7 @@ const customTheme = createTheme({ }, }); -export default function ResourceAddress({resourceData, setResourceData}) { +export default function ResourceAddress({ resourceData, setResourceData }) { const [address1, setAddress1] = useState("") const [address2, setAddress2] = useState("") const [city, setCity] = useState("") @@ -44,7 +44,7 @@ export default function ResourceAddress({resourceData, setResourceData}) { if (data.results && data.results.length > 0) { const location = data.results[0].geometry.location; setResourceData( - {...resourceData, latitude: location.lat, longitude: location.lng} + { ...resourceData, latitude: location.lat, longitude: location.lng } ) } else { console.error('Geocoding failed: No results found'); @@ -64,7 +64,7 @@ export default function ResourceAddress({resourceData, setResourceData}) { return ( - + Resource Delivery Address diff --git a/resq/frontend/src/pages/MapPage.js b/resq/frontend/src/pages/MapPage.js index 0b3ece74..65d4159b 100644 --- a/resq/frontend/src/pages/MapPage.js +++ b/resq/frontend/src/pages/MapPage.js @@ -1,18 +1,16 @@ -// noinspection JSUnusedLocalSymbols - import * as React from 'react'; -import {useEffect, useState} from 'react'; +import { useEffect, useState } from 'react'; import CssBaseline from '@mui/material/CssBaseline'; import Box from '@mui/material/Box'; -import {createTheme, ThemeProvider} from '@mui/material/styles'; +import { createTheme, ThemeProvider } from '@mui/material/styles'; import Container from '@mui/material/Container'; import DisasterMap from "../components/DisasterMap"; -import {cards} from "../components/Cards/ListCards"; -import {AmountSelector, MultiCheckbox} from "../components/MultiCheckbox"; -import {DatePicker} from "@mui/x-date-pickers"; +import { cards } from "../components/Cards/ListCards"; +import { AmountSelector, MultiCheckbox } from "../components/MultiCheckbox"; +import { DatePicker } from "@mui/x-date-pickers"; import dayjs from "dayjs"; -import {useQuery} from "@tanstack/react-query"; -import {getCategoryTree} from "../AppService"; +import { useQuery } from "@tanstack/react-query"; +import { getCategoryTree } from "../AppService"; const customTheme = createTheme({ palette: { @@ -27,7 +25,7 @@ const getAllCategories = categoryTree => { return item => { switch (item.type) { case "Annotation": - return [{id: item?.category, data: item?.category}] + return [{ id: item?.category, data: item?.category }] default: return categoryTree.findCategoryWithId(parseInt(item.categoryTreeId))?.getAllParentCategories() } @@ -65,7 +63,7 @@ const makeFilterByCategory = categories => { } }; -const makeFilterByType = (typeFilter) => item => typeFilter.length === 0 || typeFilter.map(t=>t.id).indexOf(item.type) !== -1 +const makeFilterByType = (typeFilter) => item => typeFilter.length === 0 || typeFilter.map(t => t.id).indexOf(item.type) !== -1 const makeFilterByAmount = ([amount]) => { if (typeof amount !== "string" || amount.indexOf("-") === -1) @@ -79,7 +77,7 @@ const makeFilterByAmount = ([amount]) => { const makeFilterByDateFrom = (dateFrom) => item => dateFrom === null || !dateFrom.isValid() || !(dateFrom > dayjs(item.date)) const makeFilterByDateTo = (dateTo) => item => dateTo === null || !dateTo.isValid() || !(dateTo < dayjs(item.date)) -const makeFilterByBounds = ({ne: [ne_lat, ne_lng], sw: [sw_lat, sw_lng]}) => +const makeFilterByBounds = ({ ne: [ne_lat, ne_lng], sw: [sw_lat, sw_lng] }) => function (item) { return item.latitude <= ne_lat && item.longitude <= ne_lng && @@ -88,38 +86,37 @@ const makeFilterByBounds = ({ne: [ne_lat, ne_lng], sw: [sw_lat, sw_lng]}) => } -export default function MapPage({allMarkers}) { - const [shownMarkers, setShownMarkers] = useState(allMarkers) - const [selectedPoint, setSelectedPoint] = useState(null) - const [mapCenter, setMapCenter] = useState([39, 34.5]) +const MapPage = ({ allMarkers }) => { + const [shownMarkers, setShownMarkers] = useState(allMarkers); + const [selectedPoint, setSelectedPoint] = useState(null); + const [mapCenter, setMapCenter] = useState([39, 34.5]); - const [typeFilter, setTypeFilter] = useState([]) - const [dateFromFilter, setDateFromFilter] = useState(null) - const [dateToFilter, setDateToFilter] = useState(null) - const [amountFilter, setAmountFilter] = useState([]) - const [categoryFilter, setCategoryFilter] = useState([]) - const [mapBounds, setMapBounds] = useState({ne: [0, 0], sw: [0, 0]}) + const [typeFilter, setTypeFilter] = useState([]); + const [dateFromFilter, setDateFromFilter] = useState(null); + const [dateToFilter, setDateToFilter] = useState(null); + const [amountFilter, setAmountFilter] = useState([]); + const [categoryFilter, setCategoryFilter] = useState([]); + const [mapBounds, setMapBounds] = useState({ ne: [0, 0], sw: [0, 0] }); - const categoryTree = useQuery({queryKey: ['categoryTree'], queryFn: getCategoryTree}) + const categoryTree = useQuery({ queryKey: ['categoryTree'], queryFn: getCategoryTree }); useEffect(() => { if (selectedPoint) { setMapCenter([selectedPoint.latitude, selectedPoint.longitude]); } - }, [selectedPoint]); - - useEffect(() => setShownMarkers(allMarkers), [allMarkers]) - useEffect(() => setShownMarkers( - allMarkers + const filteredMarkers = allMarkers .filter(makeFilterByCategory(categoryFilter)) .filter(makeFilterByType(typeFilter)) .filter(makeFilterByAmount(amountFilter)) .filter(makeFilterByDateFrom(dateFromFilter)) .filter(makeFilterByDateTo(dateToFilter)) - .filter(makeFilterByBounds(mapBounds)) - ), [allMarkers, amountFilter, categoryFilter, dateFromFilter, dateToFilter, mapBounds, typeFilter]) + .filter(makeFilterByBounds(mapBounds)); + + setShownMarkers(filteredMarkers); + }, [selectedPoint, allMarkers, amountFilter, categoryFilter, dateFromFilter, dateToFilter, mapBounds, typeFilter]); + const choices = new Map([ ...allMarkers @@ -133,29 +130,29 @@ export default function MapPage({allMarkers}) { // noinspection JSValidateTypes return ( - - + + ({id: i, data: i}))} - onChosenChanged={setTypeFilter}/> + choices={["Annotation", "Resource", "Request"].map(i => ({ id: i, data: i }))} + onChosenChanged={setTypeFilter} /> + choices={[...choices.values()]} + onChosenChanged={setCategoryFilter} /> + onChosenChanged={setAmountFilter} /> setDateFromFilter(e)} /> {shownMarkers.map((marker) => { const SelectedCard = cards[marker.type] - return setSelectedPoint(marker)}>< SelectedCard item={marker}/> + return setSelectedPoint(marker)}>< SelectedCard item={marker} /> })} - - + + @@ -203,5 +200,6 @@ export default function MapPage({allMarkers}) { ); } +export default MapPage;