From f5e02f6b78e8b04ef330666409dc50126a87cc40 Mon Sep 17 00:00:00 2001 From: Reynier Matthieu Date: Mon, 3 Feb 2025 14:29:26 +0100 Subject: [PATCH] improve filter but colorless doesn't work yet --- src/components/CardSearch.tsx | 54 +++++++++++------ src/components/ManaIcons.tsx | 107 ++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 17 deletions(-) create mode 100644 src/components/ManaIcons.tsx diff --git a/src/components/CardSearch.tsx b/src/components/CardSearch.tsx index 6f010c6..08a306c 100644 --- a/src/components/CardSearch.tsx +++ b/src/components/CardSearch.tsx @@ -12,7 +12,7 @@ import React, { useState } from 'react'; const [colors, setColors] = useState({ W: false, U: false, B: false, R: false, G: false, C: false }); const [colorMode, setColorMode] = useState('exactly'); const [commanderColors, setCommanderColors] = useState({ W: false, U: false, B: false, R: false, G: false, C: false }); - const [manaCost, setManaCost] = useState(''); + const [manaCost, setManaCost] = useState({ W: 0, U: 0, B: 0, R: 0, G: 0, C: 0 }); const [manaValue, setManaValue] = useState(''); const [manaValueComparison, setManaValueComparison] = useState('='); const [games, setGames] = useState({ paper: false, arena: false, mtgo: false }); @@ -62,7 +62,14 @@ import React, { useState } from 'react'; const activeColors = Object.keys(commanderColors).filter((key) => commanderColors[key as keyof typeof commanderColors]).join(''); query += `id:${activeColors} `; } - if (manaCost) query += `m:${manaCost} `; + + const manaCostString = Object.entries(manaCost) + .filter(([, count]) => count > 0) + .map(([color, count]) => `{${color}}`.repeat(count)) + .join(''); + + if (manaCostString) query += `m:${manaCostString} `; + if (manaValue) query += `mv${manaValueComparison}${manaValue} `; if (Object.values(games).some(Boolean)) { const activeGames = Object.keys(games).filter((key) => games[key as keyof typeof games]).join(','); @@ -161,15 +168,17 @@ import React, { useState } from 'react';

Card Colors

- {['W', 'U', 'B', 'R', 'G', 'C'].map((color) => ( + {Object.entries(colors).map(([color, active]) => ( ))}
@@ -185,15 +194,17 @@ import React, { useState } from 'react';

Commander Colors

- {['W', 'U', 'B', 'R', 'G', 'C'].map((color) => ( + {Object.entries(commanderColors).map(([color, active]) => ( ))}
@@ -201,13 +212,22 @@ import React, { useState } from 'react';
{/* Mana Cost */} - setManaCost(e.target.value)} - className="w-full px-4 py-2 bg-gray-800 border border-gray-700 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-white" - placeholder="Mana Cost (e.g., {W}{W})" - /> +
+ {Object.entries(manaCost).map(([color, count]) => ( +
+ + {color === 'W' ? '⚪' : color === 'U' ? '🔵' : color === 'B' ? '⚫' : color === 'R' ? '🔴' : color === 'G' ? '🟢' : '🟤'} + + setManaCost({ ...manaCost, [color]: parseInt(e.target.value) })} + className="w-16 px-2 py-1 bg-gray-800 border border-gray-700 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-white" + min="0" + /> +
+ ))} +
{/* Stats */}
diff --git a/src/components/ManaIcons.tsx b/src/components/ManaIcons.tsx new file mode 100644 index 0000000..58311e7 --- /dev/null +++ b/src/components/ManaIcons.tsx @@ -0,0 +1,107 @@ +import React from 'react'; + + export const ManaWhite = ({ size = 20, ...props }: { size?: number }) => ( + + + + ); + + export const ManaBlue = ({ size = 20, ...props }: { size?: number }) => ( + + + + + ); + + export const ManaBlack = ({ size = 20, ...props }: { size?: number }) => ( + + + + + ); + + export const ManaRed = ({ size = 20, ...props }: { size?: number }) => ( + + + + + ); + + export const ManaGreen = ({ size = 20, ...props }: { size?: number }) => ( + + + + + ); + + export const ManaColorless = ({ size = 20, ...props }: { size?: number }) => ( + + + + );