add questions query

This commit is contained in:
WindowsCrashed
2023-08-25 22:33:33 -03:00
parent 147fb997d0
commit 230a59e999
4 changed files with 78 additions and 25 deletions

View File

@@ -4,15 +4,60 @@ import { SelectedQuestionsSideBar } from "./components/SelectedQuestionsSideBar"
import { FiltersSideBar } from "./components/FiltersSideBar"; import { FiltersSideBar } from "./components/FiltersSideBar";
import { BottomBar } from "./components/BottomBar"; import { BottomBar } from "./components/BottomBar";
import { QuestionArea } from "./components/QuestionArea"; import { QuestionArea } from "./components/QuestionArea";
import { gql, useQuery } from "@apollo/client";
import { Query, Question } from "../../__generated__/graphql-schema";
const QuestionFragments = gql`
fragment QuestionFields on Question {
id
authorship
authorshipYear
bloomTaxonomy
body
checkType
difficulty
status
subject {
axis {
name
}
category {
name
}
name
}
}
`
const QUESTIONS_QUERY = gql`
${QuestionFragments}
query {
questions {
nodes {
...QuestionFields
}
}
}
`
export const NewAssessementManual = () => { export const NewAssessementManual = () => {
const [questions, setQuestions] = useState([ // const [questions, setQuestions] = useState([
"Question 1", "Question 2", "Question 3", "Question 4", // "Question 1", "Question 2", "Question 3", "Question 4",
"Question 5", "Question 6", "Question 7"]) // "Question 5", "Question 6", "Question 7"])
const [questions, setQuestions] = useState<Question[]>([])
const [selectedQuestions, setSelectedQuestions] = useState<{id: string, label: string, removeHandler: Function}[]>([]) const [selectedQuestions, setSelectedQuestions] = useState<{id: string, label: string, removeHandler: Function}[]>([])
const { fetchMore } = useQuery<Query>(QUESTIONS_QUERY, {
onCompleted: (respose) => {
const { questions: questionConnection } = respose
setQuestions(questionConnection.nodes as Question[])
console.log(respose)
},
fetchPolicy: "network-only"
})
const addQuestion = (label: string, removeHandler: Function) => { const addQuestion = (label: string, removeHandler: Function) => {
const id: string = label.replace(/\s+/g, '') const id: string = label.replace(/\s+/g, '_')
if (!selectedQuestions.find(q => q.id === id)) { if (!selectedQuestions.find(q => q.id === id)) {
setSelectedQuestions(q => [...q, { id, label, removeHandler }]) setSelectedQuestions(q => [...q, { id, label, removeHandler }])
} }
@@ -26,6 +71,8 @@ export const NewAssessementManual = () => {
setSelectedQuestions([]) setSelectedQuestions([])
} }
fetchMore({})
return ( return (
<> <>
<Navigator home /> <Navigator home />

View File

@@ -1,8 +1,9 @@
import React, { FC } from "react"; import React, { FC } from "react";
import { QuestionCard } from "./QuestionCard"; import { QuestionCard } from "./QuestionCard";
import { Question } from "../../../__generated__/graphql-schema";
interface Props { interface Props {
questions: string[] questions: Question[]
onAddQuestion: Function, onAddQuestion: Function,
onRemoveQuestion: Function onRemoveQuestion: Function
} }
@@ -11,7 +12,7 @@ export const QuestionArea: FC<Props> = ({ questions, onAddQuestion, onRemoveQues
return ( return (
<div className="col-span-3 border-l-2 border-r-2 border-gray-300 px-6"> <div className="col-span-3 border-l-2 border-r-2 border-gray-300 px-6">
{questions.map(question => {questions.map(question =>
<QuestionCard title={question} <QuestionCard key={question.id} question={question}
onAddQuestion={onAddQuestion} onAddQuestion={onAddQuestion}
onRemoveQuestion={onRemoveQuestion}/>)} onRemoveQuestion={onRemoveQuestion}/>)}
</div> </div>

View File

@@ -1,18 +1,24 @@
import React, { FC, useState } from "react"; import React, { FC, useState } from "react";
import { Button, Card } from "../../../components"; import { Button, Card } from "../../../components";
import { QuestionCardField } from "./QuestionCardField"; import { QuestionCardField } from "./QuestionCardField";
import { Question } from "../../../__generated__/graphql-schema";
import { NodeId } from "../../../utils/graphql";
import { BLOOM_TAXONOMY, CHECK_TYPE, DIFFICULTY } from "../../../utils/types";
interface Props { interface Props {
title: string question: Question
onAddQuestion: Function, onAddQuestion: Function,
onRemoveQuestion: Function onRemoveQuestion: Function
} }
export const QuestionCard: FC<Props> = ({ title, onAddQuestion, onRemoveQuestion }) => { export const QuestionCard: FC<Props> = ({ question, onAddQuestion, onRemoveQuestion }) => {
const [collapsed, setCollapsed] = useState(false) const [collapsed, setCollapsed] = useState(false)
const questionId = title.replace(/\s+/g, '') const title = `Questão ${NodeId.decode(question.id).id}`
const difficulty = DIFFICULTY.find(item => item.value === question.difficulty)?.label
const bloomTaxonomy = BLOOM_TAXONOMY.find(item => item.value === question.bloomTaxonomy)?.label
const checkType = CHECK_TYPE.find(item => item.value === question.checkType)?.label
const handleAddQuestion = () => { const handleAddQuestion = () => {
setButtonState({ setButtonState({
bg: 'bg-red-700', label: 'Remover', method: handleRemoveQuestion bg: 'bg-red-700', label: 'Remover', method: handleRemoveQuestion
@@ -24,7 +30,7 @@ export const QuestionCard: FC<Props> = ({ title, onAddQuestion, onRemoveQuestion
setButtonState({ setButtonState({
bg: '', label: 'Adicionar', method: handleAddQuestion bg: '', label: 'Adicionar', method: handleAddQuestion
}) })
onRemoveQuestion(questionId) onRemoveQuestion(question.id)
} }
const [buttonState, setButtonState] = useState({ const [buttonState, setButtonState] = useState({
@@ -32,23 +38,21 @@ export const QuestionCard: FC<Props> = ({ title, onAddQuestion, onRemoveQuestion
}) })
return ( return (
<div id={questionId}> <div id={title.replace(/\s+/g, '_')}>
<Card title={title} className="mb-5"> <Card title={title} className="mb-5">
<div> <div>
{!collapsed && <div className="grid grid-cols-2 gap-2"> {!collapsed && <div className="grid grid-cols-2 gap-2">
<QuestionCardField label="Grau de Dificuldade" value="Média"/> <QuestionCardField label="Grau de Dificuldade" value={difficulty}/>
<QuestionCardField label="Categoria" value="Modelagem"/> <QuestionCardField label="Categoria" value={question.subject?.category.name}/>
<QuestionCardField label="Eixo de Formação" value="Infra Sistemas"/> <QuestionCardField label="Eixo de Formação" value={question.subject?.axis.name}/>
<QuestionCardField label="Assunto" value="Fisica"/> <QuestionCardField label="Assunto" value={question.subject?.name}/>
<QuestionCardField label="Habilidade Cognitiva" value="Compreender"/> <QuestionCardField label="Habilidade Cognitiva" value={bloomTaxonomy}/>
<QuestionCardField label="Tipo" value="Resposta Multipla"/> <QuestionCardField label="Tipo" value={checkType}/>
<QuestionCardField label="Autoria" value="UNIFESO" /> <QuestionCardField label="Autoria" value={question.authorship} />
<QuestionCardField label="Ano" value="2023"/> <QuestionCardField label="Ano" value={question.authorshipYear}/>
<div className="col-span-2"> <div className="col-span-2">
<span className="text-gray-700">Enunciado:</span> <span className="text-gray-700">Enunciado:</span>
<div> <div dangerouslySetInnerHTML={{__html: question.body ?? ''}}></div>
ijodsjidsoifidfsiojsdfiojdsfiodfs ijdf iodsf iosd iojdf sijodsf iojdsf ioj sdfiojdf sioj dfsiojsdf iojdfs ijodsfijoidfsijodfsijdfsijo dsiofd ijosdfjiofdsidsfio
</div>
</div> </div>
</div>} </div>}
<div className="mt-6"> <div className="mt-6">

View File

@@ -1,15 +1,16 @@
import React, { FC } from "react"; import React, { FC } from "react";
import { Maybe } from "../../../__generated__/graphql-schema";
interface Props { interface Props {
label: string, label: string,
value: string value?: Maybe<string>
} }
export const QuestionCardField: FC<Props> = ({ label, value }) => { export const QuestionCardField: FC<Props> = ({ label, value }) => {
return ( return (
<div> <div>
<span className="text-gray-700">{`${label}: `}</span> <span className="text-gray-700">{`${label}: `}</span>
<span>{value}</span> <span>{value ?? ''}</span>
</div> </div>
) )
} }