import * as React from "react" import styled from "styled-components" import { getConfig } from "jamplay-common/remote-config" import { shareContentToSocialMedia, SocialMediaShareContentType, SocialMediaProviderEnum } from "jamplay-common/client/share" import withTranslate from "jamplay-common/i18n/withTranslate" const copy = require("copy-to-clipboard") /** * Implement this Component * to have ability to share everying * it receive */ const SocialPanelStyleContainer = styled.div.attrs({ className: "SocialPanel" })` .SocialPanel__icon { width: 30px; height: 30px; background-size: contain; background-position: center center; margin-right: 8px; &:nth-last-child(1) { margin-right: 0px; } cursor: pointer; &:hover { opacity: 0.8; } } .SocialPanel__icon-wrapper { display: flex; } .SocialPanel__label { color: ${(props) => props.theme.grey}; font-size: 0.8rem; margin-bottom: 3px; } ` type SocialPanelPropTypes = { contentId: string contentType: SocialMediaShareContentType shareURL?: string } export function createNewURLFromPathname(pathname: string) { try { const host = new URL(window.location.origin) const url = new URL(pathname, host) return url.toString() } catch (e) { console.error(pathname, "is invalid") return "" } } function handleOnSocialMediaClick(params: { payload: { id: string type: SocialMediaShareContentType shareProvider: SocialMediaProviderEnum } }) { return () => { shareContentToSocialMedia({ payload: { ...params.payload, origin: window.location.href } }) } } const SocialItem = ({ shareParams, shareProvider, iconImageURL }: { iconImageURL: string shareParams: any shareProvider: SocialMediaProviderEnum }) => { const staticFolder = getConfig().publicRuntimeConfig.staticFolder || "" return (
) } export const SocialPanel: React.SFC = ( props: SocialPanelPropTypes & withTranslatePropType ) => { const staticFolder = getConfig().publicRuntimeConfig.staticFolder || "" let { t } = props if (!t) { t = (s) => s } const shareParams: any = { id: props.contentId, type: props.contentType } const copyLink = () => { const shareURL = props.shareURL ? createNewURLFromPathname(props.shareURL) : window.location.href copy(shareURL) alert("link copied!") } return (
) } export default withTranslate(SocialPanel) as React.SFC