davanstrien HF staff commited on
Commit
93b03bf
·
1 Parent(s): b6c1ca0

Refactor dataset search and sorting functionality

Browse files
Files changed (1) hide show
  1. index.html +62 -8
index.html CHANGED
@@ -90,10 +90,23 @@
90
  <div
91
  class="card bg-white p-8 rounded-xl shadow-sm border border-gray-100"
92
  >
93
- <p class="text-gray-600 mb-4">
94
- Enter keywords to search through dataset descriptions. The search
95
- will automatically update as you type.
96
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  <div class="relative">
98
  <input
99
  type="text"
@@ -112,10 +125,23 @@
112
  <div
113
  class="card bg-white p-8 rounded-xl shadow-sm border border-gray-100"
114
  >
115
- <p class="text-gray-600 mb-4">
116
- Enter a dataset ID to find similar datasets. Popular datasets will
117
- appear as you type.
118
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  <div class="flex gap-3">
120
  <div class="relative w-full">
121
  <input
@@ -167,6 +193,9 @@
167
  const INITIAL_SEARCH = URL_PARAMS.get("q");
168
  const INITIAL_SIMILAR = URL_PARAMS.get("similar");
169
 
 
 
 
170
  // Initialize Lucide icons
171
  lucide.createIcons();
172
 
@@ -457,6 +486,11 @@
457
  const container = document.getElementById("resultsContainer");
458
  console.log("Displaying results:", results);
459
  if (results && results.length > 0) {
 
 
 
 
 
460
  container.innerHTML = `
461
  <div class="flex justify-between items-center mb-4">
462
  <h2 class="text-lg font-semibold">Results</h2>
@@ -689,6 +723,26 @@
689
  await findSimilarDatasets();
690
  }
691
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
692
  </script>
693
  </body>
694
  </html>
 
90
  <div
91
  class="card bg-white p-8 rounded-xl shadow-sm border border-gray-100"
92
  >
93
+ <div
94
+ class="flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between mb-4"
95
+ >
96
+ <p class="text-gray-600">
97
+ Enter keywords to search through dataset descriptions. The
98
+ search will automatically update as you type.
99
+ </p>
100
+ <select
101
+ id="searchSortSelect"
102
+ class="text-sm border rounded-lg px-3 py-2 bg-white text-gray-700 focus:ring-2 focus:ring-blue-100 focus:border-blue-300 transition-all outline-none"
103
+ onchange="handleSortChange('search')"
104
+ >
105
+ <option value="similarity">Sort by relevance</option>
106
+ <option value="likes">Sort by likes</option>
107
+ <option value="downloads">Sort by downloads</option>
108
+ </select>
109
+ </div>
110
  <div class="relative">
111
  <input
112
  type="text"
 
125
  <div
126
  class="card bg-white p-8 rounded-xl shadow-sm border border-gray-100"
127
  >
128
+ <div
129
+ class="flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between mb-4"
130
+ >
131
+ <p class="text-gray-600">
132
+ Enter a dataset ID to find similar datasets. Popular datasets
133
+ will appear as you type.
134
+ </p>
135
+ <select
136
+ id="similarSortSelect"
137
+ class="text-sm border rounded-lg px-3 py-2 bg-white text-gray-700 focus:ring-2 focus:ring-blue-100 focus:border-blue-300 transition-all outline-none"
138
+ onchange="handleSortChange('similar')"
139
+ >
140
+ <option value="similarity">Sort by relevance</option>
141
+ <option value="likes">Sort by likes</option>
142
+ <option value="downloads">Sort by downloads</option>
143
+ </select>
144
+ </div>
145
  <div class="flex gap-3">
146
  <div class="relative w-full">
147
  <input
 
193
  const INITIAL_SEARCH = URL_PARAMS.get("q");
194
  const INITIAL_SIMILAR = URL_PARAMS.get("similar");
195
 
196
+ // Add this variable with other configurations
197
+ let currentSort = "similarity";
198
+
199
  // Initialize Lucide icons
200
  lucide.createIcons();
201
 
 
486
  const container = document.getElementById("resultsContainer");
487
  console.log("Displaying results:", results);
488
  if (results && results.length > 0) {
489
+ // Sort results if not using similarity
490
+ if (currentSort !== "similarity") {
491
+ results.sort((a, b) => b[currentSort] - a[currentSort]);
492
+ }
493
+
494
  container.innerHTML = `
495
  <div class="flex justify-between items-center mb-4">
496
  <h2 class="text-lg font-semibold">Results</h2>
 
723
  await findSimilarDatasets();
724
  }
725
  });
726
+
727
+ // Modify the handleSortChange function
728
+ function handleSortChange(tab) {
729
+ const sortSelect = document.getElementById(`${tab}SortSelect`);
730
+ currentSort = sortSelect.value;
731
+
732
+ // Re-run the current search with new sort
733
+ const activeTab = document.querySelector(".tab-trigger.active").id;
734
+ if (activeTab === "searchTab") {
735
+ const searchQuery = document.getElementById("searchInput").value;
736
+ if (searchQuery.length >= MIN_SEARCH_LENGTH) {
737
+ searchDatasets(searchQuery, 1);
738
+ }
739
+ } else {
740
+ const datasetId = document.getElementById("datasetInput").value;
741
+ if (datasetId) {
742
+ findSimilarDatasets(1);
743
+ }
744
+ }
745
+ }
746
  </script>
747
  </body>
748
  </html>