Skip to content

Commit 01cf919

Browse files
committed
feat(ui): dark theme toggle
1 parent 71f44bd commit 01cf919

File tree

8 files changed

+321
-251
lines changed

8 files changed

+321
-251
lines changed

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function App() {
1515
const queryClient = new QueryClient();
1616

1717
return (
18-
<div className="wrapper">
18+
<div className="wrapper transition duration-500 dark:bg-gray-600 h-screen">
1919
<QueryClientProvider client={queryClient}>
2020
<BrowserRouter>
2121
<Switch>

src/components/Benchmarks/BenchmarkDetail.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Page from '../Page/Page';
1414
import Leaderboard from '../leaderboard/Leaderboard';
1515
import { languagesList } from '../../assets/languages';
1616
import { XIcon } from '@heroicons/react/outline';
17+
import useDarkMode from '../../hooks/darkmode';
1718

1819
function classNames(...classes: string[]) {
1920
return classes.filter(Boolean).join(' ');
@@ -30,10 +31,13 @@ const BenchmarkDetail = ({
3031
}: RouteComponentProps<BenchmarkDetailParams>) => {
3132
const [selected, setSelected] = useState(languages[0]);
3233
const [open, setOpen] = useState(false);
34+
const [colorTheme] = useDarkMode();
3335

3436
//Get monaco instance to access code later
3537
const editorRef: any = useRef<null>(null);
3638

39+
let editorTheme = colorTheme === 'dark' ? 'light' : 'vs-dark';
40+
3741
function handleEditorDidMount(editor: any, monaco: any) {
3842
editorRef.current = editor;
3943
}
@@ -185,16 +189,16 @@ const BenchmarkDetail = ({
185189
<div className="grid w-2/5">
186190
<div className="pl-8 pr-8 border-4 border-dashed border-gray-200 rounded-lg h-96 p-4">
187191
<div className="flex justify-between">
188-
<h1 className="text-2xl pb-3">Subject</h1>
192+
<h1 className="text-2xl pb-3 dark:text-white">Subject</h1>
189193
<div className="">
190194
<Listbox value={selected} onChange={setSelected}>
191195
{({ open }) => (
192196
<>
193-
<Listbox.Label className="block text-sm font-medium text-gray-700">
197+
<Listbox.Label className="block dark:text-white text-sm font-medium text-gray-700">
194198
Languages
195199
</Listbox.Label>
196200
<div className="mt-1 relative">
197-
<Listbox.Button className="relative w-full bg-white border border-gray-300 rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
201+
<Listbox.Button className="dark:text-white dark:bg-gray-800 relative w-full bg-white border border-gray-300 rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
198202
<span className="flex items-center">
199203
<img
200204
src={selected.avatar}
@@ -222,7 +226,7 @@ const BenchmarkDetail = ({
222226
>
223227
<Listbox.Options
224228
static
225-
className="absolute z-10 mt-1 w-full bg-white shadow-lg max-h-96 rounded-md py-1 text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm"
229+
className="dark:text-white dark:bg-gray-800 absolute z-10 mt-1 w-full bg-white shadow-lg max-h-96 rounded-md py-1 text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm"
226230
>
227231
{languages.map((language) => (
228232
<Listbox.Option
@@ -231,7 +235,7 @@ const BenchmarkDetail = ({
231235
classNames(
232236
active
233237
? 'text-white bg-indigo-600'
234-
: 'text-gray-900',
238+
: 'text-gray-900 dark:text-white',
235239
'cursor-default select-none relative py-2 pl-3 pr-9',
236240
)
237241
}
@@ -262,7 +266,7 @@ const BenchmarkDetail = ({
262266
className={classNames(
263267
active
264268
? 'text-white'
265-
: 'text-indigo-600',
269+
: 'text-indigo-600 dark:text-white',
266270
'absolute inset-y-0 right-0 flex items-center pr-4',
267271
)}
268272
>
@@ -284,7 +288,9 @@ const BenchmarkDetail = ({
284288
</Listbox>
285289
</div>
286290
</div>
287-
<ReactMarkdown>{benchmarkData?.subject || ''}</ReactMarkdown>
291+
<ReactMarkdown className="dark:text-white">
292+
{benchmarkData?.subject || ''}
293+
</ReactMarkdown>
288294
<div className="flex">
289295
<button
290296
className="bg-blue-500 hover:bg-blue-700 text-white font-bold mt-2 py-2 px-4 rounded-full"
@@ -300,6 +306,7 @@ const BenchmarkDetail = ({
300306
<Editor
301307
onMount={handleEditorDidMount}
302308
height="100%"
309+
theme={editorTheme}
303310
value={lastSubmission && lastSubmission}
304311
language={selected.name}
305312
/>

src/components/Benchmarks/Benchmarks.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,29 @@ const Benchmarks: React.FC = () => {
3636
<div className="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
3737
<div className="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg">
3838
<table className="min-w-full divide-y divide-gray-200">
39-
<thead className="bg-gray-50">
39+
<thead className="bg-gray-50 dark:bg-gray-800">
4040
<tr>
4141
<th
4242
scope="col"
43-
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
43+
className="dark:text-white px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
4444
>
4545
Title
4646
</th>
4747
<th
4848
scope="col"
49-
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
49+
className="dark:text-white px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
5050
>
5151
Subject
5252
</th>
5353
<th
5454
scope="col"
55-
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
55+
className="dark:text-white px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
5656
>
5757
Difficulty
5858
</th>
5959
<th
6060
scope="col"
61-
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
61+
className="dark:text-white px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
6262
>
6363
Creator
6464
</th>
@@ -67,7 +67,7 @@ const Benchmarks: React.FC = () => {
6767
</th>
6868
</tr>
6969
</thead>
70-
<tbody className="bg-white divide-y divide-gray-200">
70+
<tbody className="bg-white dark:bg-gray-300 divide-y divide-gray-200">
7171
{benchmarks.map((benchmark: benchmarkModel) => (
7272
<BenchmarkRow
7373
key={benchmark.id?.toString()}

src/components/Benchmarks/Result.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ const Result: React.FC<LayoutProps> = ({
2222
lintScore,
2323
}) => {
2424
return (
25-
<div className="flex">
25+
<div className="flex dark:text-white">
2626
<div className="w-1/3">
2727
<ScoresComponent qualityScore={qualityScore} lintScore={lintScore} />
2828
</div>
29-
<div className="w-2/3">
29+
<div className="w-2/3 ml-2">
3030
<b>Status: </b>
3131
{status}
3232
<div className="flex justify-between">

src/components/Page/Header.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Header: React.FC<HeaderProps> = ({ title, button, navTo }) => {
1111
const isButtonNeeded = button !== undefined && navTo !== undefined;
1212

1313
return (
14-
<header className="bg-white shadow">
14+
<header className="bg-white dark:bg-gray-800 shadow">
1515
{button === 'back' ? (
1616
<div className="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8 flex ">
1717
{isButtonNeeded ? (
@@ -37,11 +37,15 @@ const Header: React.FC<HeaderProps> = ({ title, button, navTo }) => {
3737
) : (
3838
<></>
3939
)}
40-
<h1 className="text-3xl font-bold text-gray-900 ml-2">{title}</h1>
40+
<h1 className="text-3xl dark:text-white font-bold text-gray-900 ml-2">
41+
{title}
42+
</h1>
4143
</div>
4244
) : (
4345
<div className="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8 flex justify-between">
44-
<h1 className="text-3xl font-bold text-gray-900">{title}</h1>
46+
<h1 className="text-3xl dark:text-white font-bold text-gray-900">
47+
{title}
48+
</h1>
4549
{isButtonNeeded ? (
4650
<Link
4751
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full"

0 commit comments

Comments
 (0)