MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / CategoryPage

Function CategoryPage

src/pages/CategoryPage.jsx:11–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9import IndexPage from './IndexPage';
10
11const CategoryPage = () => {
12 const { category, subcategory } = useParams();
13 const { transitionPhase, getPreloadedComponent } = useTransition();
14
15 const decodedLabel = decodeLabel(subcategory);
16 const isLoading = transitionPhase === 'loading';
17 const opacity = ['fade-out', 'loading'].includes(transitionPhase) ? 0 : 1;
18 const isGetStartedRoute = category === 'get-started';
19 const isIndexPage = subcategory === 'index';
20
21 const componentFactory = subcategory && componentMap[subcategory];
22 const SubcategoryComponent =
23 getPreloadedComponent(subcategory)?.default || (componentFactory ? lazy(componentFactory) : null);
24 const Loader = isGetStartedRoute ? GetStartedLoader : SkeletonLoader;
25
26 useEffect(() => {
27 if (transitionPhase !== 'fade-out') {
28 try {
29 window.scrollTo({ top: 0, behavior: 'auto' });
30 } catch {
31 window.scrollTo(0, 0);
32 }
33 }
34 }, [subcategory, transitionPhase]);
35
36 useEffect(() => {
37 if (decodedLabel) {
38 document.title = `React Bits - ${decodedLabel}`;
39 }
40 }, [decodedLabel]);
41
42 return (
43 <>
44 {isIndexPage ? (
45 <IndexPage />
46 ) : (
47 <Box className={`category-page ${isLoading ? 'loading' : ''}`}>
48 <Box className="page-transition-fade" style={{ opacity }}>
49 {!isGetStartedRoute && <h2 className="sub-category">{decodedLabel}</h2>}
50
51 {SubcategoryComponent ? (
52 <Suspense fallback={<Loader />}>
53 <SubcategoryComponent />
54 </Suspense>
55 ) : (
56 <Box p={6}>
57 <Text color="#fff" fontWeight={600} fontSize="18px">
58 Not found
59 </Text>
60 <Text color="#a6a6a6" fontSize="14px">
61 This section is unavailable.
62 </Text>
63 </Box>
64 )}
65 </Box>
66 <BackToTopButton />
67 </Box>
68 )}

Callers

nothing calls this directly

Calls 2

useTransitionFunction · 0.90
decodeLabelFunction · 0.90

Tested by

no test coverage detected