spaceshelter / orbitar

Experimental collective social/blogging platform with self-regulation.
MIT License
59 stars 23 forks source link

Reset to first page on change Feed Sorting #343

Closed maximt closed 3 months ago

maximt commented 1 year ago

Small fix

Aivean commented 1 year ago

Not sure that this is a right way to achieve this.

Currently when sorting is changed, the subscriptions request (or other similar request that corresponds to the selected feed) is triggered once.

After this change, the state change causes chain reaction and the same request is triggered FOUR times.

To test:

  1. go the second page of the current feed
  2. change sorting

Can instead simply remove the "?page=..." parameter from the feed selection buttons?

maximt commented 1 year ago

The problem is that any change of the page triggers useFeed, and changing of the page and sorting at the same time causes double call to useFeed.

Think we can encapsulate the separate fields feedType, sorting, page into object just like FeedFilterCriteria to be able to change many params at the same time.

Or have to ugly trick with one more flag just like:

setBeginUpdate(true);
setPage(page);
setSorting(sorting);
setBeginUpdate(false);

...
useFeed(....) {
 if (beginUpdate)
  return;
 ...
}
Aivean commented 1 year ago

I'll try to think about a more elegant way to fix this.

It also could be worth the effort to resurrect #53 and replace useFeed with mobX state, which simplifies these invariants significantly.