Skip to content

Commit

Permalink
fix: 修复依赖缺失错误
Browse files Browse the repository at this point in the history
  • Loading branch information
GaoNeng-wWw committed Aug 16, 2024
1 parent eafd78e commit 7e02274
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/(root)/survey/components/FillBlank.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Space, Textarea } from '@mantine/core';
import React, { useRef } from 'react';
import { InputProps } from '@/app/survey/components/generateQuestion';
import type { InputProps } from './generateQuestion';

export function FillBlank(proos: InputProps) {
const ref = useRef<HTMLTextAreaElement>(null);
Expand Down
18 changes: 6 additions & 12 deletions app/(root)/survey/components/SingleChoice.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useState } from 'react';
import { Group, Radio, Stack, Text } from '@mantine/core';
import { Group, Radio, Space, Stack, Text } from '@mantine/core';
import classes from './SingleChoice.module.css';
import type { Value } from './generateQuestion';
import type { InputProps, Value } from './generateQuestion';

export function SingleChoice(props: ChoiceProps) {
const [value, setValue] = useState<string | null>(null);
const data = props.choice;

const cards = data.map(({ title, content }, index) => (
Expand All @@ -22,23 +20,19 @@ export function SingleChoice(props: ChoiceProps) {
return (
<>
<Radio.Group
value={value}
onChange={setValue}
label="Pick one option"
description="Choose an option"
value={props.value}
onChange={props.setValue}
>
<Stack pt="md" gap="xs">
{cards}
</Stack>
</Radio.Group>

<Text fz="xs" mt="md">
CurrentValue: {value || '–'}
</Text>
<Space h={40} />
</>
);
}

export interface ChoiceProps {
export interface ChoiceProps extends InputProps {
choice: Value[];
}
17 changes: 13 additions & 4 deletions app/(root)/survey/components/generateQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@ import { MultipleChoice } from './MultipleChoice';
import { FileUpload } from './FileUpload';
import { FillBlank } from './FillBlank';

export function generateQuestion(data: QuestionProps) {
export function generateQuestion(
data: QuestionProps,
value: string | undefined,
setValue: (value: string) => void
) {
switch (data.type) {
case 1:
return (
<div key={data.id}>
<Title order={3}>{`${data.content.title}`}</Title>
<p>{data.content.content}</p>
<FillBlank />
<FillBlank value={value} setValue={setValue} />
</div>
);
case 2:
return (
<div key={data.id}>
<Title order={3}>{`${data.content.title}`}</Title>
<p>{data.content.content}</p>
<SingleChoice choice={data.values} />
<SingleChoice choice={data.values} value={value} setValue={setValue} />
</div>
);
case 3:
return (
<div key={data.id}>
<Title order={3}>{`${data.content.title}`}</Title>
<p>{data.content.content}</p>
<MultipleChoice choice={data.values} />
<MultipleChoice choice={data.values} value={value} setValue={setValue} />
</div>
);
case 4:
Expand Down Expand Up @@ -60,3 +64,8 @@ export interface Value {
content: string
title: string
}

export interface InputProps {
value: string | undefined,
setValue: (value: string) => void,
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"test": "npm run prettier:check && npm run lint && npm run typecheck && npm run jest"
},
"dependencies": {
"@floating-ui/utils": "^0.2.7",
"@mantine/core": "7.12.1",
"@mantine/hooks": "7.12.1",
"@mantine/notifications": "^7.12.1",
Expand Down

0 comments on commit 7e02274

Please sign in to comment.