Skip to content

Commit

Permalink
feat: marshall question response into Question object
Browse files Browse the repository at this point in the history
  • Loading branch information
procaconsul committed Jun 4, 2024
1 parent 0a37b87 commit 23f19d0
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 92 deletions.
15 changes: 12 additions & 3 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"plugins": [
"@trivago/prettier-plugin-sort-imports"
],
"semi": false,
"trailingComma": "es5",
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"printWidth": 100,
"importOrder": ["^[./]"],
"importOrder": [
"^[./]"
],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
"importOrderSortSpecifiers": true,
"importOrderParserPlugins": [
"typescript",
"jsx",
"[\"decorators-legacy\", {\"decoratorsBeforeExport\": true}]"
]
}
175 changes: 88 additions & 87 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/plugin-proposal-decorators": "^7.24.6",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@radix-ui/themes": "^3.0.3",
"@testing-library/jest-dom": "^5.17.0",
Expand Down
9 changes: 7 additions & 2 deletions src/hooks/question.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { plainToInstance } from 'class-transformer'
import { useEffect, useState } from 'react'

import axiosInstance from '../api/axiosInstance'
import routes from '../api/routes'
import { Question } from '../types/exam'

export const useQuestion = (number: number | undefined) => {
const [question, setQuestion] = useState<any>()
const [question, setQuestion] = useState<Question>()
const [questionIsLoaded, setQuestionIsLoaded] = useState(false)
useEffect(() => {
if (number === undefined) return
axiosInstance.get(routes.question(number)).then(console.log)
axiosInstance
.get(routes.question(number))
.then(({ data }) => setQuestion(plainToInstance(Question, data)))
.finally(() => setQuestionIsLoaded(true))
}, [number])
return { question, questionIsLoaded }
}
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Theme, ThemePanel } from '@radix-ui/themes'
import '@radix-ui/themes/styles.css'
import React from 'react'
import ReactDOM from 'react-dom/client'
import 'reflect-metadata'

import App from './App'
import './index.css'
Expand Down
Loading

0 comments on commit 23f19d0

Please sign in to comment.