@@ -162,29 +162,49 @@ export class SearchView {
162
162
cachePackagesElement . appendChild ( h1Element ) ;
163
163
164
164
for ( const pkg of window . scannedPackageCache ) {
165
- const { name, version, local } = parseNpmSpec ( pkg ) ;
166
- const pkgElement = document . createElement ( "div" ) ;
167
- pkgElement . classList . add ( "package-result" ) ;
168
- const pkgSpanElement = document . createElement ( "span" ) ;
169
- pkgSpanElement . innerHTML = `${ name } @${ version } ${ local ? " <b>local</b>" : "" } ` ;
170
- pkgSpanElement . addEventListener ( "click" , ( ) => {
171
- window . socket . send ( JSON . stringify ( { action : "SEARCH" , pkg } ) ) ;
172
- } , { once : true } ) ;
173
- const removeButton = createDOMElement ( "button" , {
174
- classList : [ "remove" ] ,
175
- text : "x"
176
- } ) ;
177
- removeButton . addEventListener ( "click" , ( event ) => {
178
- event . stopPropagation ( ) ;
179
- window . socket . send ( JSON . stringify ( { action : "REMOVE" , pkg } ) ) ;
180
- } , { once : true } ) ;
181
- pkgElement . append ( pkgSpanElement , removeButton ) ;
182
- cachePackagesElement . appendChild ( pkgElement ) ;
165
+ cachePackagesElement . appendChild ( this . #cachePackageElement( pkg ) ) ;
183
166
}
184
167
}
185
168
else {
186
169
cachePackagesElement . classList . add ( "hidden" ) ;
187
170
}
171
+
172
+ const recentPackagesElement = this . searchContainer . querySelector ( ".recent-packages" ) ;
173
+ if ( window . recentPackageCache . length > 0 ) {
174
+ recentPackagesElement . classList . remove ( "hidden" ) ;
175
+ const h1Element = document . createElement ( "h1" ) ;
176
+ h1Element . textContent = window . i18n [ lang ] . search . recentPackages ;
177
+ recentPackagesElement . appendChild ( h1Element ) ;
178
+
179
+ for ( const pkg of window . recentPackageCache ) {
180
+ recentPackagesElement . appendChild ( this . #cachePackageElement( pkg ) ) ;
181
+ }
182
+ }
183
+ else {
184
+ recentPackagesElement . classList . add ( "hidden" ) ;
185
+ }
186
+ }
187
+
188
+ #cachePackageElement( pkg ) {
189
+ const { name, version, local } = parseNpmSpec ( pkg ) ;
190
+ const pkgElement = document . createElement ( "div" ) ;
191
+ pkgElement . classList . add ( "package-result" ) ;
192
+ const pkgSpanElement = document . createElement ( "span" ) ;
193
+ pkgSpanElement . innerHTML = `${ name } @${ version } ${ local ? " <b>local</b>" : "" } ` ;
194
+ pkgSpanElement . addEventListener ( "click" , ( ) => {
195
+ window . socket . send ( JSON . stringify ( { action : "SEARCH" , pkg } ) ) ;
196
+ } , { once : true } ) ;
197
+ const removeButton = createDOMElement ( "button" , {
198
+ classList : [ "remove" ] ,
199
+ text : "x"
200
+ } ) ;
201
+ removeButton . addEventListener ( "click" , ( event ) => {
202
+ event . stopPropagation ( ) ;
203
+ window . socket . send ( JSON . stringify ( { action : "REMOVE" , pkg } ) ) ;
204
+ } , { once : true } ) ;
205
+ pkgElement . append ( pkgSpanElement , removeButton ) ;
206
+
207
+ return pkgElement ;
188
208
}
189
209
190
210
async fetchPackage ( packageName , version ) {
@@ -222,6 +242,9 @@ export class SearchView {
222
242
const cachePackagesElement = document . createElement ( "div" ) ;
223
243
cachePackagesElement . classList . add ( "cache-packages" , "hidden" ) ;
224
244
searchViewContainer . appendChild ( cachePackagesElement ) ;
245
+ const recentPackagesElement = document . createElement ( "div" ) ;
246
+ recentPackagesElement . classList . add ( "recent-packages" , "hidden" ) ;
247
+ searchViewContainer . appendChild ( recentPackagesElement ) ;
225
248
226
249
this . initialize ( ) ;
227
250
}
0 commit comments