@@ -4,35 +4,11 @@ import { useLatest, useWindowSize } from "react-use";
44import { findSystemByEdo , getSystemLabel } from "@/lib/theory/tuning" ;
55import { memoWithPick } from "@/utils/memo" ;
66import ModalFrame from "@/components/UI/modals/ModalFrame" ;
7-
8- function normalizePack ( pack ) {
9- if ( ! pack || typeof pack !== "object" ) return null ;
10- const edo = Number ( pack ?. system ?. edo ) ;
11- const metaSystemId =
12- typeof pack ?. meta ?. systemId === "string" ? pack . meta . systemId : null ;
13- const rawName = typeof pack ?. name === "string" ? pack . name : "" ;
14- const displayName = rawName . trim ( ) . length ? rawName : "Untitled pack" ;
15- const strings = Array . isArray ( pack ?. tuning ?. strings )
16- ? pack . tuning . strings
17- : [ ] ;
18- const stringsCount = strings . length ;
19- return {
20- raw : pack ,
21- rawName,
22- displayName,
23- edo : Number . isFinite ( edo ) ? edo : null ,
24- metaSystemId,
25- strings,
26- stringsCount,
27- } ;
28- }
29-
30- function formatStringsCount ( stringsCount ) {
31- if ( ! Number . isFinite ( stringsCount ) || stringsCount <= 0 ) {
32- return "Unknown string count" ;
33- }
34- return `${ stringsCount } string${ stringsCount === 1 ? "" : "s" } ` ;
35- }
7+ import {
8+ formatStringsCount ,
9+ normalizePack ,
10+ packMatchesQuery ,
11+ } from "@/components/UI/modals/tuningPackSearch" ;
3612
3713function TuningPackManagerModal ( {
3814 isOpen,
@@ -57,7 +33,6 @@ function TuningPackManagerModal({
5733 const groups = useMemo ( ( ) => {
5834 if ( ! Array . isArray ( tunings ) || tunings . length === 0 ) return [ ] ;
5935
60- const hasQuery = normalizedQuery . length > 0 ;
6136 const grouped = new Map ( ) ;
6237
6338 tunings . forEach ( ( entry ) => {
@@ -80,20 +55,12 @@ function TuningPackManagerModal({
8055
8156 const formattedStringsCount = formatStringsCount ( normalized . stringsCount ) ;
8257
83- const matchesQuery = ! hasQuery
84- ? true
85- : [
86- normalized . displayName ,
87- normalized . rawName ,
88- String ( normalized . stringsCount ?? "" ) ,
89- formattedStringsCount ,
90- systemLabel ,
91- ] . some (
92- ( value ) =>
93- typeof value === "string" &&
94- value . toLowerCase ( ) . includes ( normalizedQuery ) ,
95- ) ;
96-
58+ const matchesQuery = packMatchesQuery ( {
59+ normalizedPack : normalized ,
60+ systemLabel,
61+ normalizedQuery,
62+ formattedStringsCount,
63+ } ) ;
9764 if ( ! matchesQuery ) {
9865 return ;
9966 }
@@ -180,7 +147,7 @@ function TuningPackManagerModal({
180147 type = "search"
181148 value = { query }
182149 onChange = { ( event ) => setQuery ( event . target . value ) }
183- placeholder = "Search by name, system, or string count"
150+ placeholder = "Search by name, system, string count, or notes "
184151 aria-controls = "tuning-pack-manager-sections"
185152 autoComplete = "off"
186153 />
@@ -211,10 +178,6 @@ function TuningPackManagerModal({
211178 </ header >
212179 < ul className = "tv-modal__manager-list" >
213180 { group . packs . map ( ( pack , index ) => {
214- const preview = pack . strings
215- . map ( ( string ) => string ?. note || string ?. label || "•" )
216- . filter ( Boolean )
217- . join ( " · " ) ;
218181 return (
219182 < li
220183 key = { `${ pack . rawName || pack . displayName } __${ index } ` }
@@ -226,7 +189,9 @@ function TuningPackManagerModal({
226189 </ span >
227190 < span className = "tv-modal__manager-pack-preview" >
228191 { formatStringsCount ( pack . stringsCount ) }
229- { preview ? ` · ${ preview } ` : "" }
192+ { pack . stringPreview
193+ ? ` · ${ pack . stringPreview } `
194+ : "" }
230195 </ span >
231196 </ div >
232197 < div className = "tv-modal__manager-actions" >
0 commit comments