Skip to content

Commit

Permalink
feat: move content and toc in a single component
Browse files Browse the repository at this point in the history
  • Loading branch information
YounixM committed Nov 6, 2024
1 parent a1f69dd commit b8c0b4d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 51 deletions.
29 changes: 9 additions & 20 deletions app/docs/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import 'css/prism.css'

import { components } from '@/components/MDXComponents'
import { MDXLayoutRenderer } from 'pliny/mdx-components'
import { coreContent } from 'pliny/utils/contentlayer'
import { allDocs } from 'contentlayer/generated'
import type { Doc } from 'contentlayer/generated'
import { Metadata } from 'next'
import siteMetadata from '@/data/siteMetadata'
import React from 'react'
import DocsPrevNext from '../../../components/DocsPrevNext/DocsPrevNext'
import PageFeedback from '../../../components/PageFeedback/PageFeedback'
import { notFound } from 'next/navigation'
import TrySigNozFloatingCard from '@/components/TrySigNozFloatingCard/TrySigNozFloatingCard'
import TableOfContents from '../../../components/DocsTOC/DocsTOC'
import DocContent from '@/components/DocContent/DocContent'

export async function generateMetadata({
params,
Expand Down Expand Up @@ -59,18 +53,13 @@ export default async function Page({ params }: { params: { slug: string[] } }) {
const { title, hide_table_of_contents } = mainContent

return (
<>
<div className="doc">
<div className="doc-content">
<h2 className="mt-2 text-3xl">{title}</h2>
<MDXLayoutRenderer code={post.body.code} components={components} toc={post.toc || []} />
<PageFeedback />
<DocsPrevNext />
</div>

<TableOfContents toc={toc} hideTableOfContents={hide_table_of_contents || false} />
<TrySigNozFloatingCard />
</div>
</>
<div className="doc">
<DocContent
title={title}
post={post}
toc={toc}
hideTableOfContents={hide_table_of_contents || false}
/>
</div>
)
}
44 changes: 44 additions & 0 deletions components/DocContent/DocContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use client'

import React from 'react'
import { components } from '@/components/MDXComponents'
import { MDXLayoutRenderer } from 'pliny/mdx-components'
import PageFeedback from '../PageFeedback/PageFeedback'
import DocsPrevNext from '../DocsPrevNext/DocsPrevNext'
import TableOfContents from '../DocsTOC/DocsTOC'
import TrySigNozFloatingCard from '../TrySigNozFloatingCard/TrySigNozFloatingCard'
import { QUERY_PARAMS } from '@/constants/queryParams'
import { useSearchParams } from 'next/navigation'
import { ONBOARDING_SOURCE } from '@/constants/globals'

const DocContent: React.FC<{
title: string
post: any
toc: any
hideTableOfContents: boolean
}> = ({ title, post, toc, hideTableOfContents }) => {
const searchParams = useSearchParams()
const source = searchParams.get(QUERY_PARAMS.SOURCE)

return (
<>
<div className={`doc-content ${source === ONBOARDING_SOURCE ? 'product-onboarding' : ''}`}>
<h2 className="mt-2 text-3xl">{title}</h2>
<MDXLayoutRenderer code={post.body.code} components={components} toc={post.toc || []} />
<PageFeedback />
<DocsPrevNext />
</div>

{!hideTableOfContents && (
<TableOfContents
toc={toc}
hideTableOfContents={hideTableOfContents}
source={source || ''}
/>
)}
<TrySigNozFloatingCard source={source || ''} />
</>
)
}

export default DocContent
8 changes: 2 additions & 6 deletions components/DocsTOC/DocsTOC.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use client'

import React from 'react'
import { useSearchParams } from 'next/navigation'
import { QUERY_PARAMS } from '../../constants/queryParams'
import { ONBOARDING_SOURCE } from '../../constants/globals'
interface TocItemProps {
url: string
Expand All @@ -13,12 +11,10 @@ interface TocItemProps {
interface TableOfContentsProps {
toc: TocItemProps[]
hideTableOfContents: boolean
source: string
}

const TableOfContents: React.FC<TableOfContentsProps> = ({ toc, hideTableOfContents }) => {
const searchParams = useSearchParams()
const source = searchParams.get(QUERY_PARAMS.SOURCE)

const TableOfContents: React.FC<TableOfContentsProps> = ({ toc, hideTableOfContents, source }) => {
if (
hideTableOfContents ||
!toc ||
Expand Down
53 changes: 28 additions & 25 deletions components/TrySigNozFloatingCard/TrySigNozFloatingCard.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
'use client';
'use client'

import React, { useState, useEffect } from 'react';
import Link from 'next/link';
import { ArrowRight, X } from 'lucide-react';
import React, { useState, useEffect } from 'react'
import Link from 'next/link'
import { ArrowRight, X } from 'lucide-react'
import { ONBOARDING_SOURCE } from '@/constants/globals'

const TrySigNozFloatingCard: React.FC = () => {
const [isVisible, setIsVisible] = useState(true);
const TrySigNozFloatingCard: React.FC<{ source: string }> = ({ source }) => {
const [isVisible, setIsVisible] = useState(true)

useEffect(() => {
const cardClosed = localStorage.getItem('trySigNozCardClosed');
const cardClosed = localStorage.getItem('trySigNozCardClosed')
if (cardClosed) {
setIsVisible(false);
setIsVisible(false)
}
}, []);
}, [])

const handleClose = () => {
setIsVisible(false);
localStorage.setItem('trySigNozCardClosed', 'true');
};
setIsVisible(false)
localStorage.setItem('trySigNozCardClosed', 'true')
}

if (!isVisible) return null;
if (!isVisible || source === ONBOARDING_SOURCE) return null

return (
<div className="fixed bottom-8 right-8 w-64 bg-gradient-to-r from-gray-800 to-gray-900 rounded-xl px-4 py-6 shadow-lg hover:shadow-xl transition-all duration-300 ease-in-out transform hover:-translate-y-1 hidden lg:block">
<div className="fixed bottom-8 right-8 hidden w-64 transform rounded-xl bg-gradient-to-r from-gray-800 to-gray-900 px-4 py-6 shadow-lg transition-all duration-300 ease-in-out hover:-translate-y-1 hover:shadow-xl lg:block">
<button
onClick={handleClose}
className="absolute top-2 right-2 text-gray-400 hover:text-white"
className="absolute right-2 top-2 text-gray-400 hover:text-white"
aria-label="Close"
>
<X size={16} />
</button>
<h3 className="text-lg font-bold text-white mt-0 mb-2">Try SigNoz Cloud for FREE</h3>
<p className="text-gray-300 text-sm mb-3">Instant setup, predictable pricing, and advanced features without infrastructure hassles.</p>
<Link
id='try-signoz-cloud-floating-card-cta'
href="/teams/"
style={{color: 'white', textDecoration: 'none'}}
className="inline-block bg-signoz_robin-500 hover:bg-signoz_robin-600 text-white px-4 py-2 mt-6 rounded-lg text-sm font-semibold transition-colors duration-300 flex items-center justify-between"
<h3 className="mb-2 mt-0 text-lg font-bold text-white">Try SigNoz Cloud for FREE</h3>
<p className="mb-3 text-sm text-gray-300">
Instant setup, predictable pricing, and advanced features without infrastructure hassles.
</p>
<Link
id="try-signoz-cloud-floating-card-cta"
href="/teams/"
style={{ color: 'white', textDecoration: 'none' }}
className="mt-6 inline-block flex items-center justify-between rounded-lg bg-signoz_robin-500 px-4 py-2 text-sm font-semibold text-white transition-colors duration-300 hover:bg-signoz_robin-600"
>
<span>Get Started</span>
<ArrowRight size={16} />
</Link>
</div>
);
};
)
}

export default TrySigNozFloatingCard;
export default TrySigNozFloatingCard

0 comments on commit b8c0b4d

Please sign in to comment.