Skip to content

Commit 19b27e8

Browse files
committed
Update daily potd UI when no POTD
1 parent f7bc0e7 commit 19b27e8

File tree

4 files changed

+48
-19
lines changed

4 files changed

+48
-19
lines changed

client-test/src/components/Challenges/index.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const Challenges: React.FC = () => {
9494
setIsDailyLoading(true);
9595
const params = user ? { userId: user._id } : {};
9696
const res = await axios.get(`${import.meta.env.VITE_API_BASE_URL}/api/challenges/daily`, { params });
97+
9798
if (res.data) {
9899
const challenge = res.data;
99100
const formattedChallenge: Challenge = {
@@ -115,9 +116,16 @@ const Challenges: React.FC = () => {
115116

116117
setDailyProblem(formattedChallenge);
117118
setIsSolved(challenge.isSolved || false);
119+
} else {
120+
// No daily challenge data
121+
setDailyProblem(null);
122+
setIsSolved(false);
118123
}
119124
} catch (error) {
120125
console.error("Failed to fetch daily challenge:", error);
126+
// Backend returns 404 when no challenge is posted for today
127+
setDailyProblem(null);
128+
setIsSolved(false);
121129
} finally {
122130
setIsDailyLoading(false);
123131
}
@@ -219,6 +227,16 @@ const Challenges: React.FC = () => {
219227
}
220228
}, [user, activeTab]);
221229

230+
// Show toast when user is not logged in
231+
useEffect(() => {
232+
if (!user) {
233+
toast.error("Sign in to view status and solutions", {
234+
duration: 2000,
235+
position: 'bottom-right',
236+
});
237+
}
238+
}, [user]);
239+
222240
// Reset to page 1 when filters change
223241
useEffect(() => {
224242
if (filterOptions.categories.length > 0) {
@@ -386,9 +404,9 @@ const Challenges: React.FC = () => {
386404
<h3 className="text-xl sm:text-2xl font-bold text-gray-200 dark:text-gray-800 line-clamp-1">
387405
{dailyProblem.title}
388406
</h3>
389-
<p className="text-gray-400 dark:text-gray-600 text-sm line-clamp-2">
407+
{/* <p className="text-gray-400 dark:text-gray-600 text-sm line-clamp-2">
390408
{dailyProblem.description}
391-
</p>
409+
</p> */}
392410
<div className="flex flex-wrap gap-2">
393411
{dailyProblem.categories.map((cat: any) => (
394412
<Badge
@@ -439,7 +457,21 @@ const Challenges: React.FC = () => {
439457
</span>
440458
</div>
441459
</div>
442-
) : null}
460+
) : (
461+
<div className="mt-6 bg-gray-800 dark:bg-muted rounded-xl p-4 sm:p-6 flex flex-col items-center justify-center text-center space-y-4 h-40">
462+
<div className="bg-amber-500/20 dark:bg-amber-500/30 p-3 rounded-full">
463+
<Clock className="h-8 w-8 text-amber-500" />
464+
</div>
465+
<div className="space-y-2">
466+
<h3 className="text-lg font-semibold text-gray-200 dark:text-gray-800">
467+
No Problem Posted Today
468+
</h3>
469+
<p className="text-gray-400 dark:text-gray-600 text-sm">
470+
Please wait until a new daily challenge is posted. Check back soon!
471+
</p>
472+
</div>
473+
</div>
474+
)}
443475
</CardContent>
444476
</Card>
445477

@@ -625,7 +657,7 @@ const Challenges: React.FC = () => {
625657
<Calendar className="h-3 w-3 mr-1" /> {problem.date}
626658
</div>
627659
<h3 className="text-lg font-bold text-foreground">{problem.title}</h3>
628-
<p className="text-muted-foreground text-sm line-clamp-2">{problem.description}</p>
660+
{/* <p className="text-muted-foreground text-sm line-clamp-2">{problem.description}</p> */}
629661
<div className="flex flex-wrap gap-1.5">
630662
{problem.categories.map((cat: any) => (
631663
<Badge

client-test/src/lib/solutionStatus.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ const SolutionStatus: React.FC<ProblemStatusProps> = ({ problem }) => {
4444
const isSolved = problem.status === "Solved" ? "Solved" : "Not Solved";
4545

4646
return (
47-
<div className="flex w-full gap-2 self-start sm:self-center">
47+
<div className="flex flex-col w-full gap-2 self-start sm:self-center">
4848
{isSolved === "Solved" ? (
49-
<div className="flex w-full gap-2">
49+
<div className="flex flex-col w-full gap-2">
5050
<Button
5151
size="sm"
52-
className="flex-1 text-xs py-1 px-2 bg-green-600 hover:bg-green-700 text-white border-0 transition-colors duration-200"
52+
className="w-full text-xs py-1 px-2 bg-green-600 hover:bg-green-700 text-white border-0 transition-colors duration-200"
5353
onClick={(e) => {
5454
e.stopPropagation();
5555
window.open(problem.problemUrl, "_blank");
@@ -61,19 +61,19 @@ const SolutionStatus: React.FC<ProblemStatusProps> = ({ problem }) => {
6161
<Button
6262
size="sm"
6363
variant="outline"
64-
className="flex-1 text-xs py-1 px-2 border-blue-500 hover:bg-blue-500/10 hover:text-blue-500 transition-colors duration-200 text-foreground"
64+
className="w-full text-xs py-1 px-2 border-blue-500 hover:bg-blue-500/10 hover:text-blue-500 transition-colors duration-200 text-foreground"
6565
onClick={handleViewSolution}
6666
>
6767
<Eye className="h-3 w-3 mr-1" /> View Solution
6868
</Button>
6969
)}
7070
</div>
7171
) : (
72-
<div className="flex w-full gap-2">
72+
<div className="flex flex-col w-full gap-2">
7373
<Button
7474
size="sm"
7575
variant="outline"
76-
className="flex-1 text-xs py-1 px-2 border-primary hover:bg-primary/10 hover:text-primary transition-colors duration-200 text-foreground"
76+
className="w-full text-xs py-1 px-2 border-primary hover:bg-primary/10 hover:text-primary transition-colors duration-200 text-foreground"
7777
onClick={(e) => {
7878
e.stopPropagation();
7979
window.open(problem.problemUrl, "_blank");
@@ -85,7 +85,7 @@ const SolutionStatus: React.FC<ProblemStatusProps> = ({ problem }) => {
8585
<Button
8686
size="sm"
8787
variant="outline"
88-
className="flex-1 text-xs py-1 px-2 border-blue-500 hover:bg-blue-500/10 hover:text-blue-500 transition-colors duration-200 text-foreground"
88+
className="w-full text-xs py-1 px-2 border-blue-500 hover:bg-blue-500/10 hover:text-blue-500 transition-colors duration-200 text-foreground"
8989
onClick={handleViewSolution}
9090
>
9191
<Eye className="h-3 w-3 mr-1" /> View Solution

server/controllers/challengeController.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,9 @@ export const getDailyChallenge = async (req, res) => {
121121
}
122122
}).sort({ createdAt: -1 });
123123

124+
// If no challenge found for today, return 404 instead of fallback to most recent
124125
if (!dailyChallenge) {
125-
dailyChallenge = await Challenge.findOne().sort({ createdAt: -1 });
126-
}
127-
128-
if (!dailyChallenge) {
129-
return res.status(404).json({ message: 'No daily challenge found' });
126+
return res.status(404).json({ message: 'No challenge posted for today' });
130127
}
131128

132129
let targetUser = null;

server/server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dotenv.config();
88

99
connectDB();
1010

11-
// const PORT = process.env.PORT || 5000
12-
// app.listen(PORT, () => { console.log(`Server is running at ${PORT}`); })
11+
const PORT = process.env.PORT || 5000
12+
app.listen(PORT, () => { console.log(`Server is running at ${PORT}`); })
1313

14-
export const handler = serverless(app);
14+
// export const handler = serverless(app);

0 commit comments

Comments
 (0)