From 0b5964a6d76ea40a86a05d4afae0fdcf468d1aa2 Mon Sep 17 00:00:00 2001 From: WindowsCrashed Date: Mon, 7 Aug 2023 23:03:13 -0300 Subject: [PATCH] add add question mechanic --- .../pages/assessment/NewAssessmentManual.tsx | 183 ++++-------------- .../assessment/components/QuestionCard.tsx | 33 +++- .../components/SelectedQuestionCard.tsx | 6 +- .../components/SelectedQuestionsSideBar.tsx | 13 +- 4 files changed, 74 insertions(+), 161 deletions(-) diff --git a/app/javascript/pages/assessment/NewAssessmentManual.tsx b/app/javascript/pages/assessment/NewAssessmentManual.tsx index 7aedf74..37b821b 100644 --- a/app/javascript/pages/assessment/NewAssessmentManual.tsx +++ b/app/javascript/pages/assessment/NewAssessmentManual.tsx @@ -1,6 +1,5 @@ import { gql, useQuery } from "@apollo/client"; import React, { useState } from "react"; -import { FaTrash } from "react-icons/fa"; import { Controller, useForm } from "react-hook-form"; import { Axis, Query } from "../../__generated__/graphql-schema"; @@ -8,7 +7,6 @@ import { Button, Card, Input, Navigator } from '../../components'; import { SideBar } from "./components/SideBar"; import { QuestionCard } from "./components/QuestionCard"; import { Link } from "react-router-dom"; -import { SelectedQuestionCard } from "./components/SelectedQuestionCard"; import { SelectedQuestionsSideBar } from "./components/SelectedQuestionsSideBar"; type NewAssessementManualForm = { @@ -30,6 +28,8 @@ export const NewAssessementManual = () => { const { data } = useQuery(NEW_ASSESSEMENT_DATA_QUERY) const axes = data?.axes.nodes + const [questions, setQuestions] = useState<{id: string, label: string}[]>([]) + const [subjectsIds, setSubjectsIds] = useState([]) const { register, control, watch } = useForm({ mode: 'onBlur' @@ -52,6 +52,15 @@ export const NewAssessementManual = () => { const notSelectedAxis: Axis[] = axes.filter((axis) => !subjectsIds.includes(axis.id)) const selectedAxis: Axis[] = axes.filter((axis) => subjectsIds.includes(axis.id)) + const addQuestion = (label: string) => { + const id: string = label.replace(/\s+/g, '') + setQuestions(q => [...q, { id, label }]) + } + + const removeQuestion = (id: string) => { + setQuestions(q => q.filter(i => i.id != id)) + } + return ( <> @@ -60,156 +69,30 @@ export const NewAssessementManual = () => { Filters
{/*bg-blue-500*/} - - - - - - - + + + + + + +
- - - - - - + - // <> - // - //
- // - //
- //

Titulo:

- //
- // - //
- //
- //
- //

Observações:

- //
- // - //
- //
- //
- // - //
- //
- // - // - //
- //
- - //
- // {selectedAxis.map(axis => ( - //
- //
- //
- //
{axis.name}
- //
handleRemoveAxis(axis.id)}>
- //
- //
- // Fácil - // - // {watch(`axisWeights.easy.${axis.id}`) ?? 5} - // - //
- // ( - // - // )} - // /> - - //
- - //
- //
- // Médio - // - // {watch(`axisWeights.medium.${axis.id}`) ?? 5} - // - //
- // ( - // - // )} - // /> - - //
- - //
- //
- // Difícil - // - // {watch(`axisWeights.hard.${axis.id}`) ?? 5} - // - //
- // ( - // - // )} - // /> - - //
- - //
- //
- //
- // ))} - //
- //
- //
- // - // ) } \ No newline at end of file diff --git a/app/javascript/pages/assessment/components/QuestionCard.tsx b/app/javascript/pages/assessment/components/QuestionCard.tsx index 440ddeb..432c8a9 100644 --- a/app/javascript/pages/assessment/components/QuestionCard.tsx +++ b/app/javascript/pages/assessment/components/QuestionCard.tsx @@ -1,13 +1,35 @@ -import React, { FC } from "react"; +import React, { FC, useState } from "react"; import { Button, Card } from "../../../components"; interface Props { title: string + onAddQuestion: Function, + onRemoveQuestion: Function } -export const QuestionCard: FC = ({ title }) => { +export const QuestionCard: FC = ({ title, onAddQuestion, onRemoveQuestion }) => { + const questionId = title.replace(/\s+/g, '') + + const handleAddQuestion = () => { + setButtonState({ + bg: 'bg-red-700', label: 'Remover', method: handleRemoveQuestion + }) + onAddQuestion(title) + } + + const handleRemoveQuestion = () => { + setButtonState({ + bg: '', label: 'Adicionar', method: handleAddQuestion + }) + onRemoveQuestion(questionId) + } + + const [buttonState, setButtonState] = useState({ + bg: '', label: 'Adicionar', method: handleAddQuestion + }) + return ( -
+
@@ -49,8 +71,9 @@ export const QuestionCard: FC = ({ title }) => {

-
diff --git a/app/javascript/pages/assessment/components/SelectedQuestionCard.tsx b/app/javascript/pages/assessment/components/SelectedQuestionCard.tsx index 22f11eb..282a336 100644 --- a/app/javascript/pages/assessment/components/SelectedQuestionCard.tsx +++ b/app/javascript/pages/assessment/components/SelectedQuestionCard.tsx @@ -5,9 +5,10 @@ import { Link } from 'react-router-dom'; type Props = { label: string id: string + onRemoveQuestion: Function } -export const SelectedQuestionCard: FC = ({ label, id }) => { +export const SelectedQuestionCard: FC = ({ label, id, onRemoveQuestion }) => { return (
= ({ label, id }) => {
diff --git a/app/javascript/pages/assessment/components/SelectedQuestionsSideBar.tsx b/app/javascript/pages/assessment/components/SelectedQuestionsSideBar.tsx index e3bf953..a34a1cb 100644 --- a/app/javascript/pages/assessment/components/SelectedQuestionsSideBar.tsx +++ b/app/javascript/pages/assessment/components/SelectedQuestionsSideBar.tsx @@ -1,17 +1,22 @@ import React, { FC, PropsWithChildren } from "react"; import { SideBar } from "./SideBar"; +import { SelectedQuestionCard } from "./SelectedQuestionCard"; -interface Props extends PropsWithChildren { - +type Props = { + questions: {id: string, label: string}[], + onRemoveQuestion: Function } -export const SelectedQuestionsSideBar: FC = ({ children }) => { +export const SelectedQuestionsSideBar: FC = ({ questions, onRemoveQuestion }) => { return (

Questões Selecionadas


- {children ?? + {questions.length ? + questions.map(q => ) :

Nenhuma questão selecionada