Skip to content

Commit 9a325ce

Browse files
authoredMay 26, 2024··
Merge branch 'main' into justin-footer-redo
2 parents 41a6e8d + 945af9f commit 9a325ce

File tree

7 files changed

+78
-127
lines changed

7 files changed

+78
-127
lines changed
 

‎src/components/userComponents/SiteMap/Control.tsx

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
/* eslint-disable jsdoc/require-returns */
2-
/* eslint-disable jsdoc/require-jsdoc */
31
import L from 'leaflet';
42
import React, { useState, createRef, useEffect } from 'react';
53
import { useMap } from 'react-leaflet';
64

75
interface ControlProps {
8-
position: L.ControlPosition;
6+
position: 'bottomleft' | 'bottomright' | 'topleft' | 'topright';
97
children?: React.ReactNode;
108
container?: React.HTMLAttributes<HTMLDivElement>;
119
prepend?: boolean;
@@ -18,14 +16,22 @@ const POSITION_CLASSES = {
1816
topright: 'leaflet-top leaflet-right',
1917
};
2018

19+
/**
20+
* Custom control component for Leaflet maps using React.
21+
* @param props - The properties object.
22+
* @param props.position - The position of the control on the map.
23+
* @param [props.children] - The child elements to be rendered inside the control.
24+
* @param [props.container] - Additional HTML attributes for the control container.
25+
* @param [props.prepend] - Whether to prepend the control to the container.
26+
* @returns The custom control component.
27+
*/
2128
function Control({
2229
position,
2330
children,
2431
container,
2532
prepend,
2633
}: ControlProps): JSX.Element {
27-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
28-
const [portalRoot, setPortalRoot] = useState<any>(
34+
const [portalRoot, setPortalRoot] = useState<HTMLElement>(
2935
document.createElement('div'),
3036
);
3137
const positionClass =
@@ -35,8 +41,8 @@ function Control({
3541

3642
/**
3743
* Whenever the control container ref is created,
38-
* Ensure the click / scroll propagation is removed
39-
* This way click/scroll events do not bubble down to the map
44+
* ensure the click/scroll propagation is removed.
45+
* This way click/scroll events do not bubble down to the map.
4046
*/
4147
useEffect(() => {
4248
if (controlContainerRef.current !== null) {
@@ -46,21 +52,23 @@ function Control({
4652
}, [controlContainerRef]);
4753

4854
/**
49-
* Whenever the position is changed, go ahead and get the container of the map and the first
50-
* instance of the position class in that map container
55+
* Whenever the position is changed, go ahead and get the container of the map
56+
* and the first instance of the position class in that map container.
5157
*/
5258
useEffect(() => {
5359
const mapContainer = map.getContainer();
54-
const targetDiv = mapContainer.getElementsByClassName(positionClass);
55-
setPortalRoot(targetDiv[0]);
60+
const targetDiv = mapContainer.getElementsByClassName(positionClass)[0];
61+
if (targetDiv) {
62+
setPortalRoot(targetDiv as HTMLElement);
63+
}
5664
}, [positionClass, map]);
5765

5866
/**
5967
* Whenever the portal root is complete,
60-
* append or prepend the control container to the portal root
68+
* append or prepend the control container to the portal root.
6169
*/
6270
useEffect(() => {
63-
if (portalRoot !== null) {
71+
if (portalRoot && controlContainerRef.current) {
6472
if (prepend !== undefined && prepend === true) {
6573
portalRoot.prepend(controlContainerRef.current);
6674
} else {
@@ -70,8 +78,9 @@ function Control({
7078
}, [portalRoot, prepend, controlContainerRef]);
7179

7280
/**
73-
* Concatenate the props.container className to the class of the control div, per leaflet's built in styles.
74-
* Will need to change styling of component itself based on screen breakpoints
81+
* Concatenate the props.container className to the class of the control div,
82+
* per Leaflet's built-in styles.
83+
* Will need to change styling of the component itself based on screen breakpoints.
7584
*/
7685
const className = `${container?.className?.concat(' ') || ''}leaflet-control`;
7786

‎src/components/userComponents/SiteMap/ExhibitPreviewCard.tsx

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect, useState, useCallback } from 'react';
2-
import { LatLngExpression } from 'leaflet';
3-
import { useMapEvents } from 'react-leaflet';
2+
// import { LatLngExpression } from 'leaflet';
3+
// import { useMapEvents } from 'react-leaflet';
44
import Link from 'next/link';
55
import Image from 'next/image';
66
import { ExhibitWithCategoryRow } from '../../../types/types';
@@ -14,18 +14,19 @@ interface ExhibitCardProps {
1414

1515
/**
1616
* Props for ExhibitPreviewCard
17-
* @typedef {Object} ExhibitCardProps
18-
* @property {ExhibitWithCategoryRow} tour - The exhibit data.
19-
* @property {Function} handleClose - Function to close the preview card.
20-
* @property {Function} [handleClick] - Optional click handler for additional actions.
17+
* tour - The exhibit data.
18+
* handleClose - Function to close the preview card.
19+
* [handleClick] - Optional click handler for additional actions.
2120
*/
2221

2322
/**
2423
* A component that renders a preview card for an exhibit within a Leaflet map container.
2524
* Includes image and details, with clickable areas for further interaction.
26-
*
27-
* @param {ExhibitCardProps} props - The props for the component.
28-
* @returns {JSX.Element} The rendered JSX for the exhibit preview card.
25+
* @param props - The props for the component.
26+
* @param props.tour - props for tour
27+
* @param props.handleClick - Will handle when user clicks on the exhibit card
28+
* @param props.handleClose - This will close the preview card
29+
* @returns - The rendered JSX for the exhibit preview card.
2930
*/
3031
function ExhibitPreviewCard({
3132
tour,
@@ -36,7 +37,7 @@ function ExhibitPreviewCard({
3637
const [previewImage, setPreviewImage] = useState<string>(tour.image || '');
3738
const [name1, setname1] = useState<string>(tour.category || '');
3839

39-
const { id, description, coordinates, category } = tour;
40+
const { id, description } = tour;
4041
const [width, setWidth] = useState('20.06rem');
4142
const [height, setHeight] = useState('7.687rem');
4243
const isWebDevice = useWebDeviceDetection();
@@ -57,16 +58,6 @@ function ExhibitPreviewCard({
5758
return () => window.removeEventListener('resize', handleResize);
5859
}, [handleResize]);
5960

60-
// Map Context
61-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
62-
const map = useMapEvents({
63-
click: e => {
64-
if (!e.latlng.equals(coordinates as LatLngExpression)) {
65-
handleClose();
66-
}
67-
},
68-
});
69-
7061
// fetch image to use for preview
7162
useEffect(() => {
7263
const fetchDetails = async () => {
@@ -128,6 +119,15 @@ function ExhibitPreviewCard({
128119
e.stopPropagation();
129120
handleClose();
130121
}}
122+
onKeyDown={e => {
123+
if (e.key === 'Enter' || e.key === ' ') {
124+
e.stopPropagation();
125+
handleClose();
126+
}
127+
}}
128+
role="button"
129+
tabIndex={0}
130+
aria-label="Close preview"
131131
>
132132
<svg
133133
xmlns="http://www.w3.org/2000/svg"

‎src/components/userComponents/SiteMap/MapInteractionHandler.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useMap } from 'react-leaflet';
2-
import React, { useEffect, useState } from 'react';
2+
import { useEffect } from 'react';
33
import { LatLngExpression } from 'leaflet';
44
/**
55
* A React component that recenters the map to a given coordinate. This component does not render any visual content.
6-
* @param {Object} props - Component props.
7-
* @param {L.LatLng} props.center - The center to which the map should fly. Must include 'lat' and 'lng' properties.
8-
* @returns {null} Nothing is rendered by this component.
6+
* @param props - Component props.
7+
* @param props.center - The center to which the map should fly. Must include 'lat' and 'lng' properties.
8+
* @returns Nothing is rendered by this component.
99
*/
1010
function RecenterMap({ center }: { center: LatLngExpression }) {
1111
const map = useMap();

‎src/components/userComponents/SiteMap/SiteMap.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ function SiteMap({ mode }: SiteMapProps) {
7171
/**
7272
* This useEffect will manage fetching Data depending on if the chosen map is tours or exhibits.
7373
* It will also manage the initial state of the map when no marker is chosen
74-
*
7574
* It will fetch tours when spotlights == True
7675
*/
7776
async function fetchData() {
@@ -114,6 +113,7 @@ function SiteMap({ mode }: SiteMapProps) {
114113
setSpotlightTours(data ?? []);
115114
}
116115
} catch (error) {
116+
// eslint-disable-next-line no-console
117117
console.error(`Encountered an error fetching data: ${error}`);
118118
} finally {
119119
setLoading(false);

‎src/components/userComponents/SiteMap/TourPreviewCard.tsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ interface TourCardProps {
1313

1414
/**
1515
* Represents a preview card for a tour.
16-
*
17-
* @param {TourRow} tour - The tour data.
18-
* @param {Function} handleClick - The function to call when the card is clicked.
19-
* @param {Function} handleClose - The function to call to close the card.
20-
* @returns {JSX.Element} The component UI.
16+
* @param tour - The tour data.
17+
* @param tour.tour - The tour data.
18+
* @param tour.handleClick - The function to call when the card is clicked.
19+
* @param tour.handleClose - The function to call when the close button is clicked.
20+
* @returns The component UI.
2121
*/
2222
function TourPreviewCard({
2323
tour,
@@ -102,6 +102,15 @@ function TourPreviewCard({
102102
e.stopPropagation();
103103
handleClose();
104104
}}
105+
onKeyDown={e => {
106+
if (e.key === 'Enter' || e.key === ' ') {
107+
e.stopPropagation();
108+
handleClose();
109+
}
110+
}}
111+
role="button"
112+
tabIndex={0}
113+
aria-label="Close preview"
105114
>
106115
<div className="pl-[0.75rem] w-full">
107116
<text className="text-shadow bg-[#F173731A] pr-2 pl-2 rounded-md">

‎src/supabase/category/queries.ts

-46
This file was deleted.

‎src/supabase/category/queries.tsx

+15-36
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,30 @@
1-
'use client';
2-
3-
import { CategoryRow } from '../../types/types';
41
import supabase from '../client';
5-
6-
// eslint-disable-next-line jsdoc/require-returns
7-
/**
8-
*
9-
* @param category_in
10-
*/
11-
// eslint-disable-next-line import/prefer-default-export, camelcase
12-
// export async function get_category_color(category_in: string) {
13-
// const { data, error } = await supabase.rpc('get_category_color', { category_in });
14-
// if (error) {
15-
// // Log the error message for debugging
16-
// console.error(`An error occurred trying to generate color: ${error.message}`);
17-
// // Throw a new error with the message for further handling
18-
// throw new Error(`An error occurred trying to generate color: ${error.message}`);
19-
// }
20-
// return data;
21-
// }
2+
import { CategoryRow } from '../../types/types';
223
// Assume this function is in `supabase/category/queries.js`
234
/**
24-
*
25-
* @param category - The category for which you want to fetch the color
26-
* @returns The color for the category
5+
* @param id - Each tour or exhibit has its unique identifier
6+
* @returns color for category, else null
277
*/
288
// eslint-disable-next-line import/prefer-default-export
29-
export async function getCategoryColor1(category: string) {
9+
export async function getCategoryColor1(id: string | number) {
3010
try {
3111
const { data, error } = await supabase
32-
.from('categories') // Adjust according to your actual table name
33-
.select('color')
34-
.eq('category', category); // Use this if you're sure there's only one entry per category
12+
.from('categories')
13+
.select('color_hex')
14+
.eq('id', id);
3515

3616
if (error) {
37-
throw new Error(error.message);
17+
return null; // Return null on query error
18+
}
19+
20+
// Check if data array is not empty
21+
if (data && data.length > 0 && data[0].color_hex) {
22+
return data[0].color_hex;
3823
}
3924

40-
// Assuming 'color' is the column you want and each category has a unique color.
41-
// 'data' would be the object containing 'color', so we return data.color.
42-
// Check if 'data' exists to avoid accessing property 'color' of null.
43-
console.log(`Color for ${category}:`, data[0].color);
44-
return data ? data[0].color : null;
25+
return null; // Return null if no matching data found
4526
} catch (error) {
46-
console.error(`Error fetching color for category ${category}:`, error);
47-
// Return null or a default color to handle errors gracefully
48-
return null;
27+
return null; // Return null on unexpected error
4928
}
5029
}
5130

0 commit comments

Comments
 (0)
Please sign in to comment.