@sensiblestats/widget-react 0.54.0 → 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4152,6 +4152,24 @@ function useGamePlay(conversation, { gameId, gameDay, fixtureId, refresh }) {
4152
4152
  convRef.current = conversation;
4153
4153
  const optsRef = useRef11({ gameId, gameDay, fixtureId, refresh });
4154
4154
  optsRef.current = { gameId, gameDay, fixtureId, refresh };
4155
+ const resultRef = useRef11(null);
4156
+ resultRef.current = result;
4157
+ const refetch = useCallback8(async () => {
4158
+ const conv = convRef.current;
4159
+ if (!conv) return;
4160
+ const opts = optsRef.current;
4161
+ try {
4162
+ const payload = await conv.getGameResult(opts.gameId, opts.fixtureId, opts.gameDay);
4163
+ if (payload === null) return;
4164
+ if (payload.clientStateJson == null && resultRef.current?.clientStateJson != null) {
4165
+ setRawStatus(payload.status);
4166
+ return;
4167
+ }
4168
+ setResult(toSubmitResult(payload));
4169
+ setRawStatus(payload.status);
4170
+ } catch {
4171
+ }
4172
+ }, []);
4155
4173
  const submit = useCallback8(async (answerJson) => {
4156
4174
  const conv = convRef.current;
4157
4175
  if (!conv || inFlightRef.current) return;
@@ -4161,7 +4179,14 @@ function useGamePlay(conversation, { gameId, gameDay, fixtureId, refresh }) {
4161
4179
  const opts = optsRef.current;
4162
4180
  const playResult = await conv.postPlay(opts.gameId, answerJson, opts.gameDay, opts.fixtureId);
4163
4181
  if (playResult !== null) {
4164
- setResult(playResult);
4182
+ const hasFreshState = playResult.clientStateJson != null;
4183
+ const isTerminal2 = playResult.alreadyPlayed === true;
4184
+ const holdsState = resultRef.current?.clientStateJson != null;
4185
+ if (!hasFreshState && !isTerminal2 && holdsState) {
4186
+ await refetch();
4187
+ } else {
4188
+ setResult(playResult);
4189
+ }
4165
4190
  if (playResult.pointsDelta != null) {
4166
4191
  opts.refresh?.();
4167
4192
  }
@@ -4171,22 +4196,10 @@ function useGamePlay(conversation, { gameId, gameDay, fixtureId, refresh }) {
4171
4196
  inFlightRef.current = false;
4172
4197
  setSubmitting(false);
4173
4198
  }
4174
- }, []);
4199
+ }, [refetch]);
4175
4200
  const hydrate = useCallback8(() => {
4176
- const conv = convRef.current;
4177
- if (!conv) return;
4178
- const opts = optsRef.current;
4179
- void (async () => {
4180
- try {
4181
- const payload = await conv.getGameResult(opts.gameId, opts.fixtureId, opts.gameDay);
4182
- if (payload !== null) {
4183
- setResult(toSubmitResult(payload));
4184
- setRawStatus(payload.status);
4185
- }
4186
- } catch {
4187
- }
4188
- })();
4189
- }, []);
4201
+ void refetch();
4202
+ }, [refetch]);
4190
4203
  return { result, submitting, submit, hydrate, rawStatus };
4191
4204
  }
4192
4205
 
@@ -4288,7 +4301,7 @@ var ATTR_LABELS = {
4288
4301
  position: "Pos",
4289
4302
  nationality: "Nat",
4290
4303
  age: "Age",
4291
- shirtNumber: "Kit",
4304
+ shirtNumber: "Shirt",
4292
4305
  apps: "Apps"
4293
4306
  };
4294
4307
  var ATTR_KEYS = [
@@ -4349,13 +4362,7 @@ function MysteryTigerGame({
4349
4362
  " left"
4350
4363
  ] })
4351
4364
  ] }),
4352
- guessResults.length === 0 && !isOver && /* @__PURE__ */ jsxs49("div", { className: "ss-w-gt-legend", children: [
4353
- /* @__PURE__ */ jsx55("div", { className: "ss-w-gt-legend-lead", children: "Guess any squad player \u2014 each guess reveals how close you are:" }),
4354
- /* @__PURE__ */ jsx55("div", { className: "ss-w-gtrow", children: ATTR_KEYS.map((key) => /* @__PURE__ */ jsxs49("div", { className: "ss-w-gtile ss-w-gtile--legend", children: [
4355
- /* @__PURE__ */ jsx55("span", { className: "ss-w-gtile-lab", children: ATTR_LABELS[key] }),
4356
- /* @__PURE__ */ jsx55("span", { className: "ss-w-gtile-v", "aria-hidden": "true", children: "\xB7" })
4357
- ] }, key)) })
4358
- ] }),
4365
+ guessResults.length === 0 && !isOver && /* @__PURE__ */ jsx55("div", { className: "ss-w-gt-lead", children: "Guess any squad player \u2014 each guess reveals how close you are on position, nationality, age, shirt and apps." }),
4359
4366
  guessResults.length > 0 && /* @__PURE__ */ jsx55("div", { className: "ss-w-gtrows", children: guessResults.map((gr, i) => {
4360
4367
  const player = config.squadPlayers.find((p) => p.id === gr.playerId);
4361
4368
  return /* @__PURE__ */ jsxs49("div", { className: "ss-w-gtguess", children: [
@@ -4689,6 +4696,15 @@ function parseClientState4(json) {
4689
4696
  function findCellResult(cells, row, col) {
4690
4697
  return cells.find((c) => c.row === row && c.col === col);
4691
4698
  }
4699
+ function shortName(name) {
4700
+ if (!name) return "";
4701
+ const parts = name.trim().split(/\s+/).filter(Boolean);
4702
+ if (parts.length === 0) return "";
4703
+ const first = parts[0];
4704
+ if (parts.length === 1) return first;
4705
+ const last = parts[parts.length - 1];
4706
+ return `${first.charAt(0)}. ${last}`;
4707
+ }
4692
4708
  function SearchSheet({
4693
4709
  row,
4694
4710
  col,
@@ -4834,8 +4850,11 @@ function BeatTheGridGame({
4834
4850
  disabled: isLocked2 || submitting,
4835
4851
  onClick: () => handleCellClick(rowIdx, colIdx),
4836
4852
  children: filled ? /* @__PURE__ */ jsxs52(Fragment13, { children: [
4837
- /* @__PURE__ */ jsx58("span", { className: "ss-w-btg-cell-score", children: filled.rarityScore }),
4838
- filled.isCorrect && /* @__PURE__ */ jsx58("span", { className: "ss-w-btg-cell-check", "aria-hidden": "true", children: "\u2713" })
4853
+ /* @__PURE__ */ jsx58("span", { className: "ss-w-btg-cell-nm", children: shortName(playerPool.find((p) => p.id === filled.playerId)?.name) }),
4854
+ /* @__PURE__ */ jsxs52("span", { className: "ss-w-btg-cell-score", children: [
4855
+ filled.rarityScore,
4856
+ filled.isCorrect && /* @__PURE__ */ jsx58("span", { className: "ss-w-btg-cell-check", "aria-hidden": "true", children: " \u2713" })
4857
+ ] })
4839
4858
  ] }) : /* @__PURE__ */ jsx58("span", { className: "ss-w-btg-cell-empty", "aria-hidden": "true", children: "+" })
4840
4859
  },
4841
4860
  `cell-${rowIdx}-${colIdx}`
@@ -6944,10 +6963,7 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
6944
6963
  /* Guess rows \u2014 one labelled block per guess */
6945
6964
  .ss-w-gtrows { display: flex; flex-direction: column; gap: 8px; }
6946
6965
  /* First-load legend (empty state) */
6947
- .ss-w-gt-legend { display: flex; flex-direction: column; gap: 8px; }
6948
- .ss-w-gt-legend-lead { font-size: 11.5px; color: var(--ss-w-faint); line-height: 1.35; }
6949
- .ss-w-gtile--legend { background: var(--ss-w-bubble); border: 1px dashed var(--ss-w-line); color: var(--ss-w-faint); }
6950
- .ss-w-gtile--legend .ss-w-gtile-lab { opacity: .9; }
6966
+ .ss-w-gt-lead { font-size: 11.5px; color: var(--ss-w-faint); line-height: 1.4; }
6951
6967
  .ss-w-gtguess { display: flex; flex-direction: column; gap: 4px; }
6952
6968
  .ss-w-gtguess-nm { font-size: 11px; font-weight: 600; color: var(--ss-w-faint); }
6953
6969
  .ss-w-gtrow { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
@@ -7066,8 +7082,10 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
7066
7082
  .ss-w-btg-cell--correct { background: color-mix(in srgb, var(--ss-w-correct) 14%, var(--ss-w-panel)); border-color: color-mix(in srgb, var(--ss-w-correct) 35%, var(--ss-w-line)); }
7067
7083
  .ss-w-btg-cell--wrong { background: color-mix(in srgb, var(--ss-w-wrong) 10%, var(--ss-w-panel)); }
7068
7084
  .ss-w-btg-cell--active { border-color: var(--ss-w-accent); }
7069
- .ss-w-btg-cell-score { font-size: 14px; font-weight: 800; color: var(--ss-w-ink); font-variant-numeric: tabular-nums; }
7070
- .ss-w-btg-cell-check { font-size: 12px; color: var(--ss-w-correct); line-height: 1; }
7085
+ .ss-w-btg-cell-nm { font-size: 8.5px; font-weight: 600; line-height: 1.05; color: var(--ss-w-ink); text-align: center; max-width: 100%; padding: 0 2px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
7086
+ .ss-w-btg-cell-score { font-size: 12px; font-weight: 800; color: var(--ss-w-accent); font-variant-numeric: tabular-nums; }
7087
+ .ss-w-btg-cell--correct .ss-w-btg-cell-score { color: var(--ss-w-correct); }
7088
+ .ss-w-btg-cell-check { color: var(--ss-w-correct); line-height: 1; }
7071
7089
  .ss-w-btg-cell-empty { font-size: 16px; color: var(--ss-w-faint); }
7072
7090
  /* Scoped search sheet: slides up over the grid */
7073
7091
  .ss-w-btg-sheet { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--ss-w-panel); border: 1.5px solid var(--ss-w-line); border-radius: 14px; box-shadow: 0 4px 20px rgba(0,0,0,.1); }
@@ -7089,12 +7107,16 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
7089
7107
  /* Pitch: a flag per slot laid out in formation rows on a green field. A real min-height plus
7090
7108
  space-between distributes the formation lines top\u2192bottom like a pitch (GK at the back, forwards
7091
7109
  forward); yard-line stripes reinforce the read. Without a height the lines collapse together. */
7092
- .ss-w-gxi-pitch { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; min-height: 300px; padding: 18px 10px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--ss-w-correct) 22%, var(--ss-w-line));
7110
+ /* A football pitch is grass-green regardless of the operator accent, so the field uses fixed
7111
+ green values (not --ss-w-correct, which is a muted per-operator token that vanished on dark
7112
+ themes) plus visible horizontal yard-lines and a brighter halfway line. */
7113
+ .ss-w-gxi-pitch { position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 8px; min-height: 300px; padding: 18px 10px; border-radius: 14px; border: 1px solid rgba(46, 160, 86, .38);
7093
7114
  background:
7094
- linear-gradient(180deg, color-mix(in srgb, var(--ss-w-correct) 12%, var(--ss-w-panel)), color-mix(in srgb, var(--ss-w-correct) 4%, var(--ss-w-panel))),
7095
- repeating-linear-gradient(180deg, transparent 0 40px, color-mix(in srgb, var(--ss-w-ink) 4%, transparent) 40px 80px); }
7096
- .ss-w-gxi-prow { display: flex; justify-content: center; align-items: center; gap: 14px; }
7097
- .ss-w-gxi-flag { width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 20px; line-height: 1; background: var(--ss-w-panel); border: 1px solid var(--ss-w-line); box-shadow: 0 1px 3px rgba(0,0,0,.14); overflow: hidden; }
7115
+ linear-gradient(180deg, rgba(46, 160, 86, .015) 0, rgba(46, 160, 86, .015) 49.5%, rgba(255,255,255,.14) 49.5%, rgba(255,255,255,.14) 50.5%, rgba(46, 160, 86, .015) 50.5%),
7116
+ repeating-linear-gradient(180deg, transparent 0 31px, rgba(255,255,255,.045) 31px 32px),
7117
+ linear-gradient(180deg, rgba(46, 160, 86, .28), rgba(38, 132, 71, .16)); }
7118
+ .ss-w-gxi-prow { display: flex; justify-content: center; align-items: center; gap: 12px; }
7119
+ .ss-w-gxi-flag { width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 17px; line-height: 1; background: rgba(9, 12, 10, .55); border: 1px solid rgba(255,255,255,.16); box-shadow: 0 1px 3px rgba(0,0,0,.3); overflow: hidden; }
7098
7120
  /* Wrong-guess trail */
7099
7121
  .ss-w-gxi-wrong { display: flex; flex-wrap: wrap; gap: 6px; }
7100
7122
  .ss-w-gxi-wrong-pill { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: color-mix(in srgb, var(--ss-w-wrong) 10%, var(--ss-w-panel)); border: 1px solid var(--ss-w-line); color: var(--ss-w-faint); text-decoration: line-through; }