From 09f28d0f6a9ad85f3c3920c1c65a4ddf4ca0e238 Mon Sep 17 00:00:00 2001 From: Giorgio Date: Sat, 11 Nov 2023 22:52:13 -1000 Subject: [PATCH] Revamp events and discusssion --- my-app/src/components/events/ProgressBar.jsx | 2 +- my-app/src/pages/event/[_id].jsx | 34 +++--- my-app/src/pages/thread/[_id].jsx | 118 +++++++++++++------ my-app/src/styles/globals.css | 2 +- 4 files changed, 104 insertions(+), 52 deletions(-) diff --git a/my-app/src/components/events/ProgressBar.jsx b/my-app/src/components/events/ProgressBar.jsx index 68c7adc..9129857 100644 --- a/my-app/src/components/events/ProgressBar.jsx +++ b/my-app/src/components/events/ProgressBar.jsx @@ -5,7 +5,7 @@ const ProgressBar = ({ status, setCurrentChecked }) => { const statusIndex = STATUS.indexOf(status); const baseClass = 'step cursor-pointer hover:brightness-110 transition-all'; return ( -
+
  • { const router = useRouter(); @@ -28,20 +30,20 @@ const EventPage = () => { if (loaded) return; if (data) { switch (data.status) { - case "Removal and Storage": - setCurrentStep(1); - break; - case "Sorting": - setCurrentStep(2); - break; - case "Disposal": - setCurrentStep(3); - break; - case "Complete": - setCurrentStep(4); - break; - default: - setCurrentStep(0); + case "Removal and Storage": + setCurrentStep(1); + break; + case "Sorting": + setCurrentStep(2); + break; + case "Disposal": + setCurrentStep(3); + break; + case "Complete": + setCurrentStep(4); + break; + default: + setCurrentStep(0); } setLoaded(true); } @@ -56,6 +58,10 @@ const EventPage = () => { status={data.status} setCurrentChecked={setCurrentStep} /> + + + Discussion +
    { - return
    {label}
    ; + return ( +
    + {label} +
    + ); }; const EventInfo = ({ thread }) => { - const { data: event, error } = useSWR(`/api/mongo/event/id/${thread.eventId}`, fetcher); + const { data: event, error } = useSWR( + `/api/mongo/event/id/${thread.eventId}`, + fetcher + ); if (error) return
    failed to load
    ; if (!event) return ; return ( -
    -

    Event Info

    +
    +
    +

    Event Info

    + + Go to event → + +
    { const _id = router.query._id; - const { data: thread, error } = useSWR(`/api/mongo/thread/id/${_id}`, fetcher, { - refreshInterval: 100, - }); + const { data: thread, error } = useSWR( + `/api/mongo/thread/id/${_id}`, + fetcher, + { + refreshInterval: 100, + } + ); if (error) return
    failed to load
    ; if (!thread) return ; @@ -81,15 +102,24 @@ const ThreadPage = () => { const timestamp = new Date().toISOString(); try { - const response = await fetch(`/api/mongo/thread/send-message/${threadId}`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - message: { authorName, authorEmail, authorOrganization, content, timestamp }, - }), - }); + const response = await fetch( + `/api/mongo/thread/send-message/${threadId}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + message: { + authorName, + authorEmail, + authorOrganization, + content, + timestamp, + }, + }), + } + ); } catch (error) { console.error("Error sending data to API:", error); } @@ -100,9 +130,11 @@ const ThreadPage = () => {
    {message.authorName}
    - +
    -
    {message.content}
    +
    {message.content}
    ); }; @@ -112,21 +144,31 @@ const ThreadPage = () => { return ; } return ( -
    -

    Messages

    - {messages.length ? ( - messages.map((message, index) => ) - ) : ( -
    There are currently no messages
    - )} -
    handleSubmit(e, _id)}> -
    +
    +

    Messages

    +
    + {messages.length ? ( +
    + {messages.map((message, index) => ( + + ))} +
    + ) : ( +
    There are currently no messages
    + )} +
    + handleSubmit(e, _id)} className="w-full"> +
    + -
    @@ -135,13 +177,17 @@ const ThreadPage = () => { if (session) { return ( -
    -

    Thread

    -
    - - -
    -
    + +
    +

    + Discussion +

    +
    + + +
    +
    +
    ); } }; diff --git a/my-app/src/styles/globals.css b/my-app/src/styles/globals.css index 1db71d7..59ac714 100644 --- a/my-app/src/styles/globals.css +++ b/my-app/src/styles/globals.css @@ -11,7 +11,7 @@ } .input-bordered, .select-bordered { - @apply border border-gray-200 rounded-md; + @apply border border-gray-200; } .label-text {