From 422f1b7818329f6934a918ed5c40e8846c851a90 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 2 Jul 2023 02:33:18 -0700 Subject: [PATCH] Add functionality to PartyFooter buttons The "Edit info" and "Remix" buttons now have their proper functionality in PartyFooter, matching how they behave in PartyHeader --- components/party/PartyFooter/index.tsx | 94 ++++++++++++++++++++------ 1 file changed, 75 insertions(+), 19 deletions(-) diff --git a/components/party/PartyFooter/index.tsx b/components/party/PartyFooter/index.tsx index a3542634..99d669e4 100644 --- a/components/party/PartyFooter/index.tsx +++ b/components/party/PartyFooter/index.tsx @@ -14,6 +14,9 @@ import SegmentedControl from '~components/common/SegmentedControl' import Segment from '~components/common/Segment' import GridRepCollection from '~components/GridRepCollection' import GridRep from '~components/GridRep' +import RemixTeamAlert from '~components/dialogs/RemixTeamAlert' +import RemixedToast from '~components/toasts/RemixedToast' +import EditPartyModal from '../EditPartyModal' import api from '~utils/api' import { appState } from '~utils/appState' @@ -30,6 +33,7 @@ interface Props { party?: Party new: boolean editable: boolean + remixCallback: () => void updateCallback: (details: DetailsObject) => void } @@ -37,13 +41,15 @@ const PartyFooter = (props: Props) => { const { t } = useTranslation('common') const router = useRouter() - const { party } = useSnapshot(appState) + const { party: partySnapshot } = useSnapshot(appState) const youtubeUrlRegex = /(?:https:\/\/www\.youtube\.com\/watch\?v=|https:\/\/youtu\.be\/)([\w-]+)/g - // State: UI + // State: Component const [currentSegment, setCurrentSegment] = useState(0) + const [remixAlertOpen, setRemixAlertOpen] = useState(false) + const [remixToastOpen, setRemixToastOpen] = useState(false) // State: Data const [remixes, setRemixes] = useState([]) @@ -52,8 +58,8 @@ const PartyFooter = (props: Props) => { useEffect(() => { // Extract the video IDs from the description - if (party.description) { - const videoIds = extractYoutubeVideoIds(party.description) + if (partySnapshot.description) { + const videoIds = extractYoutubeVideoIds(partySnapshot.description) // Fetch the video titles for each ID const fetchPromises = videoIds.map(({ id }) => fetchYoutubeData(id)) @@ -62,7 +68,7 @@ const PartyFooter = (props: Props) => { Promise.all(fetchPromises).then((videoTitles) => { // Replace the video URLs in the description with LiteYoutubeEmbed elements const newDescription = reactStringReplace( - party.description, + partySnapshot.description, youtubeUrlRegex, (match, i) => ( { } else { setEmbeddedDescription('') } - }, [party.description]) + }, [partySnapshot.description]) async function fetchYoutubeData(videoId: string) { return await youtube @@ -154,6 +160,30 @@ const PartyFooter = (props: Props) => { }) } + // Actions: Remix team + function remixTeamCallback() { + setRemixToastOpen(true) + props.remixCallback() + } + + // Alerts: Remix team + function openRemixTeamAlert() { + setRemixAlertOpen(true) + } + + function handleRemixTeamAlertChange(open: boolean) { + setRemixAlertOpen(open) + } + + // Toasts: Remix team + function handleRemixToastOpenChanged(open: boolean) { + setRemixToastOpen(!open) + } + + function handleRemixToastCloseClicked() { + setRemixToastOpen(false) + } + const segmentedControl = ( { selected={currentSegment === 1} onClick={() => setCurrentSegment(1)} > - {t('footer.remixes.label', { count: party?.remixes?.length })} + {t('footer.remixes.label', { count: partySnapshot?.remixes?.length })} ) const descriptionSection = (
- {party && party.description && party.description.length > 0 && ( - {embeddedDescription} - )} - {(!party || !party.description) && ( + {partySnapshot && + partySnapshot.description && + partySnapshot.description.length > 0 && ( + {embeddedDescription} + )} + {(!partySnapshot || !partySnapshot.description) && (

{t('footer.description.empty')}

{props.editable && ( -
)} @@ -196,20 +233,24 @@ const PartyFooter = (props: Props) => { const remixesSection = (
- {party?.remixes?.length > 0 && ( + {partySnapshot?.remixes?.length > 0 && ( {renderRemixes()} )} - {party?.remixes?.length === 0 && ( + {partySnapshot?.remixes?.length === 0 && (

{t('footer.remixes.empty')}

-
)}
) function renderRemixes() { - return party?.remixes.map((party, i) => { + return partySnapshot?.remixes.map((party, i) => { return ( { {currentSegment === 0 && descriptionSection} {currentSegment === 1 && remixesSection} + + + + ) }