| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- "use client";
- /*
- import Script from "next/script";
- import {
- createContext,
- useContext,
- useState
- } from "react";
- type ShareToSocialName = "pinterest" | "facebook" | "teitter" | "X" | "x" | "whatsapp" | "email" | "copy_link";
- type SDKLoadState = "none" | "loading" | "error" | "success";
- type SDKName = "pinterest";
- interface SocialSDKState {
- pinterest: SDKLoadState;
- }
- interface SocialShareContextProps {
- loadSDKState: SocialSDKState;
- }
- const pinterestShareSDKURL = "https://assets.pinterest.com/js/pinit.js";
- const SocialShareContext = createContext<SocialShareContextProps|null>(null);
- export function SocialShareProvider({
- children
- }: {
- children:React.ReactNode;
- }){
- const [loadSDKState, setLoadSDKState] = useState<SocialSDKState>({
- pinterest: 'none', // none loading error success
- });
- const onSdkLoad = (m:SDKName) => {
- setLoadSDKState((prev) => {
- return {
- ...prev,
- [m]: 'success'
- }
- });
- };
- const onSdkError = (m:SDKName) => {
- setLoadSDKState((prev) => {
- return {
- ...prev,
- [m]: 'error'
- }
- });
- };
- const handlerShare = ({
- name,
- url,
- title,
- pic,
- }:{
- name: ShareToSocialName;
- url: string;
- title: string;
- pic: string;
- }) => {
- var facebook = 'https://www.facebook.com/sharer/sharer.php?u={url}&t={title}&pic={pic}';
-
- if(name === 'pinterest') {
- if(loadSDKState.pinterest === 'success') {
- // window.PinUtils.pinOne({
- // url: url,
- // media: pic,
- // description: title,
- // });
- }
-
- } else if(name === 'facebook') {
- // shareModal.simpleShare.facebook();
- var facebook = 'https://www.facebook.com/sharer/sharer.php?u={url}&t={title}&pic={pic}';
- } else if(name === 'teitter') {
- var twitter = 'https://twitter.com/intent/tweet?text={title}&url={url}';
- } else if(name === 'whatsapp') {
- var waShareUrl = 'https://wa.me/?text=' + window.encodeURIComponent(title + url)
- window.open(waShareUrl,'t','toolbar=0,resizable=1,status=0,width=640,height=528,left=500,top=300');
- }else if(name === 'email') {
- // var aDom = jQuery('<a></a>');
- // aDom.attr('href', 'mailto:?subject=' + window.encodeURIComponent('Share Alipearlhair Product') + '&body=' + window.encodeURIComponent(shareModal.shareInfo.url));
- // aDom[0].click();
- } else if(name === 'copy_link') {
- // shareModal.copyText(shareModal.shareInfo.url);
- }
- };
- return (
- <SocialShareContext.Provider
- value={{
- loadSDKState
- }}
- >
-
- <Script id="pinterest-share-sdk" strategy="lazyOnload"
- src={pinterestShareSDKURL}
- onLoad={() => onSdkLoad('pinterest')}
- onError={() => {
- onSdkError('pinterest');
- }}
- />
-
- {children}
- </SocialShareContext.Provider>
- )
- }
- export const useSocialShareContext = () => {
- const context = useContext(SocialShareContext);
- if (!context) {
- throw new Error("useSocialShareContext must be used within a SocialShareProvider");
- }
- return context;
- };
- */
|