Skip to content

Commit

Permalink
snapchat button could be used for sharing a content
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitardanailov committed Nov 24, 2024
1 parent 10a8c38 commit c00b59d
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apps/website/src/app/demos/snapchat-share/Content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use client'

import React, {FC} from 'react'
import useSnapKit from './hooks/useSnapKit'

const Component: FC = () => {
useSnapKit()

return (
<div>
<button
className="snapchat-custom-share-button"
data-share-url="https://zaynvipkey.fan3.io/share"
>
Share on Snapchat
</button>
</div>
)
}

export default Component
44 changes: 44 additions & 0 deletions apps/website/src/app/demos/snapchat-share/hooks/useSnapKit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {useEffect} from 'react'

declare global {
interface Window {
snapKitInit: () => void
}
}

/**
* Documentation page:
* https://developers.snap.com/snap-kit/creative-kit/web#customize-the-share-button
*/
const useSnapKit = () => {
useEffect(() => {
const loadSnapKit = () => {
const script = document.createElement('script')
script.src = 'https://sdk.snapkit.com/js/v1/create.js'
script.async = true

script.onload = () => {
setTimeout(() => {
console.log('Snap Kit SDK loaded')
})
}

script.onerror = () => {
console.error('Failed to load Snap Kit SDK')
}

document.body.appendChild(script)

window.snapKitInit = function () {
// @ts-ignore
snap.creativekit.initalizeShareButtons(
document.getElementsByClassName('snapchat-custom-share-button'),
)
}
}

loadSnapKit()
}, [])
}

export default useSnapKit
39 changes: 39 additions & 0 deletions apps/website/src/app/demos/snapchat-share/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use client'

import type {NextPage} from 'next'

import Content from './Content'

import Layout from '@/components/MainLayout'
import LeftDrawer from '@/components/Drawers/LeftDrawer'
import {menuItems} from '@/menu'

import {drawerWidth} from '@/config/layout'
import {LayoutProvider} from '@/providers'

import {title} from './seo'

const Title = () => {
return <h1>{title}</h1>
}

const PageContent = () => {
return (
<LayoutProvider>
<Content />
</LayoutProvider>
)
}

const Page: NextPage = () => {
return (
<Layout
PageContent={PageContent}
HeaderTitle={Title}
drawerWidth={drawerWidth}
LeftDrawer={<LeftDrawer items={menuItems} />}
/>
)
}

export default Page
15 changes: 15 additions & 0 deletions apps/website/src/app/demos/snapchat-share/seo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {InternalMetadata} from '@/seo/metadata'

const title = 'Simple Snapchat Share Button'
const description = 'Simple Snapchat Share Button'
const canonical = '/demos/snapchat-share'

const props: InternalMetadata = {
title,
description,
canonical,
}

export default props

export {title}

0 comments on commit c00b59d

Please sign in to comment.