Parcourir la source

:tada: Allow mech search by name

DricomDragon il y a 7 mois
Parent
commit
2693309eac
2 fichiers modifiés avec 15 ajouts et 5 suppressions
  1. 4 0
      dev-front/src/App.css
  2. 11 5
      dev-front/src/mech/MechPicker.tsx

+ 4 - 0
dev-front/src/App.css

@@ -24,6 +24,10 @@ header {
     width: 25%;
 }
 
+.mech-picker input {
+    display: block;
+}
+
 .custom-squad {
     /* Take the remaining width */
     flex-grow: 1;

+ 11 - 5
dev-front/src/mech/MechPicker.tsx

@@ -1,14 +1,20 @@
-import React from 'react';
+import React, { useState } from 'react';
 import mechData from './mech-data.json'
 
 function MechPicker() {
+    const [searchText, setSearchText] = useState("");
+
     return (
-        <aside>
+        <aside className='mech-picker'>
             <h2>Mech picker</h2>
+            <label htmlFor='search-mech-input'>Search mech</label>
+            <input id='search-mech-input' type='text' placeholder='Mech name' value={searchText} onChange={event => setSearchText(event.target.value)}/>
             <ul>
-                {mechData.map(mech => (
-                    <li key={mech.id}>{mech.name}</li>
-                ))}
+                {mechData
+                    .filter(mech => mech.name.toLowerCase().includes(searchText.toLocaleLowerCase()))
+                    .map(mech => (
+                        <li key={mech.id}>{mech.name}</li>
+                    ))}
             </ul>
         </aside>
     );