v0 Anay commited on
Commit
f5e80db
·
1 Parent(s): 3a798a3

feat: redesign player card and pitch for better scaling

Browse files

Enlarge pitch and player card dimensions; fix badge scaling on mobile.

Co-authored-by: Anay <129646663+anay1104@users.noreply.github.com>

frontend/src/components/PitchView.jsx CHANGED
@@ -3,18 +3,31 @@ import React, { useRef, useState, useEffect, useCallback } from "react";
3
  import { DraggablePlayer } from "./DraggablePlayer";
4
 
5
  /*
6
- DESIGN DIMENSIONS
7
- Card slot height = CARD_H(80) + mt(1) + label(48) = 129px
8
- 4 starter rows = 516px
9
- STARTERS_H = 660: usable = 660-48(py-6) = 612, leaves 96px = ~19px × 5 gaps via justify-evenly ✓
10
- BENCH_H = 180: card(80) + label(48) + mt(1) + pt(16) + pb(35) = 180 ✓
11
- DESIGN_WIDTH = 680: fits 5 cards × 88px + 4 gaps × 40px = 440 + 160 = 600px + 40px padding ✓
 
 
 
 
 
 
 
 
 
 
12
  */
13
- const DESIGN_WIDTH = 520;
14
- const STARTERS_H = 660;
15
- const BENCH_H = 180;
16
  // Gap between player card wrappers in px (in design space)
17
  const CARD_GAP = 24;
 
 
 
18
 
19
  export const PitchView = ({
20
  teamData,
@@ -39,7 +52,10 @@ export const PitchView = ({
39
  const updateScale = useCallback(() => {
40
  if (!containerRef.current) return;
41
  const w = containerRef.current.offsetWidth;
42
- setScale(Math.min(1, w / DESIGN_WIDTH));
 
 
 
43
  }, []);
44
 
45
  useEffect(() => {
@@ -180,4 +196,4 @@ export const PitchView = ({
180
  </div>
181
  </div>
182
  );
183
- };
 
3
  import { DraggablePlayer } from "./DraggablePlayer";
4
 
5
  /*
6
+ DESIGN DIMENSIONS — single source of truth for the pitch.
7
+ All cards are laid out at these fixed pixel dimensions and the whole pitch
8
+ is uniformly transform-scaled to fit the actual container. This keeps
9
+ proportions identical across every screen size (no element gets relatively
10
+ bigger or smaller than another when the viewport changes).
11
+
12
+ Card slot height = CARD_H(104) + mt(1) + label(~50) = 155px
13
+ 4 starter rows = 620px content + 48px py-padding + 5 evenly-distributed gaps
14
+ STARTERS_H = 760 → ~18px between rows via justify-evenly ✓
15
+ BENCH_H = 210 → card(104) + label(50) + mt(1) + pt(16) + pb(32) = 203 + slack ✓
16
+
17
+ DESIGN_WIDTH = 600: fits widest row (5 mids/defs) = 5×84 + 4×24 = 516 ≤ 600 ✓
18
+ Bench (4 cards): 4×84 + 3×24 + 48px padding = 456 ≤ 600 ✓
19
+
20
+ MAX_SCALE > 1 lets the pitch grow modestly on wide desktops instead of
21
+ capping at design size and looking marooned in whitespace.
22
  */
23
+ const DESIGN_WIDTH = 600;
24
+ const STARTERS_H = 760;
25
+ const BENCH_H = 210;
26
  // Gap between player card wrappers in px (in design space)
27
  const CARD_GAP = 24;
28
+ // Allow the pitch to scale up to 1.1× on wide screens so cards don't look
29
+ // undersized on desktop. Below DESIGN_WIDTH it scales down naturally to fit.
30
+ const MAX_SCALE = 1.1;
31
 
32
  export const PitchView = ({
33
  teamData,
 
52
  const updateScale = useCallback(() => {
53
  if (!containerRef.current) return;
54
  const w = containerRef.current.offsetWidth;
55
+ // Allow scaling up to MAX_SCALE on wider screens; scale down proportionally
56
+ // on narrow screens. This keeps every element (cards, badges, text)
57
+ // visually consistent at any viewport.
58
+ setScale(Math.min(MAX_SCALE, w / DESIGN_WIDTH));
59
  }, []);
60
 
61
  useEffect(() => {
 
196
  </div>
197
  </div>
198
  );
199
+ };
frontend/src/components/PlayerCardVisual.jsx CHANGED
@@ -4,9 +4,17 @@ import { getShortName } from "../utils/teams";
4
  import { getPlayerPrice } from "../utils/fplLogic";
5
  import { PlayerContext } from "../PlayerContext";
6
 
7
- // Fixed card dimensions — these are design-space pixels (before PitchView scaling)
8
- const CARD_W = 72;
9
- const CARD_H = 88; // photo card height only (label strip is separate, in flow below)
 
 
 
 
 
 
 
 
10
 
11
  export const PlayerCardVisual = ({
12
  player,
@@ -31,24 +39,28 @@ export const PlayerCardVisual = ({
31
  className="relative flex flex-col items-center justify-center cursor-pointer border-2 border-dashed border-slate-500 bg-slate-900/60 rounded-xl hover:bg-slate-800 hover:border-emerald-400 transition-all z-20 shadow-inner group"
32
  >
33
  {player.replacedPlayer && (
34
- <div className="absolute left-[1px] top-[1px] flex flex-col gap-[1px] z-40 pointer-events-auto">
 
 
 
35
  <button
36
  onPointerDown={(e) => e.stopPropagation()}
37
  onClick={(e) => onUndo(e, player.ID, player.replacedPlayer)}
38
- className="w-[11px] h-[11px] flex items-center justify-center rounded-full bg-red-600 hover:bg-red-500 text-white transition-colors border border-red-400 shadow-lg"
 
39
  title="Undo transfer"
40
  >
41
- <RotateCcw size={8} strokeWidth={3} />
42
  </button>
43
  </div>
44
  )}
45
- <Plus className="text-slate-500 group-hover:text-emerald-400 transition-colors mb-1" size={20} />
46
- <span className="text-[8px] font-black text-slate-500 group-hover:text-emerald-400 uppercase tracking-widest">
47
  {player.Pos}
48
  </span>
49
  </div>
50
  {/* Placeholder label area so blank slots have identical height to real cards */}
51
- <div style={{ height: 48 }} />
52
  </div>
53
  );
54
  }
@@ -129,10 +141,12 @@ export const PlayerCardVisual = ({
129
  });
130
  };
131
 
 
 
132
  const evStyles = [
133
- "text-emerald-400 text-[11px] font-extrabold",
134
- "text-emerald-500 text-[9px] font-bold",
135
- "text-emerald-600 text-[7px] font-semibold",
136
  ];
137
 
138
  const isTransferIn = Boolean(player.replacedPlayer || onSolverUndo);
@@ -158,17 +172,29 @@ export const PlayerCardVisual = ({
158
  `}
159
  style={{ width: CARD_W, height: CARD_H }}
160
  >
161
- {/* C / V buttons — small by design; PitchView scale handles mobile shrinking */}
162
- <div className="absolute left-[1px] top-[1px] flex flex-col gap-[1px] z-40 pointer-events-auto">
 
 
 
 
 
 
 
 
 
 
 
163
  {!isBench && handleCapChange && (
164
  <>
165
  <button
166
  onPointerDown={(e) => e.stopPropagation()}
167
  onClick={(e) => { e.stopPropagation(); handleCapChange(player.ID, "C"); }}
168
- className={`w-[11px] h-[11px] flex items-center justify-center rounded-full text-[6px] font-bold transition-colors shadow-md transform-gpu
 
169
  ${isCap
170
  ? activeChipType === "tc"
171
- ? "bg-purple-500 text-white border border-purple-300 text-[7px]"
172
  : "bg-yellow-400 text-slate-900 border border-white"
173
  : "bg-slate-900/90 text-slate-400 border border-slate-700 hover:text-yellow-400"
174
  }`}
@@ -178,7 +204,8 @@ export const PlayerCardVisual = ({
178
  <button
179
  onPointerDown={(e) => e.stopPropagation()}
180
  onClick={(e) => { e.stopPropagation(); handleCapChange(player.ID, "V"); }}
181
- className={`w-[11px] h-[11px] flex items-center justify-center rounded-full text-[6px] font-bold transition-colors shadow-md
 
182
  ${isVice ? "bg-slate-300 text-slate-900 border border-white" : "bg-slate-900/90 text-slate-400 border border-slate-700 hover:text-white"}`}
183
  >
184
  V
@@ -189,23 +216,30 @@ export const PlayerCardVisual = ({
189
  <button
190
  onPointerDown={(e) => e.stopPropagation()}
191
  onClick={(e) => { e.stopPropagation(); onSolverUndo(player); }}
192
- className="w-[11px] h-[11px] flex items-center justify-center rounded-full bg-red-600 hover:bg-red-500 text-white transform-gpu transition-colors border border-red-400"
 
193
  >
194
- <RotateCcw size={8} strokeWidth={3} />
195
  </button>
196
  ) : player.replacedPlayer ? (
197
  <button
198
  onPointerDown={(e) => e.stopPropagation()}
199
  onClick={(e) => onUndo(e, player.ID, player.replacedPlayer)}
200
- className="w-[11px] h-[11px] flex items-center justify-center rounded-full bg-red-600 hover:bg-red-500 text-white transform-gpu transition-colors border border-red-400"
 
201
  >
202
- <RotateCcw size={8} strokeWidth={3} />
203
  </button>
204
  ) : null}
205
  </div>
206
 
207
- {/* EV numbers — pulled closer to card edge */}
208
- <div className="absolute right-[2px] top-[2px] flex flex-col items-end z-30 pointer-events-none drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]">
 
 
 
 
 
209
  {playerCardGWs.map((gw, i) => (
210
  <span key={gw} className={`${evStyles[i]} leading-tight tabular-nums`}>
211
  {Number(player[`${gw}_Pts`] || 0).toFixed(2)}
@@ -234,27 +268,36 @@ export const PlayerCardVisual = ({
234
  )}
235
  </div>
236
 
237
- {/* ── LABEL STRIP — in normal flow below the card ── */}
 
 
 
 
 
 
 
 
 
238
  <div
239
  draggable="false"
240
  className={`flex flex-col items-center z-30 pointer-events-none mt-[1px] flex-shrink-0 ${isBench ? "opacity-80" : "opacity-100"}`}
241
- style={{ width: "110%" }} // 110% of 88px = 97px — fits in 88+40=128px slot gap
242
  >
243
- <div className={`w-full text-center py-[2px] truncate px-1 font-bold text-[8px] rounded-t shadow-md
244
  ${isTransferIn ? "bg-cyan-600 text-white" : "bg-slate-950 text-slate-100 border border-slate-700"}`}>
245
  {player.Name}
246
  </div>
247
  <div className="w-full bg-slate-200 border-x border-slate-700 flex justify-center items-center gap-1 py-[2px] shadow-inner">
248
- <span className={`text-[8px] font-black flex items-baseline gap-[2px] ${isBlankThisGw ? "text-slate-400" : "text-slate-800"}`}>
249
  {isBlankThisGw ? "-" : (player[`${activeGW}_xMins`] ?? 90)}
250
- <span className="text-[6px] font-bold text-slate-500 uppercase tracking-tight">xMins</span>
251
  </span>
252
- <span className="text-slate-400 font-light text-[8px]">|</span>
253
- <span className="text-[8px] font-black text-emerald-700">
254
  £{getPlayerPrice(player).toFixed(1)}
255
  </span>
256
  </div>
257
- <div className="w-full bg-slate-900 border-x border-b border-slate-700 flex items-center rounded-b shadow-md px-0.5 overflow-hidden" style={{ height: 17 }}>
258
  <div className="flex items-center justify-center w-full whitespace-nowrap overflow-hidden">
259
  {renderFixtures(player.Team, activeGW)}
260
  </div>
@@ -264,4 +307,4 @@ export const PlayerCardVisual = ({
264
  );
265
  };
266
 
267
- export default memo(PlayerCardVisual);
 
4
  import { getPlayerPrice } from "../utils/fplLogic";
5
  import { PlayerContext } from "../PlayerContext";
6
 
7
+ // Fixed card dimensions — these are design-space pixels (before PitchView scaling).
8
+ // Sized to match the reference aesthetic: roughly 1.24:1 height-to-width photo
9
+ // area, large enough that the player photo, EV, and C/V badges all read clearly
10
+ // at design scale, and that scale down gracefully on narrow viewports because
11
+ // the entire pitch is uniformly transform-scaled by PitchView.
12
+ const CARD_W = 84;
13
+ const CARD_H = 104; // photo card height only (label strip is separate, in flow below)
14
+ // Badge dimensions for C / V / Reset stack. Kept compact (~15% of card width)
15
+ // so they never visually overpower the photo, and use a large enough font that
16
+ // mobile browsers don't auto-inflate it (the cause of "huge badges on mobile").
17
+ const BADGE_SIZE = 13;
18
 
19
  export const PlayerCardVisual = ({
20
  player,
 
39
  className="relative flex flex-col items-center justify-center cursor-pointer border-2 border-dashed border-slate-500 bg-slate-900/60 rounded-xl hover:bg-slate-800 hover:border-emerald-400 transition-all z-20 shadow-inner group"
40
  >
41
  {player.replacedPlayer && (
42
+ <div
43
+ className="absolute left-[2px] top-[2px] flex flex-col gap-[2px] z-40 pointer-events-auto"
44
+ style={{ WebkitTextSizeAdjust: "100%" }}
45
+ >
46
  <button
47
  onPointerDown={(e) => e.stopPropagation()}
48
  onClick={(e) => onUndo(e, player.ID, player.replacedPlayer)}
49
+ style={{ width: BADGE_SIZE, height: BADGE_SIZE }}
50
+ className="flex items-center justify-center rounded-full bg-red-600 hover:bg-red-500 text-white transition-colors border border-red-400 shadow-lg"
51
  title="Undo transfer"
52
  >
53
+ <RotateCcw size={9} strokeWidth={3} />
54
  </button>
55
  </div>
56
  )}
57
+ <Plus className="text-slate-500 group-hover:text-emerald-400 transition-colors mb-1" size={22} />
58
+ <span className="text-[9px] font-black text-slate-500 group-hover:text-emerald-400 uppercase tracking-widest">
59
  {player.Pos}
60
  </span>
61
  </div>
62
  {/* Placeholder label area so blank slots have identical height to real cards */}
63
+ <div style={{ height: 50 }} />
64
  </div>
65
  );
66
  }
 
141
  });
142
  };
143
 
144
+ // EV text sizes — bumped slightly to match the larger card. Primary GW gets
145
+ // the strongest visual weight, subsequent GWs taper down for hierarchy.
146
  const evStyles = [
147
+ "text-emerald-400 text-[12px] font-extrabold",
148
+ "text-emerald-500 text-[10px] font-bold",
149
+ "text-emerald-600 text-[8px] font-semibold",
150
  ];
151
 
152
  const isTransferIn = Boolean(player.replacedPlayer || onSolverUndo);
 
172
  `}
173
  style={{ width: CARD_W, height: CARD_H }}
174
  >
175
+ {/*
176
+ C / V / Reset stack.
177
+ - Sized via the BADGE_SIZE constant so all three badges always match.
178
+ - WebkitTextSizeAdjust: "100%" stops iOS Safari from auto-enlarging
179
+ the small label text, which was the root cause of the badges
180
+ looking oversized and obstructing other players on mobile.
181
+ - The whole stack lives inside PitchView's scale transform, so it
182
+ shrinks/grows uniformly with the rest of the pitch.
183
+ */}
184
+ <div
185
+ className="absolute left-[2px] top-[2px] flex flex-col gap-[2px] z-40 pointer-events-auto"
186
+ style={{ WebkitTextSizeAdjust: "100%" }}
187
+ >
188
  {!isBench && handleCapChange && (
189
  <>
190
  <button
191
  onPointerDown={(e) => e.stopPropagation()}
192
  onClick={(e) => { e.stopPropagation(); handleCapChange(player.ID, "C"); }}
193
+ style={{ width: BADGE_SIZE, height: BADGE_SIZE }}
194
+ className={`flex items-center justify-center rounded-full text-[7px] font-bold leading-none transition-colors shadow-md transform-gpu
195
  ${isCap
196
  ? activeChipType === "tc"
197
+ ? "bg-purple-500 text-white border border-purple-300 text-[8px]"
198
  : "bg-yellow-400 text-slate-900 border border-white"
199
  : "bg-slate-900/90 text-slate-400 border border-slate-700 hover:text-yellow-400"
200
  }`}
 
204
  <button
205
  onPointerDown={(e) => e.stopPropagation()}
206
  onClick={(e) => { e.stopPropagation(); handleCapChange(player.ID, "V"); }}
207
+ style={{ width: BADGE_SIZE, height: BADGE_SIZE }}
208
+ className={`flex items-center justify-center rounded-full text-[7px] font-bold leading-none transition-colors shadow-md
209
  ${isVice ? "bg-slate-300 text-slate-900 border border-white" : "bg-slate-900/90 text-slate-400 border border-slate-700 hover:text-white"}`}
210
  >
211
  V
 
216
  <button
217
  onPointerDown={(e) => e.stopPropagation()}
218
  onClick={(e) => { e.stopPropagation(); onSolverUndo(player); }}
219
+ style={{ width: BADGE_SIZE, height: BADGE_SIZE }}
220
+ className="flex items-center justify-center rounded-full bg-red-600 hover:bg-red-500 text-white transform-gpu transition-colors border border-red-400 shadow-md"
221
  >
222
+ <RotateCcw size={9} strokeWidth={3} />
223
  </button>
224
  ) : player.replacedPlayer ? (
225
  <button
226
  onPointerDown={(e) => e.stopPropagation()}
227
  onClick={(e) => onUndo(e, player.ID, player.replacedPlayer)}
228
+ style={{ width: BADGE_SIZE, height: BADGE_SIZE }}
229
+ className="flex items-center justify-center rounded-full bg-red-600 hover:bg-red-500 text-white transform-gpu transition-colors border border-red-400 shadow-md"
230
  >
231
+ <RotateCcw size={9} strokeWidth={3} />
232
  </button>
233
  ) : null}
234
  </div>
235
 
236
+ {/* EV numbers — pulled to the top-right corner. Slightly larger than
237
+ before to match the larger card; the primary EV is most prominent
238
+ and subsequent gameweeks gradually de-emphasize. */}
239
+ <div
240
+ className="absolute right-[3px] top-[2px] flex flex-col items-end z-30 pointer-events-none drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]"
241
+ style={{ WebkitTextSizeAdjust: "100%" }}
242
+ >
243
  {playerCardGWs.map((gw, i) => (
244
  <span key={gw} className={`${evStyles[i]} leading-tight tabular-nums`}>
245
  {Number(player[`${gw}_Pts`] || 0).toFixed(2)}
 
268
  )}
269
  </div>
270
 
271
+ {/*
272
+ LABEL STRIP — in normal flow below the photo card.
273
+ Width is 110% of CARD_W (≈92px @ design) so the strip slightly
274
+ overhangs the card for that classic FPL look, while still fitting
275
+ comfortably inside the CARD_GAP (24px) so neighbouring labels never
276
+ collide on any viewport.
277
+ WebkitTextSizeAdjust: "100%" prevents iOS Safari from inflating the
278
+ small label text — without this the name/stats wrap or overflow on
279
+ mobile.
280
+ */}
281
  <div
282
  draggable="false"
283
  className={`flex flex-col items-center z-30 pointer-events-none mt-[1px] flex-shrink-0 ${isBench ? "opacity-80" : "opacity-100"}`}
284
+ style={{ width: "110%", WebkitTextSizeAdjust: "100%" }}
285
  >
286
+ <div className={`w-full text-center py-[2px] truncate px-1 font-bold text-[9px] leading-tight rounded-t shadow-md
287
  ${isTransferIn ? "bg-cyan-600 text-white" : "bg-slate-950 text-slate-100 border border-slate-700"}`}>
288
  {player.Name}
289
  </div>
290
  <div className="w-full bg-slate-200 border-x border-slate-700 flex justify-center items-center gap-1 py-[2px] shadow-inner">
291
+ <span className={`text-[9px] font-black flex items-baseline gap-[2px] leading-none ${isBlankThisGw ? "text-slate-400" : "text-slate-800"}`}>
292
  {isBlankThisGw ? "-" : (player[`${activeGW}_xMins`] ?? 90)}
293
+ <span className="text-[7px] font-bold text-slate-500 uppercase tracking-tight">xMins</span>
294
  </span>
295
+ <span className="text-slate-400 font-light text-[9px] leading-none">|</span>
296
+ <span className="text-[9px] font-black text-emerald-700 leading-none">
297
  £{getPlayerPrice(player).toFixed(1)}
298
  </span>
299
  </div>
300
+ <div className="w-full bg-slate-900 border-x border-b border-slate-700 flex items-center rounded-b shadow-md px-0.5 overflow-hidden" style={{ height: 19 }}>
301
  <div className="flex items-center justify-center w-full whitespace-nowrap overflow-hidden">
302
  {renderFixtures(player.Team, activeGW)}
303
  </div>
 
307
  );
308
  };
309
 
310
+ export default memo(PlayerCardVisual);