Skip to content

Commit 9b5d0ba

Browse files
Merge pull request #2 from foundersandcoders/style_questions_counter
Style questions counter
2 parents 73dc895 + 8f1db75 commit 9b5d0ba

File tree

9 files changed

+140
-221
lines changed

9 files changed

+140
-221
lines changed

src/components/Header.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react';
22
import { useStatements } from '../hooks/useStatements';
3-
// import { useQuestions } from '@/hooks/useQuestions';
3+
44
import {
55
Dialog,
66
DialogTrigger,
@@ -10,10 +10,12 @@ import {
1010
} from './ui/dialog';
1111
import { Button } from './ui/button';
1212
import { Input } from './ui/input';
13-
import { User, Edit2, Save, X } from 'lucide-react';
13+
import { Edit2, Save, X } from 'lucide-react';
1414
import { Tooltip, TooltipTrigger, TooltipContent } from './ui/tooltip';
1515
import { validateEmail } from '../../utils/validateEmail';
16-
import QuestionCounter from './ui/QuestionCounter';
16+
import QuestionCounter from './ui/questionCounter/QuestionCounter';
17+
import SmallCircularQuestionCounter from './ui/questionCounter/smallCircularQuestionCounter';
18+
import LargeCircularQuestionCounter from './ui/questionCounter/LargeCircularQuestionCounter';
1719

1820
const Header: React.FC = () => {
1921
// const { questions, setQuestions } = useQuestions();
@@ -50,9 +52,9 @@ const Header: React.FC = () => {
5052
{data.username ? (
5153
<span className='mr-2'>Logged as: {data.username}</span>
5254
) : (
53-
<span>Not logged</span>
55+
<span className='mr-2'>Not logged</span>
5456
)}
55-
<User size={24} />
57+
<SmallCircularQuestionCounter />
5658
</div>
5759
</DialogTrigger>
5860
<DialogContent headerTitle="User's Data" className='sm:max-w-md p-0'>
@@ -142,6 +144,7 @@ const Header: React.FC = () => {
142144
</div>
143145
<div className='text-sm text-gray-800'>
144146
<QuestionCounter />
147+
<LargeCircularQuestionCounter />
145148
</div>
146149
</div>
147150
</div>

src/components/MainPage.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use client';
22

33
import React from 'react';
4-
// import StatementBuilder from './StatementBuilder';
54
import StatementList from './statements/StatementList';
65
import { useStatements } from '../hooks/useStatements';
76

@@ -15,12 +14,6 @@ const MainPage: React.FC = () => {
1514
</h1>
1615
<div className='container mx-auto px-4'>
1716
<StatementList username={username} />
18-
19-
{/* <div className='flex flex-col justify-center max-w-3xl mx-auto'>
20-
<div className='bg-white rounded-xl shadow-lg p-6'>
21-
<StatementBuilder username={username} />
22-
</div>
23-
</div> */}
2417
</div>
2518
</main>
2619
);

src/components/StatementBuilder.tsx

Lines changed: 0 additions & 188 deletions
This file was deleted.

src/components/StatementWizardOld.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type { Statement, DescriptorsData } from '../../types/types';
2121
type Step = 'closed' | 'who' | 'action' | 'object' | 'privacy';
2222

2323
const StatementWizard: React.FC<{ username: string }> = ({ username }) => {
24-
const { dispatch } = useStatements();
24+
const { setData } = useStatements();
2525

2626
const [isOpen, setIsOpen] = useState(false);
2727
const [step, setStep] = useState<Step>('closed');
@@ -31,6 +31,7 @@ const StatementWizard: React.FC<{ username: string }> = ({ username }) => {
3131
verb: '',
3232
object: '',
3333
isPublic: false,
34+
category: '',
3435
});
3536
const [selectedCategory, setSelectedCategory] = useState<string | null>(null);
3637

@@ -124,6 +125,7 @@ const StatementWizard: React.FC<{ username: string }> = ({ username }) => {
124125
verb: '',
125126
object: '',
126127
isPublic: false,
128+
category: '',
127129
});
128130
};
129131

@@ -157,7 +159,7 @@ const StatementWizard: React.FC<{ username: string }> = ({ username }) => {
157159
};
158160

159161
// Dispatch the new statement to the context.
160-
dispatch({ type: 'ADD_STATEMENT', payload: newStatement });
162+
setData({ type: 'ADD_STATEMENT', payload: newStatement });
161163

162164
// Post the new statement to the backend.
163165
await postNewStatement(newStatement);

src/components/ui/QuestionCounter.tsx

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from 'react';
2+
import { useAnsweredCount } from '../../../hooks/useAnsweredCount';
3+
4+
interface LargeCircularQuestionCounterProps {
5+
size?: number; // default 100px
6+
strokeWidth?: number; // default 6px
7+
}
8+
9+
const LargeCircularQuestionCounter: React.FC<
10+
LargeCircularQuestionCounterProps
11+
> = ({ size = 100, strokeWidth = 6 }) => {
12+
const { answered, total } = useAnsweredCount();
13+
const progress = total > 0 ? Math.round((answered / total) * 100) : 0;
14+
15+
const radius = (size - strokeWidth) / 2;
16+
const circumference = 2 * Math.PI * radius;
17+
const dashOffset = circumference * (1 - progress / 100);
18+
19+
return (
20+
<div className='relative w-fit'>
21+
<svg width={size} height={size} viewBox={`0 0 ${size} ${size}`}>
22+
{/* Background circle */}
23+
<circle
24+
className='text-gray-200'
25+
stroke='currentColor'
26+
strokeWidth={strokeWidth}
27+
fill='transparent'
28+
r={radius}
29+
cx={size / 2}
30+
cy={size / 2}
31+
/>
32+
{/* Progress circle */}
33+
<circle
34+
className='text-brand-pink'
35+
stroke='currentColor'
36+
strokeWidth={strokeWidth}
37+
fill='transparent'
38+
r={radius}
39+
cx={size / 2}
40+
cy={size / 2}
41+
strokeDasharray={circumference}
42+
strokeDashoffset={dashOffset}
43+
transform={`rotate(-90 ${size / 2} ${size / 2})`} // ✅ Start from the top
44+
style={{ transition: 'stroke-dashoffset 0.35s ease-out' }}
45+
/>
46+
</svg>
47+
{/* Percentage Text in Center */}
48+
<span className='absolute inset-0 flex items-center justify-center text-lg font-semibold'>
49+
{progress}%
50+
</span>
51+
</div>
52+
);
53+
};
54+
55+
export default LargeCircularQuestionCounter;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import { useAnsweredCount } from '../../../hooks/useAnsweredCount';
3+
4+
const QuestionCounter: React.FC = () => {
5+
const { answered, total } = useAnsweredCount(); // Extract values
6+
7+
return (
8+
<div className='text-sm text-gray-700'>
9+
{answered} / {total} questions answered
10+
</div>
11+
);
12+
};
13+
14+
export default QuestionCounter;

0 commit comments

Comments
 (0)