-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provisioning for fitted points and centralized message handler #2
- Loading branch information
1 parent
1a81272
commit 4193a63
Showing
18 changed files
with
457 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import { FaTimes } from 'react-icons/fa'; | ||
import { useMessage } from './messageContext'; // Adjust the path | ||
|
||
const MessageBox = () => { | ||
const { message, messageType, showMessage, setShowMessage } = useMessage(); | ||
|
||
if (!showMessage || !message) return null; // Don't show the box if there's no message | ||
|
||
const getBackgroundColor = () => { | ||
switch (messageType) { | ||
case 'success': | ||
return '#dff0d8'; // Light green | ||
case 'error': | ||
return '#f2dede'; // Light red | ||
case 'warning': | ||
return '#fcf8e3'; // Light yellow | ||
default: | ||
return '#f5f5f5'; // Default (grayish) | ||
} | ||
}; | ||
|
||
const getTextColor = () => { | ||
switch (messageType) { | ||
case 'success': | ||
return '#3c763d'; // Dark green | ||
case 'error': | ||
return '#a94442'; // Dark red | ||
case 'warning': | ||
return '#8a6d3b'; // Dark yellow | ||
default: | ||
return '#333'; // Default dark gray | ||
} | ||
}; | ||
|
||
return ( | ||
<div | ||
style={{ | ||
backgroundColor: getBackgroundColor(), | ||
color: getTextColor(), | ||
padding: '15px', | ||
borderRadius: '5px', | ||
marginBottom: '20px', | ||
textAlign: 'center', | ||
position: 'relative' | ||
}} | ||
> | ||
<FaTimes | ||
onClick={() => setShowMessage(false)} // Hide the message on clicking | ||
style={{ | ||
position: 'absolute', | ||
right: '10px', | ||
top: '10px', | ||
cursor: 'pointer', | ||
}} | ||
/> | ||
|
||
{message} | ||
</div> | ||
); | ||
}; | ||
|
||
export default MessageBox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { createContext, useState, useContext } from 'react'; | ||
|
||
// Create the context | ||
const MessageContext = createContext(); | ||
|
||
// Create a provider component | ||
export const MessageProvider = ({ children }) => { | ||
const [message, setMessage] = useState(''); // Message content | ||
const [messageType, setMessageType] = useState(''); // 'error', 'success', 'warning' | ||
const [showMessage, setShowMessage] = useState(false); // New state to control visibility | ||
|
||
|
||
// Function to set a message | ||
const setMessageInfo = (type, content) => { | ||
setMessage(content); | ||
setMessageType(type); | ||
setShowMessage(true); | ||
|
||
// Optional: Clear the message automatically after a timeout | ||
setTimeout(() => { | ||
setShowMessage(false); | ||
setMessage(''); | ||
setMessageType(''); | ||
}, 5000); // 5 seconds | ||
}; | ||
|
||
return ( | ||
<MessageContext.Provider value={{ message, messageType, showMessage, setMessageInfo, setShowMessage }}> | ||
{children} | ||
</MessageContext.Provider> | ||
); | ||
}; | ||
|
||
// Create a hook to consume the context easily | ||
export const useMessage = () => useContext(MessageContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
export const fitGcps = async (api, widgets, setWidgets, setMessageInfo) => { | ||
|
||
// temporary test function; | ||
const updateWidgets = () => { | ||
setWidgets((prevWidgets) => | ||
prevWidgets.map((widget) => ({ | ||
...widget, | ||
fit: {"row": 1075, "col": 1915}, | ||
})) | ||
); | ||
}; | ||
try { | ||
// Checks! | ||
if (widgets.length < 0) { | ||
const msg = `Too few GCPs (${widgets.length} / 6)` | ||
setMessageInfo('error', msg); | ||
// throw new Error(msg); | ||
} | ||
|
||
// Extract coordinates into separated lists | ||
const src = widgets.map(({ coordinates }) => [ | ||
parseFloat(coordinates.x) || 0, | ||
parseFloat(coordinates.y) || 0, | ||
coordinates.z === '' || isNaN(Number(coordinates.z)) ? NaN : parseFloat(coordinates.z) | ||
]); | ||
|
||
const dst = widgets.map(({ coordinates }) => [ | ||
parseFloat(coordinates.row, 10) || 0, | ||
parseFloat(coordinates.col, 10) || 0, | ||
]); | ||
|
||
const payload = { | ||
"src": src, | ||
"dst": dst, | ||
}; | ||
|
||
console.log('Sending payload:', payload); | ||
updateWidgets(); | ||
console.log(widgets); | ||
// // Send data to API endpoint | ||
// const response = await api.post('https://api.example.com/endpoint', payload); | ||
// console.log('API Response:', response.data); | ||
|
||
} catch (error) { | ||
console.error('Failed to send coordinates:', error); | ||
// Optionally, handle errors (e.g., display an error message) | ||
} | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import L from "leaflet"; // Import Leaflet for DivIcon | ||
|
||
// Function to create a custom DivIcon with dynamic RGBA colors | ||
export const createCustomMarker = (color) => { | ||
|
||
return L.divIcon({ | ||
className: "custom-marker", // Base class (can use CSS for additional styles) | ||
html: `<div style=" | ||
background-color: ${color}; | ||
width: 1.5rem; | ||
height: 1.5rem; | ||
left: -0.75rem; | ||
top: -0.75rem; | ||
transform: rotate(45deg); | ||
border-radius: 1.5rem 1.5rem 0; | ||
alignItems: center; | ||
justify-content: center; | ||
border: 1px solid rgba(0, 0, 0, 0.5); | ||
color: white | ||
"><div style='transform: rotate(-45deg)'>1</div></div>`, | ||
iconSize: [30, 30], // Marker size | ||
iconAnchor: [15, 15], // Position the icon properly | ||
popupAnchor: [0, -20], // Adjust popup anchor relative to marker | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.