-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponents.js
157 lines (145 loc) · 5.65 KB
/
components.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// QuestionDisplay Component with mobile-first design
const QuestionDisplay = ({ question }) => {
if (!question) {
return null;
}
const title = question.title;
const description = question.description;
const example = question.example;
return React.createElement('div', {
className: 'card'
}, [
// Compact header
React.createElement('div', {
key: 'header',
className: 'mb-3'
}, [
React.createElement('h2', {
className: 'text-lg font-semibold'
}, title),
React.createElement('p', {
className: 'text-sm text-gray-600 mt-1'
}, description)
]),
// Compact example
React.createElement('div', {
key: 'example',
className: 'bg-gray-50 rounded-xl p-3 mb-3'
}, [
React.createElement('h3', {
className: 'text-xs font-medium text-gray-700 mb-1'
}, 'Example'),
React.createElement('code', {
className: 'text-sm block'
}, example)
]),
// Compact function signature
React.createElement('div', {
key: 'signature',
className: 'pt-3 border-t border-gray-200'
}, [
React.createElement('h3', {
className: 'text-xs font-medium text-gray-700 mb-1'
}, 'Function Signature'),
React.createElement('code', {
className: 'text-sm block'
}, question.starterCode.split('\n')[0])
])
]);
};
// Updated ProblemNavigator for mobile
const ProblemNavigator = ({ problems, solvedProblems, onProblemSelect }) => {
const [searchTerm, setSearchTerm] = React.useState('');
const [currentPage, setCurrentPage] = React.useState(1);
const problemsPerPage = 20; // Show more problems on mobile grid
const filteredProblems = problems.filter(problem => {
const searchLower = searchTerm.toLowerCase();
return problem.description.toLowerCase().includes(searchLower);
});
const totalPages = Math.ceil(filteredProblems.length / problemsPerPage);
const startIndex = (currentPage - 1) * problemsPerPage;
const displayedProblems = filteredProblems.slice(startIndex, startIndex + problemsPerPage);
const totalSolved = solvedProblems.size;
const completionPercentage = Math.round((totalSolved / problems.length) * 100);
return React.createElement('div', {
className: 'card'
}, [
// Compact progress section
React.createElement('div', {
key: 'progress',
className: 'mb-3'
}, [
React.createElement('div', {
className: 'flex justify-between items-center mb-2'
}, [
React.createElement('span', {
className: 'text-sm font-medium'
}, `${totalSolved} / ${problems.length} Complete`),
React.createElement('span', {
className: 'text-sm text-gray-600'
}, `${completionPercentage}%`)
]),
React.createElement('div', {
className: 'progress-bar'
}, [
React.createElement('div', {
className: 'progress-fill',
style: { width: `${completionPercentage}%` }
})
])
]),
// Compact search
React.createElement('input', {
key: 'search',
type: 'search',
placeholder: 'Search problems...',
value: searchTerm,
onChange: (e) => {
setSearchTerm(e.target.value);
setCurrentPage(1);
},
className: 'search-input mb-3'
}),
// Mobile-friendly grid
React.createElement('div', {
key: 'grid',
className: 'problem-grid'
}, displayedProblems.map((problem, index) => {
const problemNumber = startIndex + index + 1;
const isSolved = solvedProblems.has(problem.id);
return React.createElement('button', {
key: problem.id,
onClick: () => onProblemSelect(problem),
className: `problem-item ${isSolved ? 'bg-green-50 border-green-200' : 'bg-white border-gray-200'}`
}, [
React.createElement('span', {
key: 'number',
className: isSolved ? 'text-green-600' : 'text-gray-600'
}, problemNumber),
React.createElement('span', {
key: 'icon',
className: `text-xs ${isSolved ? 'text-green-500' : 'text-gray-400'}`
}, isSolved ? '✓' : '')
]);
}))
]);
};
// Main App Wrapper Component
const AppWrapper = ({ questions, solvedProblems, onProblemSelect, currentQuestion }) => {
return React.createElement('div', { className: 'w-full space-y-6' }, [
React.createElement('h1', {
key: 'title',
className: 'text-2xl font-bold text-center text-gray-900'
}, 'Biocode'),
React.createElement(ProblemNavigator, {
key: 'navigator',
problems: questions,
solvedProblems: new Set(solvedProblems),
onProblemSelect: onProblemSelect
}),
React.createElement(QuestionDisplay, {
key: 'question',
question: currentQuestion
})
]);
};