Skip to content

Commit 94a0812

Browse files
committed
chore: cleanup
1 parent 2e11288 commit 94a0812

2 files changed

Lines changed: 85 additions & 100 deletions

File tree

src/forms/create-contest.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { ResultError } from "@/lib/client";
2525
import TableTemplate from "@/components/templates/table";
2626
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/ui/select';
2727

28+
// TODO: cleanup
29+
2830
export interface FormData {
2931
title: string;
3032
description: string;
@@ -183,14 +185,12 @@ export function CreateContestForm() {
183185
return;
184186
}
185187

186-
// Forbid negative sign
187188
if (inputValue.includes('-')) {
188189
return;
189190
}
190191

191192
const val = parseFloat(inputValue);
192193

193-
// Forbid negative values
194194
if (val < 0) {
195195
return;
196196
}
@@ -204,7 +204,6 @@ export function CreateContestForm() {
204204
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
205205
e.preventDefault();
206206
}
207-
// Prevent entering negative sign
208207
if (e.key === '-') {
209208
e.preventDefault();
210209
}
@@ -272,19 +271,16 @@ export function CreateContestForm() {
272271
return;
273272
}
274273

275-
// Forbid negative sign and decimal point
276274
if (val.includes('-') || val.includes('.') || val.includes(',')) {
277275
return;
278276
}
279277

280-
// Only allow digits
281278
if (!/^\d+$/.test(val)) {
282279
return;
283280
}
284281

285282
const numVal = Number(val);
286283

287-
// Forbid negative values
288284
if (numVal < 0) {
289285
return;
290286
}

src/modules/contest/details.tsx

Lines changed: 83 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -8,125 +8,114 @@ import Address from "@/components/address";
88
import TonPrizes from "@/components/ton-prizes";
99
import Tx from "@/components/tx";
1010

11-
// --- Shared row layout component ---
1211
function DetailRow({ label, children }: { label: string; children: React.ReactNode }) {
13-
return (
14-
<div className="flex">
15-
<div className="flex-1 text-secondary-foreground">{label}</div>
16-
<div className="flex-1">{children}</div>
17-
</div>
18-
);
12+
return (
13+
<div className="flex">
14+
<div className="flex-1 text-secondary-foreground">{label}</div>
15+
<div className="flex-1">{children}</div>
16+
</div>
17+
);
1918
}
2019

21-
// --- Individual point components ---
22-
2320
function StartTime({ date }: { date: Date }) {
24-
return (
25-
<DetailRow label="Start">
26-
<DateView date={date} />
27-
</DetailRow>
28-
);
21+
return (
22+
<DetailRow label="Start">
23+
<DateView date={date} />
24+
</DetailRow>
25+
);
2926
}
3027

3128
function EndTime({ date }: { date: Date }) {
32-
return (
33-
<DetailRow label="End">
34-
<DateView date={date} />
35-
</DetailRow>
36-
);
29+
return (
30+
<DetailRow label="End">
31+
<DateView date={date} />
32+
</DetailRow>
33+
);
3734
}
3835

3936
function SubmissionDeadline({ date }: { date: Date }) {
40-
return (
41-
<DetailRow label="Deadline">
42-
<Timer target={date} expiredLabel="expired" />
43-
</DetailRow>
44-
);
37+
return (
38+
<DetailRow label="Deadline">
39+
<Timer target={date} expiredLabel="expired" />
40+
</DetailRow>
41+
);
4542
}
4643

4744
function ContestAddress({ address }: { address: string }) {
48-
return (
49-
<DetailRow label="Address">
50-
<Address address={address} length={4} />
51-
</DetailRow>
52-
);
45+
return (
46+
<DetailRow label="Address">
47+
<Address address={address} length={4} />
48+
</DetailRow>
49+
);
5350
}
5451

5552
function DistributionTx({ tx }: { tx: string }) {
56-
return (
57-
<DetailRow label="Distribution tx">
58-
<Tx tx={tx} length={5} />
59-
</DetailRow>
60-
);
53+
return (
54+
<DetailRow label="Distribution tx">
55+
<Tx tx={tx} length={5} />
56+
</DetailRow>
57+
);
6158
}
6259

6360
function Prizes({ nanos }: { nanos: number }) {
64-
return (
65-
<DetailRow label="Prizes">
66-
<TonPrizes nanos={nanos} />
67-
</DetailRow>
68-
);
61+
return (
62+
<DetailRow label="Prizes">
63+
<TonPrizes nanos={nanos} />
64+
</DetailRow>
65+
);
6966
}
7067

7168
function EntryPrice({ nanos }: { nanos: number }) {
72-
return (
73-
<DetailRow label="Pay for entry">
74-
<TonPrizes nanos={nanos} />
75-
</DetailRow>
76-
);
69+
return (
70+
<DetailRow label="Pay for entry">
71+
<TonPrizes nanos={nanos} />
72+
</DetailRow>
73+
);
7774
}
7875

79-
function Participants({
80-
participants,
81-
max_entries,
82-
}: {
83-
participants: number;
84-
max_entries?: number;
85-
}) {
86-
return (
87-
<DetailRow label="Participants">
88-
{max_entries === undefined ? participants : `${participants}/${max_entries}`}
89-
</DetailRow>
90-
);
76+
function Participants({ participants, max_entries }: { participants: number; max_entries?: number }) {
77+
return (
78+
<DetailRow label="Participants">
79+
{max_entries === undefined ? participants : `${participants}/${max_entries}`}
80+
</DetailRow>
81+
);
9182
}
9283

93-
// --- Main component ---
94-
9584
export default function Details({ contest }: { contest: ContestDetailed }) {
96-
return (
97-
<Widget className="flex-1">
98-
<WidgetContent>
99-
<WidgetTitle className="text-foreground">ABOUT</WidgetTitle>
100-
101-
<StartTime date={contest.start_time} />
102-
<EndTime date={contest.end_time} />
103-
104-
{contest.entry?.submission_deadline && (
105-
<SubmissionDeadline date={contest.entry.submission_deadline} />
106-
)}
107-
108-
{contest.awards.kind !== "no" && contest.address && (
109-
<>
110-
<ContestAddress address={contest.address} />
111-
112-
{contest.awards.is_distributed ? (
113-
<DistributionTx tx={contest.awards.distribution_tx_hash} />
114-
) : (
115-
<>
116-
<Prizes nanos={contest.awards.nanocoins} />
117-
{contest.awards.kind === 'pool' &&
118-
<EntryPrice nanos={contest.entry_price_ton_nanos} />
119-
}
120-
</>
121-
)}
122-
</>
123-
)}
124-
125-
<Participants
126-
participants={contest.participants}
127-
max_entries={contest.max_entries}
128-
/>
129-
</WidgetContent>
130-
</Widget>
131-
);
85+
return (
86+
<Widget className="flex-1">
87+
<WidgetContent>
88+
<WidgetTitle className="text-foreground">ABOUT</WidgetTitle>
89+
90+
<StartTime date={contest.start_time} />
91+
<EndTime date={contest.end_time} />
92+
93+
{contest.entry?.submission_deadline && (
94+
<SubmissionDeadline date={contest.entry.submission_deadline} />
95+
)}
96+
97+
{contest.awards.kind !== "no" && contest.address && (
98+
<>
99+
<ContestAddress address={contest.address} />
100+
101+
{contest.awards.is_distributed ? (
102+
<DistributionTx tx={contest.awards.distribution_tx_hash} />
103+
) : (
104+
<>
105+
<Prizes nanos={contest.awards.nanocoins} />
106+
{contest.awards.kind === 'pool' &&
107+
<EntryPrice nanos={contest.entry_price_ton_nanos} />
108+
}
109+
</>
110+
)}
111+
</>
112+
)}
113+
114+
<Participants
115+
participants={contest.participants}
116+
max_entries={contest.max_entries}
117+
/>
118+
</WidgetContent>
119+
</Widget>
120+
);
132121
}

0 commit comments

Comments
 (0)