@@ -50,6 +50,7 @@ export default function PluginsInclude(updates) {
50
50
let isLoading = false ;
51
51
let hasMore = true ;
52
52
let isSearching = false ;
53
+ let currentFilter = null ;
53
54
const LIMIT = 50 ;
54
55
55
56
Contextmenu ( {
@@ -81,26 +82,32 @@ export default function PluginsInclude(updates) {
81
82
downloads : strings . most_downloaded ,
82
83
} ;
83
84
const filterName = filterNames [ item ] ;
85
+ currentFilter = item ;
86
+ currentPage = 1 ;
87
+ hasMore = true ;
88
+ isLoading = false ;
89
+ plugins . all = [ ] ; // Reset the all plugins array
84
90
render ( "all" ) ;
85
- getFilteredPlugins ( item ) . then ( ( plugins ) => {
86
- $list . all . replaceChildren ( ) ;
87
- $list . all . append (
88
- < div className = "filter-message" >
89
- Filter for < strong > { filterName } </ strong >
90
- < span
91
- className = "icon clearclose"
92
- data-action = "clear-filter"
93
- onclick = { ( ) => {
94
- $list . all . replaceChildren ( ) ;
95
- getAllPlugins ( ) ;
96
- } }
97
- > </ span >
98
- </ div > ,
99
- ) ;
100
- plugins . forEach ( ( plugin ) => {
101
- $list . all . append ( < Item { ...plugin } /> ) ;
102
- } ) ;
103
- } ) ;
91
+ $list . all . replaceChildren ( ) ;
92
+ $list . all . append (
93
+ < div className = "filter-message" >
94
+ Filtered by < strong > { filterName } </ strong >
95
+ < span
96
+ className = "icon clearclose"
97
+ data-action = "clear-filter"
98
+ onclick = { ( ) => {
99
+ currentFilter = null ;
100
+ currentPage = 1 ;
101
+ hasMore = true ;
102
+ isLoading = false ;
103
+ plugins . all = [ ] ; // Reset the all plugins array
104
+ $list . all . replaceChildren ( ) ;
105
+ getAllPlugins ( ) ;
106
+ } }
107
+ > </ span >
108
+ </ div > ,
109
+ ) ;
110
+ getFilteredPlugins ( item ) ;
104
111
} ,
105
112
} ) ;
106
113
@@ -153,8 +160,12 @@ export default function PluginsInclude(updates) {
153
160
if ( isLoading || ! hasMore || isSearching ) return ;
154
161
155
162
const { scrollTop, scrollHeight, clientHeight } = e . target ;
156
- if ( scrollTop + clientHeight >= scrollHeight - 100 ) {
157
- await getAllPlugins ( ) ;
163
+ if ( scrollTop + clientHeight >= scrollHeight - 50 ) {
164
+ if ( currentFilter ) {
165
+ await getFilteredPlugins ( currentFilter ) ;
166
+ } else {
167
+ await getAllPlugins ( ) ;
168
+ }
158
169
}
159
170
} )
160
171
@@ -237,6 +248,7 @@ export default function PluginsInclude(updates) {
237
248
currentPage = 1 ;
238
249
hasMore = true ;
239
250
isLoading = false ;
251
+ plugins . all = [ ] ; // Reset the all plugins array
240
252
$list . all . replaceChildren ( ) ;
241
253
getAllPlugins ( ) ;
242
254
}
@@ -274,21 +286,56 @@ export default function PluginsInclude(updates) {
274
286
}
275
287
276
288
async function getFilteredPlugins ( filterName ) {
289
+ if ( isLoading || ! hasMore ) return ;
290
+
277
291
try {
292
+ isLoading = true ;
293
+ $list . all . setAttribute ( "empty-msg" , strings [ "loading..." ] ) ;
294
+
278
295
let response ;
279
296
if ( filterName === "top_rated" ) {
280
- response = await fetch ( `${ constants . API_BASE } /plugins?explore=random` ) ;
297
+ response = await fetch ( `${ constants . API_BASE } /plugins?explore=random&page= ${ currentPage } &limit= ${ LIMIT } ` ) ;
281
298
} else {
282
299
response = await fetch (
283
- `${ constants . API_BASE } /plugin?orderBy=${ filterName } ` ,
300
+ `${ constants . API_BASE } /plugin?orderBy=${ filterName } &page= ${ currentPage } &limit= ${ LIMIT } ` ,
284
301
) ;
285
302
}
286
- return await response . json ( ) ;
303
+ const fetchedPlugins = await response . json ( ) ;
304
+
305
+ if ( fetchedPlugins . length < LIMIT ) {
306
+ hasMore = false ;
307
+ }
308
+
309
+ const installed = await fsOperation ( PLUGIN_DIR ) . lsDir ( ) ;
310
+ const disabledMap = settings . value . pluginsDisabled || { } ;
311
+
312
+ installed . forEach ( ( { url } ) => {
313
+ const plugin = fetchedPlugins . find ( ( { id } ) => id === Url . basename ( url ) ) ;
314
+ if ( plugin ) {
315
+ plugin . installed = true ;
316
+ plugin . enabled = disabledMap [ plugin . id ] !== true ;
317
+ plugin . onToggleEnabled = onToggleEnabled ;
318
+ plugin . localPlugin = getLocalRes ( plugin . id , "plugin.json" ) ;
319
+ }
320
+ } ) ;
321
+
322
+ // Add plugins to the all plugins array
323
+ plugins . all . push ( ...fetchedPlugins ) ;
324
+
325
+ const fragment = document . createDocumentFragment ( ) ;
326
+ fetchedPlugins . forEach ( ( plugin ) => {
327
+ fragment . append ( < Item { ...plugin } updates = { updates } /> ) ;
328
+ } ) ;
329
+ $list . all . append ( fragment ) ;
330
+
331
+ currentPage ++ ;
332
+ $list . all . setAttribute ( "empty-msg" , strings [ "no plugins found" ] ) ;
287
333
} catch ( error ) {
288
334
$list . all . setAttribute ( "empty-msg" , strings [ "error" ] ) ;
289
335
window . log ( "error" , "Failed to filter plugins:" ) ;
290
336
window . log ( "error" , error ) ;
291
- return [ ] ;
337
+ } finally {
338
+ isLoading = false ;
292
339
}
293
340
}
294
341
@@ -308,17 +355,26 @@ export default function PluginsInclude(updates) {
308
355
}
309
356
310
357
const installed = await fsOperation ( PLUGIN_DIR ) . lsDir ( ) ;
358
+ const disabledMap = settings . value . pluginsDisabled || { } ;
359
+
311
360
installed . forEach ( ( { url } ) => {
312
361
const plugin = newPlugins . find ( ( { id } ) => id === Url . basename ( url ) ) ;
313
362
if ( plugin ) {
314
363
plugin . installed = true ;
364
+ plugin . enabled = disabledMap [ plugin . id ] !== true ;
365
+ plugin . onToggleEnabled = onToggleEnabled ;
315
366
plugin . localPlugin = getLocalRes ( plugin . id , "plugin.json" ) ;
316
367
}
317
368
} ) ;
318
369
370
+ // Add plugins to the all plugins array
371
+ plugins . all . push ( ...newPlugins ) ;
372
+
373
+ const fragment = document . createDocumentFragment ( ) ;
319
374
newPlugins . forEach ( ( plugin ) => {
320
- $list . all . append ( < Item { ...plugin } /> ) ;
375
+ fragment . append ( < Item { ...plugin } updates = { updates } /> ) ;
321
376
} ) ;
377
+ $list . all . append ( fragment ) ;
322
378
323
379
currentPage ++ ;
324
380
$list . all . setAttribute ( "empty-msg" , strings [ "no plugins found" ] ) ;
@@ -347,7 +403,7 @@ export default function PluginsInclude(updates) {
347
403
plugin . onToggleEnabled = onToggleEnabled ;
348
404
plugins . installed . push ( plugin ) ;
349
405
if ( $list . installed . get ( `[data-id=\"${ id } \"]` ) ) return ;
350
- $list . installed . append ( < Item { ...plugin } /> ) ;
406
+ $list . installed . append ( < Item { ...plugin } updates = { updates } /> ) ;
351
407
} ) ,
352
408
) ;
353
409
$list . installed . setAttribute ( "empty-msg" , strings [ "no plugins found" ] ) ;
@@ -356,14 +412,22 @@ export default function PluginsInclude(updates) {
356
412
async function getOwned ( ) {
357
413
$list . owned . setAttribute ( "empty-msg" , strings [ "loading..." ] ) ;
358
414
const purchases = await helpers . promisify ( iap . getPurchases ) ;
415
+ const disabledMap = settings . value . pluginsDisabled || { } ;
416
+
359
417
purchases . forEach ( async ( { productIds } ) => {
360
418
const [ sku ] = productIds ;
361
419
const url = Url . join ( constants . API_BASE , "plugin/owned" , sku ) ;
362
420
const plugin = await fsOperation ( url ) . readFile ( "json" ) ;
363
421
const isInstalled = plugins . installed . find ( ( { id } ) => id === plugin . id ) ;
364
422
plugin . installed = ! ! isInstalled ;
423
+
424
+ if ( plugin . installed ) {
425
+ plugin . enabled = disabledMap [ plugin . id ] !== true ;
426
+ plugin . onToggleEnabled = onToggleEnabled ;
427
+ }
428
+
365
429
plugins . owned . push ( plugin ) ;
366
- $list . owned . append ( < Item { ...plugin } /> ) ;
430
+ $list . owned . append ( < Item { ...plugin } updates = { updates } /> ) ;
367
431
} ) ;
368
432
$list . owned . setAttribute ( "empty-msg" , strings [ "no plugins found" ] ) ;
369
433
}
@@ -392,7 +456,7 @@ export default function PluginsInclude(updates) {
392
456
393
457
const existingItem = $list . installed . get ( `[data-id="${ plugin . id } "]` ) ;
394
458
if ( ! existingItem ) {
395
- $list . installed . append ( < Item { ...plugin } /> ) ;
459
+ $list . installed . append ( < Item { ...plugin } updates = { updates } /> ) ;
396
460
}
397
461
398
462
}
@@ -456,17 +520,39 @@ export default function PluginsInclude(updates) {
456
520
window . toast ( strings [ "plugin_enabled" ] || "Plugin enabled" ) ;
457
521
}
458
522
459
- // Update the plugin object's state
460
- const plugin = plugins . installed . find ( p => p . id === id ) ;
461
- if ( plugin ) {
462
- plugin . enabled = ! enabled ;
463
-
464
- // Re-render the specific item
465
- const $existingItem = $list . installed . get ( `[data-id="${ id } "]` ) ;
466
- if ( $existingItem ) {
467
- const $newItem = < Item { ...plugin } /> ;
468
- $existingItem . replaceWith ( $newItem ) ;
469
- }
523
+ // Update the plugin object's state in all plugin arrays
524
+ const installedPlugin = plugins . installed . find ( p => p . id === id ) ;
525
+ if ( installedPlugin ) {
526
+ installedPlugin . enabled = ! enabled ;
527
+ }
528
+
529
+ const allPlugin = plugins . all . find ( p => p . id === id ) ;
530
+ if ( allPlugin ) {
531
+ allPlugin . enabled = ! enabled ;
532
+ }
533
+
534
+ const ownedPlugin = plugins . owned . find ( p => p . id === id ) ;
535
+ if ( ownedPlugin ) {
536
+ ownedPlugin . enabled = ! enabled ;
537
+ }
538
+
539
+ // Re-render the specific item in all tabs
540
+ const $installedItem = $list . installed . get ( `[data-id="${ id } "]` ) ;
541
+ if ( $installedItem && installedPlugin ) {
542
+ const $newItem = < Item { ...installedPlugin } updates = { updates } /> ;
543
+ $installedItem . replaceWith ( $newItem ) ;
544
+ }
545
+
546
+ const $allItem = $list . all . get ( `[data-id="${ id } "]` ) ;
547
+ if ( $allItem && allPlugin ) {
548
+ const $newItem = < Item { ...allPlugin } updates = { updates } /> ;
549
+ $allItem . replaceWith ( $newItem ) ;
550
+ }
551
+
552
+ const $ownedItem = $list . owned . get ( `[data-id="${ id } "]` ) ;
553
+ if ( $ownedItem && ownedPlugin ) {
554
+ const $newItem = < Item { ...ownedPlugin } updates = { updates } /> ;
555
+ $ownedItem . replaceWith ( $newItem ) ;
470
556
}
471
557
}
472
558
}
0 commit comments