diff --git a/components/PartyDetails/index.scss b/components/PartyDetails/index.scss index e9df8d65..afb68168 100644 --- a/components/PartyDetails/index.scss +++ b/components/PartyDetails/index.scss @@ -3,6 +3,7 @@ flex-direction: column; margin: $unit-4x auto 0 auto; max-width: $grid-width; + padding-bottom: $unit-12x; @include breakpoint(phone) { padding: 0 $unit; @@ -10,13 +11,13 @@ .PartyDetails { display: none; - margin: 0 auto; + margin: 0 auto $unit-2x; max-width: $unit * 94; overflow: hidden; width: 100%; &.Visible { - margin-bottom: $unit-12x; + // margin-bottom: $unit-12x; } &.Editable { @@ -332,4 +333,21 @@ } } } + + .Remixes { + display: flex; + flex-direction: column; + gap: $unit-2x; + + h3 { + font-size: $font-medium; + font-weight: $medium; + } + + .GridRepCollection { + gap: $unit-2x; + margin-left: $unit-2x * -1; + margin-right: $unit-2x * -1; + } + } } diff --git a/components/PartyDetails/index.tsx b/components/PartyDetails/index.tsx index ee5927d9..b5c92081 100644 --- a/components/PartyDetails/index.tsx +++ b/components/PartyDetails/index.tsx @@ -3,6 +3,7 @@ import Link from 'next/link' import { useRouter } from 'next/router' import { useSnapshot } from 'valtio' import { useTranslation } from 'next-i18next' +import clonedeep from 'lodash.clonedeep' import Linkify from 'react-linkify' import LiteYouTubeEmbed from 'react-lite-youtube-embed' @@ -16,7 +17,8 @@ import CharLimitedFieldset from '~components/CharLimitedFieldset' import Input from '~components/Input' import DurationInput from '~components/DurationInput' import Token from '~components/Token' - +import GridRepCollection from '~components/GridRepCollection' +import GridRep from '~components/GridRep' import RaidDropdown from '~components/RaidDropdown' import TextFieldset from '~components/TextFieldset' import Switch from '~components/Switch' @@ -33,6 +35,7 @@ import EditIcon from '~public/icons/Edit.svg' import type { DetailsObject } from 'types' import './index.scss' +import api from '~utils/api' // Props interface Props { @@ -69,6 +72,8 @@ const PartyDetails = (props: Props) => { const [turnCount, setTurnCount] = useState(undefined) const [clearTime, setClearTime] = useState(0) + const [remixes, setRemixes] = useState([]) + const [raidSlug, setRaidSlug] = useState('') const [embeddedDescription, setEmbeddedDescription] = useState() @@ -111,6 +116,7 @@ const PartyDetails = (props: Props) => { setFullAuto(props.party.full_auto) setChargeAttack(props.party.charge_attack) setClearTime(props.party.clear_time) + setRemixes(props.party.remixes) if (props.party.turn_count) setTurnCount(props.party.turn_count) if (props.party.button_count) setButtonCount(props.party.button_count) if (props.party.chain_count) setChainCount(props.party.chain_count) @@ -300,6 +306,49 @@ const PartyDetails = (props: Props) => { props.deleteCallback() } + // Methods: Navigation + function goTo(shortcode: string) { + router.push(`/p/${shortcode}`) + } + + // Methods: Favorites + function toggleFavorite(teamId: string, favorited: boolean) { + if (favorited) unsaveFavorite(teamId) + else saveFavorite(teamId) + } + + function saveFavorite(teamId: string) { + api.saveTeam({ id: teamId }).then((response) => { + if (response.status == 201) { + const index = remixes.findIndex((p) => p.id === teamId) + const party = remixes[index] + + party.favorited = true + + let clonedParties = clonedeep(remixes) + clonedParties[index] = party + + setRemixes(clonedParties) + } + }) + } + + function unsaveFavorite(teamId: string) { + api.unsaveTeam({ id: teamId }).then((response) => { + if (response.status == 200) { + const index = remixes.findIndex((p) => p.id === teamId) + const party = remixes[index] + + party.favorited = false + + let clonedParties = clonedeep(remixes) + clonedParties[index] = party + + setRemixes(clonedParties) + } + }) + } + function extractYoutubeVideoIds(text: string) { // Initialize an array to store the video IDs const videoIds = [] @@ -388,6 +437,28 @@ const PartyDetails = (props: Props) => { ) } + function renderRemixes() { + return remixes.map((party, i) => { + return ( + + ) + }) + } + const deleteAlert = () => { if (party.editable) { return ( @@ -620,6 +691,15 @@ const PartyDetails = (props: Props) => { ) + const remixSection = () => { + return ( +
+

Remixes

+ {{renderRemixes()}} +
+ ) + } + return (
@@ -654,6 +734,7 @@ const PartyDetails = (props: Props) => {
{readOnly} {editable} + {remixes.length > 0 ? remixSection() : ''} {deleteAlert()}
)