All files / web/src/components/my-stuff PlayerStuffModal.tsx

0% Statements 0/205
0% Branches 0/1
0% Functions 0/1
0% Lines 0/205

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206                                                                                                                                                                                                                                                                                                                                                                                                                           
'use client'

import * as Dialog from '@radix-ui/react-dialog'
import Link from 'next/link'
import { useState } from 'react'
import {
  CelebrationSongsSection,
  EuclidCreationsSection,
  PostcardsSection,
} from '@/components/my-stuff/PlayerStuffSections'
import { Z_INDEX } from '@/constants/zIndex'
import { PortalContainerProvider } from '@/contexts/PortalContainerContext'
import { css } from '../../../styled-system/css'
import { hstack, vstack } from '../../../styled-system/patterns'

interface PlayerStuffModalProps {
  open: boolean
  onClose: () => void
  playerId: string
  playerName: string
  playerEmoji?: string
}

/**
 * Mini "My Stuff" modal — a compact view of one player's postcards, celebration
 * songs, and Euclid creations, summonable from the per-player popover in
 * `PracticeSubNav`. Renders the same factored sections as the full
 * `/my-stuff/player/[playerId]` page (never fork, always factor).
 */
export function PlayerStuffModal({
  open,
  onClose,
  playerId,
  playerName,
  playerEmoji,
}: PlayerStuffModalProps) {
  // Captured via callback ref so descendant Radix Portals (e.g. the song
  // ShareSongPopover) render inside the modal's stacking/focus context
  // instead of document.body — no z-index war, and they stay interactive.
  const [contentEl, setContentEl] = useState<HTMLDivElement | null>(null)

  return (
    <Dialog.Root open={open} onOpenChange={(o) => !o && onClose()}>
      <Dialog.Portal>
        <Dialog.Overlay
          data-element="player-stuff-modal-overlay"
          className={css({
            position: 'fixed',
            inset: 0,
            backgroundColor: 'rgba(0, 0, 0, 0.5)',
            zIndex: Z_INDEX.MODAL_BACKDROP,
            animation: 'fadeIn 0.15s ease',
          })}
        />

        <Dialog.Content
          ref={setContentEl}
          data-component="player-stuff-modal"
          className={css({
            position: 'fixed',
            top: { base: 0, md: '50%' },
            left: { base: 0, md: '50%' },
            transform: { base: 'none', md: 'translate(-50%, -50%)' },
            zIndex: Z_INDEX.MODAL,
            // Non-clipping positioned wrapper. It establishes the modal's
            // stacking + focus context and is the portal target for
            // descendant popovers (ShareSongPopover), so they overlap the
            // frame instead of being clipped by it. The visual box, rounded
            // corners, and scroll live on the inner frame below.
            overflow: 'visible',
            outline: 'none',
          })}
        >
          <PortalContainerProvider container={contentEl}>
            <div
              data-element="player-stuff-modal-frame"
              className={css({
                width: { base: '100vw', md: '92vw' },
                maxWidth: { base: 'none', md: '720px' },
                height: { base: '100vh', md: 'auto' },
                maxHeight: { base: '100vh', md: '85vh' },
                backgroundColor: 'gray.50',
                borderRadius: { base: 0, md: '16px' },
                boxShadow: '0 20px 60px rgba(0, 0, 0, 0.3)',
                overflow: 'hidden',
                display: 'flex',
                flexDirection: 'column',
              })}
            >
              {/* Header */}
              <div
                data-element="player-stuff-modal-header"
                className={hstack({
                  gap: '12px',
                  alignItems: 'center',
                  p: '16px 20px',
                  bg: 'white',
                  borderBottom: '1px solid token(colors.gray.200)',
                  flexShrink: 0,
                })}
              >
                <span
                  className={css({
                    fontSize: '28px',
                    lineHeight: '1',
                    w: '44px',
                    h: '44px',
                    display: 'flex',
                    alignItems: 'center',
                    justifyContent: 'center',
                    bg: 'gray.50',
                    borderRadius: '50%',
                    border: '1px solid token(colors.gray.200)',
                    flexShrink: 0,
                  })}
                >
                  {playerEmoji ?? '🧒'}
                </span>
                <div className={vstack({ alignItems: 'flex-start', gap: '1px', flex: 1, minW: 0 })}>
                  <Dialog.Title
                    className={css({
                      fontSize: '18px',
                      fontWeight: '800',
                      color: 'gray.900',
                      whiteSpace: 'nowrap',
                      overflow: 'hidden',
                      textOverflow: 'ellipsis',
                      maxW: '100%',
                    })}
                  >
                    {playerName}&apos;s Stuff
                  </Dialog.Title>
                  <Dialog.Description className={css({ fontSize: '12px', color: 'gray.500' })}>
                    Songs, creations & postcards
                  </Dialog.Description>
                </div>

                <Link
                  href={`/my-stuff/player/${playerId}`}
                  data-action="view-full-player-stuff"
                  onClick={onClose}
                  className={css({
                    fontSize: '13px',
                    fontWeight: '600',
                    color: 'blue.600',
                    textDecoration: 'none',
                    px: '10px',
                    py: '6px',
                    borderRadius: '8px',
                    flexShrink: 0,
                    _hover: { bg: 'blue.50', textDecoration: 'underline' },
                  })}
                >
                  View full page →
                </Link>

                <Dialog.Close asChild>
                  <button
                    type="button"
                    data-action="close-player-stuff-modal"
                    aria-label="Close"
                    className={css({
                      w: '32px',
                      h: '32px',
                      borderRadius: '8px',
                      border: 'none',
                      bg: 'transparent',
                      color: 'gray.500',
                      fontSize: '20px',
                      cursor: 'pointer',
                      display: 'flex',
                      alignItems: 'center',
                      justifyContent: 'center',
                      flexShrink: 0,
                      _hover: { bg: 'gray.100', color: 'gray.800' },
                    })}
                  >

                  </button>
                </Dialog.Close>
              </div>

              {/* Scrollable body */}
              <div
                data-element="player-stuff-modal-body"
                className={vstack({
                  alignItems: 'stretch',
                  gap: '32px',
                  p: '20px',
                  overflow: 'auto',
                  flex: 1,
                  minH: 0,
                })}
              >
                <PostcardsSection playerId={playerId} />
                <CelebrationSongsSection playerId={playerId} />
                <EuclidCreationsSection playerId={playerId} />
              </div>
            </div>
          </PortalContainerProvider>
        </Dialog.Content>
      </Dialog.Portal>
    </Dialog.Root>
  )
}