@@ -994,26 +994,8 @@ export default {
994
994
} else {
995
995
// First update the counts
996
996
await this .updateCounts ();
997
-
998
- // Reset the results array to force a re-render
999
- const oldResults = [... this .results ];
1000
- this .results = [];
1001
-
1002
- // Force an immediate submit to update the display
997
+ // Submit without clearing current results to avoid flicker on mobile
1003
998
this .submit ();
1004
-
1005
- // Use Vue's nextTick to ensure DOM updates after data changes
1006
- this .$nextTick (() => {
1007
- // If submit hasn't populated results yet, restore the old ones temporarily
1008
- if (this .results .length === 0 && oldResults .length > 0 ) {
1009
- this .results = [... oldResults];
1010
-
1011
- // Then force another update after a short delay
1012
- setTimeout (() => {
1013
- this .forceUpdate ();
1014
- }, 50 );
1015
- }
1016
- });
1017
999
}
1018
1000
},
1019
1001
deep: true ,
@@ -1269,16 +1251,15 @@ export default {
1269
1251
this .submitTimeout = null ;
1270
1252
}
1271
1253
this .submitTimeout = setTimeout (submit .bind (this ), 50 ); // Reduced timeout for faster response
1272
-
1254
+
1273
1255
function submit () {
1274
- // Force a complete reset of the results to trigger reactivity
1256
+ // Reset pagination values
1275
1257
this .page = 0 ;
1276
1258
this .loadedAll = false ;
1277
1259
this .total = 0 ; // Reset total as well
1278
- this .results = [];
1279
-
1280
- // Immediately force a fetch of new data
1281
- this .fetchPage ();
1260
+
1261
+ // Fetch new data and replace results when it arrives
1262
+ this .fetchPage (true );
1282
1263
1283
1264
// Restart infinite scroll monitoring
1284
1265
this .restartLoadMoreIfNeeded ();
@@ -1287,17 +1268,8 @@ export default {
1287
1268
this .filtersOpen = false ;
1288
1269
this .submitTimeout = null ;
1289
1270
1290
- // Force DOM update by directly manipulating the DOM after a short delay
1291
- setTimeout (() => {
1292
- if (typeof document !== ' undefined' ) {
1293
- // This is a browser-only technique to force a repaint
1294
- const plants = document .querySelectorAll (' .plant' );
1295
- if (plants .length === 0 ) {
1296
- // If no plants are visible yet, force a fetchPage again
1297
- this .fetchPage ();
1298
- }
1299
- }
1300
- }, 100 );
1271
+ // Allow any queued DOM updates to complete
1272
+ this .$nextTick (() => {});
1301
1273
}
1302
1274
},
1303
1275
async updateCounts () {
@@ -1340,12 +1312,14 @@ export default {
1340
1312
doUpdate ();
1341
1313
});
1342
1314
},
1343
- async fetchPage () {
1315
+ async fetchPage (replace = false ) {
1344
1316
this .loading = true ;
1345
1317
if (this .favorites && ! [... this .$store .state .favorites ].length ) {
1346
1318
// Avoid a query that would result in seeing all of the plants
1347
1319
// in the database as "favorites"
1348
- this .results = [];
1320
+ if (replace) {
1321
+ this .results = [];
1322
+ }
1349
1323
this .loadedAll = true ;
1350
1324
this .total = 0 ;
1351
1325
this .loading = false ;
@@ -1378,13 +1352,16 @@ export default {
1378
1352
if (! data .results .length || this .favorites || this .questions ) {
1379
1353
this .loadedAll = true ;
1380
1354
}
1381
- // Prevent duplicate plants by checking if they already exist in the results array
1382
- data .results .forEach ((datum ) => {
1383
- // Only add the plant if it's not already in the results array
1384
- if (! this .results .some (existing => existing ._id === datum ._id )) {
1385
- this .results .push (datum);
1386
- }
1387
- });
1355
+ if (replace) {
1356
+ this .results = data .results ;
1357
+ } else {
1358
+ // Prevent duplicate plants by checking if they already exist in the results array
1359
+ data .results .forEach ((datum ) => {
1360
+ if (! this .results .some ((existing ) => existing ._id === datum ._id )) {
1361
+ this .results .push (datum);
1362
+ }
1363
+ });
1364
+ }
1388
1365
this .total = data .total ;
1389
1366
this .loading = false ;
1390
1367
},
0 commit comments