Skip to content

Commit

Permalink
refactor: reuse SharePageUrlButton
Browse files Browse the repository at this point in the history
  • Loading branch information
clintonlunn committed Nov 27, 2024
1 parent 47e4bd2 commit 2c994cd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 45 deletions.
4 changes: 3 additions & 1 deletion src/app/(default)/components/SharePageURLButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { ControlledTooltip } from '@/components/ui/Tooltip'
*/
export const SharePageURLButton: React.FC<{ path: string, name: string }> = ({ path, name }) => {
const slug = getFriendlySlug(name)
const url = `https://openbeta.io/${path}/${slug}`
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL != null ? process.env.NEXT_PUBLIC_BASE_URL : 'http://localhost:3000'
const optionalSlug = slug !== '' ? `/${slug}` : ''
const url = `${baseUrl}${path}${optionalSlug}`

const [clicked, setClicked] = useState(false)

Expand Down
7 changes: 5 additions & 2 deletions src/components/maps/TileHandlers/CragContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import { getAreaPageFriendlyUrl } from '@/js/utils'
import { EntityIcon } from '@/app/(default)/editArea/[slug]/general/components/AreaItem'
import { BaseDrawerContent } from './Drawer'
import { MiniCarousel } from '../CardGallery'
import { ShareButton } from '../../ui/ShareButton'
import { SharePageURLButton } from '@/app/(default)/components/SharePageURLButton'
import { usePathname } from 'next/navigation'

export const CragDrawerContent: React.FC<CragFeatureProperties> = ({ id, areaName, climbs, content: { description }, media }) => {
const friendlyUrl = getAreaPageFriendlyUrl(id, areaName)
const editUrl = `/editArea/${id}/general`
const pathname = `${usePathname()}${window.location.search}`

return (
<>
<BaseDrawerContent
media={<MiniCarousel mediaList={media} />}
heading={<Link href={friendlyUrl}>{areaName}</Link>}
subheading={<Subheading id={id} totalClimbs={climbs.length} />}
cta={<Link className='btn btn-primary btn-outline btn-sm no-animation' href={editUrl}>Edit area</Link>}
share={<ShareButton />}
share={<SharePageURLButton path={pathname} name='' />}
>
<section className='text-sm'>
{description == null || description.trim() === ''
Expand Down
42 changes: 0 additions & 42 deletions src/components/ui/ShareButton.tsx

This file was deleted.

0 comments on commit 2c994cd

Please sign in to comment.