File tree 1 file changed +11
-12
lines changed
1 file changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -56,28 +56,27 @@ <h1 class="text-4xl font-bold tracking-tight text-gray-900">
56
56
57
57
searchInput . addEventListener ( "input" , ( e ) => {
58
58
const query = e . target . value . toLowerCase ( ) . trim ( ) ;
59
- const results = [ ] ;
59
+ let titleMatches = [ ] ;
60
+ let descriptionMatches = [ ] ;
60
61
61
62
if ( query ) {
62
63
allSoftwares . forEach ( category => {
63
64
category . services . forEach ( service => {
64
- if (
65
- service . title . toLowerCase ( ) . includes ( query ) ||
66
- service . description . toLowerCase ( ) . includes ( query )
67
- ) {
68
- const alreadyExists = results . find (
69
- ( result ) => result . id === service . id
70
- ) ;
65
+ const titleMatch = service . title . toLowerCase ( ) . includes ( query ) ;
66
+ const descriptionMatch = service . description . toLowerCase ( ) . includes ( query ) ;
71
67
72
- if ( ! alreadyExists ) {
73
- results . push ( service ) ;
74
- }
68
+ if ( titleMatch ) {
69
+ titleMatches . push ( service ) ;
70
+ } else if ( descriptionMatch ) {
71
+ descriptionMatches . push ( service ) ;
75
72
}
76
73
} ) ;
77
74
} ) ;
78
75
}
79
76
80
- renderResults ( results ) ;
77
+ const sortedResults = [ ...titleMatches , ...descriptionMatches ] . slice ( 0 , 10 ) ;
78
+
79
+ renderResults ( sortedResults ) ;
81
80
} ) ;
82
81
83
82
const renderResults = ( results ) => {
You can’t perform that action at this time.
0 commit comments