From 9902e013b2c3ec702154424182ffd6dfd7b121d8 Mon Sep 17 00:00:00 2001 From: AbdBarho Date: Mon, 2 Jan 2023 08:26:33 +0100 Subject: [PATCH 1/4] Use Chakra UI for Messages --- website/src/components/FlaggableElement.tsx | 129 +++++++++----------- website/src/components/Messages.tsx | 18 ++- 2 files changed, 66 insertions(+), 81 deletions(-) diff --git a/website/src/components/FlaggableElement.tsx b/website/src/components/FlaggableElement.tsx index cae24484..c8fc17ce 100644 --- a/website/src/components/FlaggableElement.tsx +++ b/website/src/components/FlaggableElement.tsx @@ -2,6 +2,7 @@ import { Button, Checkbox, Flex, + Grid, Popover, PopoverAnchor, PopoverArrow, @@ -15,6 +16,7 @@ import { SliderTrack, Spacer, useBoolean, + useId, } from "@chakra-ui/react"; import { FlagIcon, QuestionMarkCircleIcon } from "@heroicons/react/20/solid"; import { useState } from "react"; @@ -65,58 +67,47 @@ export const FlaggableElement = (props) => { isLazy lazyBehavior="keepMounted" > -
+ {props.children} - -
+ - -
- -
    - {TEXT_LABEL_FLAGS.map((option, i) => { - return ( - - ); - })} -
-
- -
-
+
+
+ + {TEXT_LABEL_FLAGS.map((option, i) => ( + + ))} + + + + ); }; -function FlagCheckboxLi(props: { +function FlagCheckbox(props: { option: textFlagLabels; idx: number; checkboxValues: boolean[]; @@ -136,37 +127,35 @@ function FlagCheckboxLi(props: { ); } + const id = useId(); + return ( -
  • - - { - props.checkboxHandler(e.target.checked, props.idx); - }} - /> - - - { - props.sliderHandler(val / 100, props.idx); - }} - > - - - - - - -
  • + + { + props.checkboxHandler(e.target.checked, props.idx); + }} + /> + + + { + props.sliderHandler(val / 100, props.idx); + }} + > + + + + + + ); } interface textFlagLabels { diff --git a/website/src/components/Messages.tsx b/website/src/components/Messages.tsx index cc94fcc0..5b77cd26 100644 --- a/website/src/components/Messages.tsx +++ b/website/src/components/Messages.tsx @@ -1,3 +1,4 @@ +import { Grid } from "@chakra-ui/react"; import { FlaggableElement } from "./FlaggableElement"; export interface Message { @@ -10,18 +11,13 @@ const getColor = (isAssistant: boolean) => (isAssistant ? "bg-slate-800" : "bg-s export const Messages = ({ messages, post_id }: { messages: Message[]; post_id: string }) => { const items = messages.map(({ text, is_assistant }: Message, i: number) => { return ( -
    - -
    - {text} -
    -
    -
    + +
    + {text} +
    +
    ); }); // Maybe also show a legend of the colors? - return <>{items}; + return {items}; }; From 65e38009970ef349da9f375f031d65ba99eb69b4 Mon Sep 17 00:00:00 2001 From: Klotske Date: Tue, 3 Jan 2023 00:13:05 +0300 Subject: [PATCH 2/4] Use session for username, removed update handler --- website/src/pages/account/index.tsx | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/website/src/pages/account/index.tsx b/website/src/pages/account/index.tsx index 51f7ed38..c05c2f67 100644 --- a/website/src/pages/account/index.tsx +++ b/website/src/pages/account/index.tsx @@ -6,20 +6,6 @@ import React, { useState } from "react"; export default function Account() { const { data: session } = useSession(); - const [username, setUsername] = useState("null"); - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const handleUpdate = async () => { - const response = await fetch("../api/update", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ username }), - }); - const { name } = await response.json(); - setUsername(name); - }; if (!session) { return; @@ -34,7 +20,7 @@ export default function Account() { />
    -

    {username}

    +

    {session.user.name || "No username"}

    From 15c06348ce977ddb0e1ef212a0600f23da1442b8 Mon Sep 17 00:00:00 2001 From: Klotske Date: Tue, 3 Jan 2023 00:17:32 +0300 Subject: [PATCH 3/4] Removed unused import --- website/src/pages/account/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/pages/account/index.tsx b/website/src/pages/account/index.tsx index c05c2f67..9f8dc4a3 100644 --- a/website/src/pages/account/index.tsx +++ b/website/src/pages/account/index.tsx @@ -2,7 +2,7 @@ import { Button } from "@chakra-ui/react"; import Head from "next/head"; import Link from "next/link"; import { useSession } from "next-auth/react"; -import React, { useState } from "react"; +import React from "react"; export default function Account() { const { data: session } = useSession(); From 47ffd40d383ccde30dbcbbf24106e3218e688e73 Mon Sep 17 00:00:00 2001 From: croumegous Date: Tue, 3 Jan 2023 00:44:07 +0100 Subject: [PATCH 4/4] fix(frontend): fix invalid json error when HTTP response is 204 --- website/src/pages/api/new_task/[task_type].ts | 1 - 1 file changed, 1 deletion(-) diff --git a/website/src/pages/api/new_task/[task_type].ts b/website/src/pages/api/new_task/[task_type].ts index 69548b5f..2a2a0215 100644 --- a/website/src/pages/api/new_task/[task_type].ts +++ b/website/src/pages/api/new_task/[task_type].ts @@ -63,7 +63,6 @@ const handler = async (req, res) => { message_id: registeredTask.id, }), }); - await ackRes.json(); // Send the results to the client. res.status(200).json(registeredTask);