From 5bc83e69884248f4884354fef9273116119e4a74 Mon Sep 17 00:00:00 2001 From: Bentroen <29354120+Bentroen@users.noreply.github.com> Date: Fri, 20 Dec 2024 02:01:20 -0300 Subject: [PATCH 01/29] feat: add popup with licensing info when downloading a song --- .../song/components/SongPageButtons.tsx | 38 +++++++---- .../components/client/DownloadSongModal.tsx | 68 +++++++++++++++++++ 2 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 web/src/modules/song/components/client/DownloadSongModal.tsx diff --git a/web/src/modules/song/components/SongPageButtons.tsx b/web/src/modules/song/components/SongPageButtons.tsx index 7aab4cb1..fbc1e11a 100644 --- a/web/src/modules/song/components/SongPageButtons.tsx +++ b/web/src/modules/song/components/SongPageButtons.tsx @@ -16,6 +16,7 @@ import Link from 'next/link'; import { useState } from 'react'; import { toast } from 'react-hot-toast'; +import DownloadSongModal from './client/DownloadSongModal'; import ShareModal from './client/ShareModal'; import { downloadSongFile, openSongInNBS } from '../util/downloadSong'; @@ -199,22 +200,29 @@ const showOpenFailedToast = () => { ); }; -const DownloadSongButton = ({ - song, -}: { - song: { - publicId: string; - title: string; - downloadCount: number; - }; -}) => { +const DownloadSongButton = ({ song }: { song: SongViewDtoType }) => { + const [isDownloadModalOpen, setIsDownloadModalOpen] = useState(false); + return ( - { - downloadSongFile(song); - }} - /> + <> + { + setIsDownloadModalOpen(true); + }} + />{' '} + { + setIsDownloadModalOpen(isOpen); + + setTimeout(() => { + downloadSongFile(song); + }, 3000); + }} + song={song} + /> + ); }; diff --git a/web/src/modules/song/components/client/DownloadSongModal.tsx b/web/src/modules/song/components/client/DownloadSongModal.tsx new file mode 100644 index 00000000..1218f5f5 --- /dev/null +++ b/web/src/modules/song/components/client/DownloadSongModal.tsx @@ -0,0 +1,68 @@ +'use client'; + +import { SongViewDtoType } from '@shared/validation/song/dto/types'; +import { useState } from 'react'; + +import { DownloadPopupAdSlot } from '@web/src/modules/shared/components/client/ads/AdSlots'; +import GenericModal from '@web/src/modules/shared/components/client/GenericModal'; + +export default function DownloadSongModal({ + isOpen, + setIsOpen, + song, +}: { + isOpen: boolean; + setIsOpen: (isOpen: boolean) => void; + song: SongViewDtoType; +}) { + const [isCopied, setIsCopied] = useState(false); + + let licenseInfo; + + if (song.license == 'cc_by_sa') { + licenseInfo = `"${song.title}" by ${song.uploader.username} is licensed under CC BY-SA 4.0\n(https://creativecommons.org/licenses/by-sa/4.0)\n${process.env.NEXT_PUBLIC_URL}/song/${song.publicId}`; + } else { + licenseInfo = `"${song.title}" by ${song.uploader.username}. All rights reserved.\n${process.env.NEXT_PUBLIC_URL}/song/${song.publicId}`; + } + + const handleCopy = () => () => { + navigator.clipboard.writeText(licenseInfo); + + setIsCopied(true); + + setTimeout(() => { + setIsCopied(false); + }, 1000); + }; + + return ( + +

+ If you plan to use this song in your own creations, provide attribution + to the author by attaching the following text: +

+
+ {/* Attribution box */} +