Skip to content

Commit 27a8b13

Browse files
Merge pull request #96 from syntaxandsips/mr-dark-debug/implement-neo-brutalism-themed-topics-page
feat: redesign topics hub with neo-brutalist layout
2 parents 7992c61 + 533ffd8 commit 27a8b13

4 files changed

Lines changed: 1193 additions & 192 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"use client";
2+
3+
import { useCallback, useMemo } from 'react';
4+
import { useRouter, useSearchParams } from 'next/navigation';
5+
import { Sparkles } from 'lucide-react';
6+
7+
interface RandomTopicButtonProps {
8+
topics: { slug: string; label: string }[];
9+
}
10+
11+
export const RandomTopicButton = ({ topics }: RandomTopicButtonProps) => {
12+
const router = useRouter();
13+
const searchParams = useSearchParams();
14+
15+
const topicPool = useMemo(() => {
16+
if (topics.length === 0) {
17+
return [];
18+
}
19+
20+
return topics;
21+
}, [topics]);
22+
23+
const handleClick = useCallback(() => {
24+
if (topicPool.length === 0) {
25+
return;
26+
}
27+
28+
const currentTopic = searchParams.get('topic');
29+
const pool = topicPool.filter((topic) => topic.slug !== currentTopic);
30+
const selectionPool = pool.length > 0 ? pool : topicPool;
31+
const randomIndex = Math.floor(Math.random() * selectionPool.length);
32+
const nextTopic = selectionPool[randomIndex];
33+
34+
router.push(`/topics?topic=${encodeURIComponent(nextTopic.slug)}`);
35+
}, [router, searchParams, topicPool]);
36+
37+
return (
38+
<button
39+
type="button"
40+
onClick={handleClick}
41+
className="inline-flex items-center gap-2 rounded-full border-2 border-black bg-gradient-to-r from-[#FF8A00] via-[#FF3D81] to-[#7048FF] px-5 py-2.5 text-sm font-black uppercase tracking-[0.18em] text-white shadow-[6px_6px_0px_0px_rgba(0,0,0,0.25)] transition-transform hover:-translate-y-1 focus:outline-none focus-visible:ring-4 focus-visible:ring-black/60"
42+
aria-label="Pick a random topic"
43+
>
44+
<Sparkles className="h-4 w-4" aria-hidden="true" />
45+
Superime me
46+
</button>
47+
);
48+
};

0 commit comments

Comments
 (0)