Skip to content

Commit

Permalink
Merge branch 'main' into 20-threads
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandeJames committed Nov 9, 2023
2 parents 01cd511 + 02f0113 commit 7235d59
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 131 deletions.
28 changes: 23 additions & 5 deletions my-app/src/components/chatbot/DialogflowChatWidget.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { useEffect } from 'react';
import { useEffect, useState } from 'react';

const DialogflowChatWidget = () => {
const [scrollDirection, setScrollDirection] = useState(null);

useEffect(() => {
let lastScrollY = window.pageYOffset;

const updateScrollDirection = () => {
const scrollY = window.pageYOffset;
const direction = scrollY > lastScrollY ? "down" : "up";
if (direction !== scrollDirection && (scrollY - lastScrollY > 10 || scrollY - lastScrollY < -10)) {
setScrollDirection(direction);
}
lastScrollY = scrollY > 0 ? scrollY : 0;
};
window.addEventListener("scroll", updateScrollDirection); // add event listener

if (typeof window !== 'undefined' && !window.dialogflowMessengerLoaded) {
window.dialogflowMessengerLoaded = true;

Expand All @@ -27,8 +41,9 @@ const DialogflowChatWidget = () => {
};

document.body.appendChild(script);
return () => window.removeEventListener("scroll", updateScrollDirection); // remove event listener
}
}, []);
}, [scrollDirection]);

const dfMessengerColors = {
textColor:'#fff',
Expand All @@ -45,8 +60,9 @@ const DialogflowChatWidget = () => {
};

return (
<style>
{`
<div>
<style>
{`
:root {
--df-messenger-font-family: Helvetica Neue, Helvetica, sans-serif;
--df-messenger-primary-color: ${dfMessengerColors.primaryColor};
Expand Down Expand Up @@ -95,7 +111,9 @@ const DialogflowChatWidget = () => {
--df-messenger-chat-bubble-background: ${dfMessengerColors.primaryColorHover};
}
`}
</style>
</style>
<div id="chatContainer" className={`fixed ${ scrollDirection === "down" ? "-bottom-24" : "md:bottom-0 bottom-14"} right-4 h-20 transition-all duration-500`}></div>
</div>
);
};

Expand Down
46 changes: 26 additions & 20 deletions my-app/src/components/events/EventReported.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import EventCollapse from "./common/EventCollapse";
import DispatchTeamBtn from "./event-reported/DispatchTeamBtn";
import DismissBtn from "./event-reported/DismissBtn";
import StaticMap from "../map/StaticLocationMap/StaticMap";
import { prettyHstDate } from "@/utils/dateConverter";

const EventRemoval = ({ event }) => {
const { data: session } = useSession();
Expand All @@ -12,36 +13,39 @@ const EventRemoval = ({ event }) => {
<div className="p-3 bg-base-100 rounded-xl">
<header>
<div className="flex flex-col md:flex-row justify-between">
<h3 className="font-bold md:text-2xl">Event ID: {event._id}</h3>
<time className="font-bold md:text-2xl">
Date Reported: {event.reportedDate.toLocaleString("en-US")}
<h3 className="font-bold md:text-xl">Event ID: {event._id}</h3>
<time className="font-bold md:text-xl">
Date Reported: {prettyHstDate(event.reportedDate)}
</time>
</div>
</header>
<section className="py-3">
<div className="flex flex-col md:flex-row gap-x-12">
<div className="w-full md:w-1/2 h-96 bg-primary-content flex justify-center items-center rounded-md my-3">
{/* <div className="text-base-100">THIS IS WHERE MAP GOES</div> */}
<StaticMap latitude={event.mapLat} longitude={event.mapLong} />
{event.mapLat && event.mapLong ? (
<StaticMap latitude={event.mapLat} longitude={event.mapLong} />
) : (
<div className="text-base-100">No coordinates found.</div>
)}
</div>
<div className="w-full md:w-1/2 flex flex-col gap-x-12">
<section className="w-full md:w-1/2">
<section className="w-full md:w-3/4">
<h2 className="font-bold text-2xl">Location</h2>
<div className="flex justify-between">
<p>Longitude: </p>
<p>{event.mapLong}</p>
<p>{event.mapLong ?? "-"}</p>
</div>
<div className="flex justify-between">
<p>Latitude: </p>
<p>{event.mapLat}</p>
<p>{event.mapLat ?? "-"}</p>
</div>
<div className="flex justify-between">
<p>Island: </p>
<p>{event.closestIsland}</p>
<p>{event.closestIsland ?? "-"}</p>
</div>
</section>
<section className="w-full md:w-1/2">
<h2 className="font-bold text-2xl">Contact Information</h2>
<section className="w-full md:w-3/4">
<h2 className="font-bold md:text-2xl">Contact Information</h2>
<div className="flex justify-between">
<p>Email: </p>
<p>{event.publicContact.email}</p>
Expand All @@ -65,18 +69,20 @@ const EventRemoval = ({ event }) => {
<div className="w-full md:w-1/2">
<h2 className="text-2xl font-bold">Information</h2>
<ul className="list-disc pl-4 overflow-auto">
<li className="break-words">{event.publicType}</li>
<li className="break-words">{event.publicLocationDesc}</li>
<li className="break-works">{event.publicDebrisEnvDesc}</li>
<li className="break-words">
{event.publicType && (
<li className="break-words">Type: {event.publicType}</li>
)}
{event.publicLocationDesc && <li className="break-words">{event.publicLocationDesc}</li>}
{event.publicDebrisEnvDesc && <li className="break-works">{event.publicDebrisEnvDesc}</li>}
{event.publicBiofoulingRating && (<li className="break-words">
Biofouling Rating - {event.publicBiofoulingRating}
</li>
<li className="break-words">
</li>)}
{event.publicContainerFullness && (<li className="break-words">
Container Fullness - {event.publicContainerFullness}
</li>
<li className="break-words">
</li>)}
{event.publicClaimBoat && (<li className="break-words">
Contact claims boat - {event.publicClaimBoat}
</li>
</li>)}
</ul>
</div>
<div className="w-full md:w-1/2 h-96 bg-primary-content rounded-md flex items-center justify-center text-base-100 py-3">
Expand Down
2 changes: 1 addition & 1 deletion my-app/src/components/events/RemovalAndStorage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const RemovalAndStorage = ({ event, userOrgId }) => {
{STATUS.indexOf(event.status) <= 1 ? (
<MarkAsCompleteBtn eventId={event._id} nextStatus={STATUS[2]} />
) : (
<UndoStepBtn eventId={event._id} prevStatus={STATUS[1]} />
<UndoStepBtn eventId={event._id} prevStatus={STATUS[0]} />
)}
</section>
)}
Expand Down
1 change: 1 addition & 0 deletions my-app/src/components/events/common/UndoStepBtn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const UndoStepBtn = ({ eventId, prevStatus }) => {
},
body: JSON.stringify({
status: prevStatus,
removalOrgId: null,
}),
});
if (res.ok) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { STATUS } from "@/constants/constants";

const DispatchTeamBtn = ({ userOrgId, eventId }) => {
async function dispatchTeam() {
console.log("userOrgId", userOrgId);
console.log("eventId", eventId);
try {
const res = await fetch(`/api/mongo/event/id/${eventId}`, {
method: "PUT",
Expand All @@ -11,12 +15,11 @@ const DispatchTeamBtn = ({ userOrgId, eventId }) => {
status: STATUS[1],
}),
});
if (res.status === 200) {
if (res.ok) {
console.log("Successfully dispatched team");
} else {
throw new Error("Failed to dispatch team");
}
} catch (err) {
console.log(err);
console.log("Failed to dispatch team");
}
}
Expand Down
2 changes: 1 addition & 1 deletion my-app/src/models/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const eventSchema = new mongoose.Schema({
type: String,
},
removalOrgId: {
type: String,
type: mongoose.Schema.Types.ObjectId,
trim: true,
},
removalStartDate: {
Expand Down
26 changes: 1 addition & 25 deletions my-app/src/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,9 @@ import { ToastContainer } from "react-toastify";
import DialogflowChatWidget from "@/components/chatbot/DialogflowChatWidget";
import "@/styles/globals.css";
import 'react-toastify/dist/ReactToastify.css';
import {useEffect, useState} from "react";


const App = ({ Component, pageProps: { session, ...pageProps } }) => {
const [scrollDirection, setScrollDirection] = useState(null);

useEffect(() => {
let lastScrollY = window.pageYOffset;

const updateScrollDirection = () => {
const scrollY = window.pageYOffset;
const direction = scrollY > lastScrollY ? "down" : "up";
if (direction !== scrollDirection && (scrollY - lastScrollY > 10 || scrollY - lastScrollY < -10)) {
setScrollDirection(direction);
}
lastScrollY = scrollY > 0 ? scrollY : 0;
};
window.addEventListener("scroll", updateScrollDirection); // add event listener
return () => {
window.removeEventListener("scroll", updateScrollDirection); // clean up
}
}, [scrollDirection]);

console.log(scrollDirection)

return (
<>
<SessionProvider session={session}>
Expand All @@ -40,9 +18,7 @@ const App = ({ Component, pageProps: { session, ...pageProps } }) => {
</div>
<MobileNavbar />
<ToastContainer />
<div id="chatContainer" className={`fixed ${ scrollDirection === "down" ? "-bottom-24" : "md:bottom-0 bottom-14"} right-4 h-20 transition-all duration-500`}>
<DialogflowChatWidget/>
</div>
<DialogflowChatWidget/>
</div>
</SessionProvider>
</>
Expand Down
File renamed without changes.
Loading

0 comments on commit 7235d59

Please sign in to comment.