Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added share music modal #68

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions app/components/ShareModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";

interface ShareModalProps {
isOpen: boolean;
onClose: () => void;
shareableLink: string;
}

export const ShareModal: React.FC<ShareModalProps> = ({
isOpen,
onClose,
shareableLink,
}) => {
if (!isOpen) return null;

const platforms = ["Twitter", "LinkedIn", "WhatsApp"];

return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50">
<div className="bg-white rounded-lg p-6 shadow-lg max-w-lg w-full relative">
<h2 className="text-lg font-bold text-gray-900">Share this link</h2>
<button
className="absolute top-3 right-3 text-gray-400 hover:text-gray-600"
onClick={onClose}
aria-label="Close"
>
&times;
</button>
<div className="space-y-4 mt-4">
{platforms.map((platform) => (
<button
key={platform}
onClick={() =>
window.open(
`https://www.${platform.toLowerCase()}.com/share?url=${encodeURIComponent(
shareableLink
)}`,
"_blank"
)
}
className="w-full bg-purple-700 hover:bg-purple-800 text-white py-2 rounded-lg"
>
Share on {platform}
</button>
))}
</div>
</div>
</div>
);
};
42 changes: 15 additions & 27 deletions app/components/StreamView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'react-lite-youtube-embed/dist/LiteYouTubeEmbed.css'
import { YT_REGEX } from '../lib/utils'
//@ts-ignore
import YouTubePlayer from 'youtube-player';

import { ShareModal } from '../components/ShareModal';
interface Video {
"id": string,
"type": string,
Expand Down Expand Up @@ -43,7 +43,15 @@ export default function StreamView({
const [loading, setLoading] = useState(false);
const [playNextLoader, setPlayNextLoader] = useState(false);
const videoPlayerRef = useRef<HTMLDivElement>();
const [isModalOpen, setIsModalOpen] = useState(false);

const handleShare = () => {
setIsModalOpen(true);
}

const closeModal = () => {
setIsModalOpen(false);
}
async function refreshStreams() {
const res = await fetch(`/api/streams/?creatorId=${creatorId}`, {
credentials: "include"
Expand Down Expand Up @@ -141,31 +149,6 @@ export default function StreamView({
}
}

const handleShare = () => {
const shareableLink = `${window.location.hostname}/creator/${creatorId}`
navigator.clipboard.writeText(shareableLink).then(() => {
toast.success('Link copied to clipboard!', {
position: "top-right",
autoClose: 3000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
})
}, (err) => {
console.error('Could not copy text: ', err)
toast.error('Failed to copy link. Please try again.', {
position: "top-right",
autoClose: 3000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
})
})
}

return (
<div className="flex flex-col min-h-screen bg-[rgb(10,10,10)] text-gray-200">
Expand Down Expand Up @@ -274,6 +257,11 @@ export default function StreamView({
pauseOnHover
theme="dark"
/>
<ShareModal
isOpen={isModalOpen}
onClose={closeModal}
shareableLink={`${window.location.hostname}/creator/${creatorId}`}
/>
</div>
)
}
}