Skip to content

Commit 7e9eff6

Browse files
authored
Merge pull request #60 from UTSC-CSCC01-Software-Engineering-I/updates
Updates
2 parents 6e58393 + 73f9b8c commit 7e9eff6

2 files changed

Lines changed: 45 additions & 23 deletions

File tree

frontend/src/components/MapComponent.jsx

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -191,34 +191,58 @@ export default function MapComponent() {
191191
const t = item.temp || item.Result;
192192
const name = item.siteName || item.Label || `User Point ${i + 1}`;
193193

194-
// Get current unit and format temperature
194+
// determine age (fallback to createdAt for user‐points)
195+
const rawTime = item.timestamp || item.createdAt || item.created_at;
196+
const ts = new Date(rawTime).getTime();
197+
const isStale = !isNaN(ts) && (Date.now() - ts) > 2 * 24 * 60 * 60 * 1000; // older than 2 days
198+
195199
const currentUnit = UnitManager.getUnit();
196200
const formattedTemp = formatTemperature(t, currentUnit);
197-
const tempColor = getAccessibleTemperatureColor(t, 'C'); // Use accessible color function
201+
const tempColor = getAccessibleTemperatureColor(t, 'C');
198202
const tempCategory = getTemperatureCategory(t);
199-
const tempSymbol = getTemperatureSymbol(t);
200203

201-
console.log(`Plotting [${i}]: ${name} @ ${lat},${lon} = ${formattedTemp}`);
204+
// outline for stale, grey text for stale
205+
const outlineStyle = isStale ? 'border: 2px solid grey;' : '';
206+
const valueColor = isStale ? 'color: grey;' : '';
207+
208+
// determine stale styling
209+
const bgColor = isStale ? '#ffffff20' : tempColor;
210+
const staleFilter = isStale
211+
? 'backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);'
212+
: '';
202213

203214
const icon = L.divIcon({
204215
className: 'custom-temp-marker',
205216
html: `
206217
<div
207-
class="temp-label accessible-marker"
208-
style="background-color: ${tempColor};"
218+
class="temp-label accessible-marker${isStale ? ' stale' : ''}"
219+
style="
220+
background-color: ${bgColor};
221+
${outlineStyle}
222+
${staleFilter}
223+
"
209224
role="button"
210225
tabindex="0"
211-
aria-label="Water temperature ${formattedTemp} at ${name}. Category: ${tempCategory}. Press Enter or Space to view details."
212-
data-temp-category="${tempCategory.toLowerCase().replace(' ', '-')}"
226+
aria-label="Water temperature ${formattedTemp} at ${name}. ${isStale ? 'Data older than 2 days.' : `Category: ${tempCategory}. Press Enter or Space to view details.`}"
227+
data-temp-category="${tempCategory.toLowerCase().replace(/ /g,'-')}"
213228
>
214-
<span class="temp-value">${formattedTemp}</span>
229+
<span class="temp-value" style="${valueColor}">${formattedTemp}</span>
215230
</div>
216231
`,
217-
iconSize: [50, 40], // Slightly larger for better touch targets
232+
iconSize: [50, 40],
218233
iconAnchor: [25, 20],
219234
});
220235

221-
const marker = L.marker([lat, lon], { icon }).addTo(map);
236+
const marker = L.marker([lat, lon], { icon }).addTo(mapInstanceRef.current);
237+
238+
// bump this marker to the top on hover
239+
marker.on('mouseover', () => {
240+
marker.setZIndexOffset(1000);
241+
});
242+
// reset when mouse leaves
243+
marker.on('mouseout', () => {
244+
marker.setZIndexOffset(0);
245+
});
222246

223247
// Add function to announce to screen readers (this was missing)
224248
function announceToScreenReader(message) {
@@ -240,24 +264,17 @@ export default function MapComponent() {
240264

241265
// Add click handler FIRST (this is the main functionality)
242266
marker.on('click', async () => {
243-
console.log('Marker clicked:', name); // Debug log
244-
245-
// Announce to screen readers
246-
try {
247-
announceToScreenReader(`Viewing details for ${name} with water temperature ${formattedTemp}`);
248-
} catch (e) {
249-
console.log('Screen reader announcement failed:', e);
250-
}
267+
// add prefix for grey (stale) points
268+
const labelPrefix = isStale ? '<strong>OLD:</strong> ' : '';
251269

252270
const historicalData = await fetchHistoricalData(name);
271+
const popupOffset = [17, -32];
253272

254-
// add once at top of click‐handler so you can reuse
255-
const popupOffset = [17, -32]; // x=0 (center), y=−45px (above marker)
256-
273+
// no historical data
257274
if (historicalData.length === 0) {
258275
marker.bindPopup(`
259276
<div role="dialog" aria-labelledby="popup-title-${i}">
260-
<h3 id="popup-title-${i}">${name}</h3>
277+
<h3 id="popup-title-${i}">${labelPrefix}${name}</h3>
261278
<p>No historical data available</p>
262279
<p>Current temperature: ${formattedTemp} (${tempCategory})</p>
263280
</div>

frontend/src/styles/MapView.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,8 @@
280280
max-height: 60vh !important;
281281
}
282282
}
283+
284+
/* at the end of the file, override any data-temp-category borders on stale points */
285+
.temp-label.stale {
286+
border-left: none !important;
287+
}

0 commit comments

Comments
 (0)