diff --git a/frontend-next/src/components/app/datatypes.js b/frontend-next/src/components/app/datatypes.js index 7100432..343c23d 100644 --- a/frontend-next/src/components/app/datatypes.js +++ b/frontend-next/src/components/app/datatypes.js @@ -27,6 +27,26 @@ let dateOptions = { minute: "2-digit", }; +/** + * Rich Message Formatting + * @param {String} message - Message to Format + * @returns {String} - Formatted Message (IN HTML) + */ +function RMF(message) { + var URLREGEX = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g; + var URLmatch = message.match(URLREGEX); + if (URLmatch) { + for (var i = 0; i < URLmatch.length; i++) { + var link = ( + {message.split(URLmatch[i])[0]} + {URLmatch[i]} + {message.split(URLmatch[i])[1]} + ) + message = link + } + } + return message +} /** * Grabs Window Size * @returns {Object} - Window Size Object (width, height) @@ -51,7 +71,6 @@ export function useWindowSize() { return windowSize; } - /** * Generates Color based on string hash * @param {String} user_str - Username / String for hashing @@ -74,6 +93,7 @@ const generateColor = (user_str) => { * @returns {Object} - Chat Message Component */ export function Chat({ chatObj }) { + var message = RMF(chatObj.body) return (
@@ -84,7 +104,7 @@ export function Chat({ chatObj }) { {chatObj.user} - : {chatObj.body} + : {message}
{new Date(chatObj.timestamp).toLocaleString(dateOptions)} diff --git a/frontend-next/src/components/app/sidebar/home.js b/frontend-next/src/components/app/sidebar/home.js index 15a785c..5f5d04e 100644 --- a/frontend-next/src/components/app/sidebar/home.js +++ b/frontend-next/src/components/app/sidebar/home.js @@ -83,7 +83,6 @@ function classNames(...classes) { * @returns {Object} - App Page Sidebar Component */ export function Sidebar({user,location,loadingLoc}) { - const [tab, setTab] = useState("nearby"); const [nearbyArr, setNearbyArr] = useState([]) const [nearbyArrReady, setNearbyArrReady] = useState(false) // Add myRooms to Sidebar @@ -115,6 +114,8 @@ export function Sidebar({user,location,loadingLoc}) { ); nearbyArr.push(newRoom); } + } else { + nearbyArr.push(
No Nearby Rooms
Create One?
) } setNearbyArr(nearbyArr) setNearbyArrReady(true) @@ -153,13 +154,6 @@ export function Sidebar({user,location,loadingLoc}) {
- {!nearbyArr && !loadingLoc && ( -
- No Nearby Rooms -
- Create One? -
- )} {loadingLoc &&
Loading...
} {nearbyArrReady && nearbyArr}