Skip to content

Commit

Permalink
refactor: arrange utils into dedicated directory
Browse files Browse the repository at this point in the history
  • Loading branch information
procaconsul committed Jun 12, 2024
1 parent d6ac5b2 commit 61c5502
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/components/questionStructure/Part.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box, Button, Card, Em, Flex, Heading, Separator, Text } from '@radix-ui/themes'
import React, { FC, ReactNode } from 'react'

import { numberToLetter } from '../../utils'
import { numberToLetter } from '../../utils/common'
import Markdown from '../Markdown'

interface PartProps {
Expand Down
2 changes: 1 addition & 1 deletion src/components/questionStructure/Section.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Flex, Grid, Strong, Text } from '@radix-ui/themes'
import React, { FC, ReactNode } from 'react'

import { numberToRoman } from '../../utils'
import { numberToRoman } from '../../utils/common'
import Markdown from '../Markdown'

interface SectionProps {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/exam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react'
import axiosInstance from '../api/axiosInstance'
import routes from '../api/routes'
import { Answer, Question, QuestionAnswersLookup } from '../types/exam'
import { buildAnswerLookupTable } from '../utils'
import { buildAnswerLookupTable } from '../utils/answers'

export const useQuestion = (number: number | undefined) => {
const [question, setQuestion] = useState<Question>()
Expand Down
2 changes: 1 addition & 1 deletion src/tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { numberToLetter, numberToRoman } from '../utils'
import { numberToLetter, numberToRoman } from '../utils/common'

describe('numberToLetter', () => {
test.each([
Expand Down
2 changes: 1 addition & 1 deletion src/types/exam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Transform, Type } from 'class-transformer'
import { addMinutes } from 'date-fns'

import { TaskType } from '../components/questionStructure/Task/constants'
import { stringToEnumValue } from './utils'
import { stringToEnumValue } from '../utils/types'

export class MCQOption {
value: string
Expand Down
14 changes: 14 additions & 0 deletions src/utils/answers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { reduce, set } from 'lodash'

import { Answer } from '../types/exam'

export function buildAnswerLookupTable(answers: Answer[]) {
return reduce(
answers,
(res, { question, part, section, task, answer }) => {
set(res, [question, part, section, task], answer)
return res
},
{}
)
}
15 changes: 0 additions & 15 deletions src/utils.ts → src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { reduce, set } from 'lodash'

import { Answer } from './types/exam'

const ASCII_LOWERCASE_OFFSET = 96

export function numberToLetter(num: number): string {
Expand Down Expand Up @@ -38,14 +34,3 @@ export function numberToRoman(num: number): string {
return result + numeral.repeat(repeatCount)
}, '')
}

export function buildAnswerLookupTable(answers: Answer[]) {
return reduce(
answers,
(res, { question, part, section, task, answer }) => {
set(res, [question, part, section, task], answer)
return res
},
{}
)
}
File renamed without changes.

0 comments on commit 61c5502

Please sign in to comment.