Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: friends popup #337

Merged
merged 36 commits into from
Nov 18, 2023
Merged

Conversation

papo1011
Copy link
Contributor

@papo1011 papo1011 commented Oct 10, 2023

Friends popup #242

  • Relation Repository (getFollowing, follow, unfollow)
  • Test Relation Repository
  • Following screen
  • Following online socket topic (following_onlines, following_enters, following_leaves)
  • Following online screen

@papo1011 papo1011 changed the title feature friends popup #242 feature friends popup Oct 10, 2023
@papo1011 papo1011 mentioned this pull request Oct 10, 2023
@papo1011 papo1011 changed the title feature friends popup Feature: friends popup Oct 10, 2023
Copy link
Contributor

@veloce veloce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for your work, it already looks really good!

lib/src/model/relation/relation_ctrl.dart Outdated Show resolved Hide resolved
lib/src/model/relation/relation_ctrl.dart Outdated Show resolved Hide resolved
lib/src/model/relation/relation_ctrl.dart Outdated Show resolved Hide resolved
);
}

@riverpod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should cache this with @Riverpod(keepAlive: true)

Copy link
Contributor Author

@papo1011 papo1011 Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with @Riverpod(keepAlive: true) I have this behavior, steps to reproduce:

  • go to following screen
  • unfollow user
  • go back to friends screen
  • go to following screen

it serves old response, not updated with unfollow request at step 2
because cached with @Riverpod(keepAlive: true)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I see... the unfollow action should also invalidate the cache with ref.invalidate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I've added @Riverpod(keepAlive: true) and ref.invalidate :)

lib/src/view/relation/following_screen.dart Outdated Show resolved Hide resolved
lib/src/view/relation/following_screen.dart Outdated Show resolved Hide resolved
lib/src/view/relation/following_screen.dart Outdated Show resolved Hide resolved
lib/src/view/relation/relation_screen.dart Outdated Show resolved Hide resolved
lib/src/view/relation/relation_screen.dart Outdated Show resolved Hide resolved
lib/src/view/relation/relation_screen.dart Outdated Show resolved Hide resolved
@papo1011 papo1011 marked this pull request as ready for review October 29, 2023 15:36
@veloce
Copy link
Contributor

veloce commented Nov 6, 2023

@papo1011 I'm going to review the PR. Could you fix the conflict please?

Copy link
Contributor

@veloce veloce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for this caching mechanism that need to be removed it looks really good! thanks!

);
}

void _invalidateFollowingCache() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a bit complex logic here: we should probably not cache the data at all to avoid such code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the added benefit of caching is not worth the complexity imo

lib/src/view/relation/following_screen.dart Outdated Show resolved Hide resolved
});
} else {
ref
.read(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other comment, the whole caching logic seems too complex here. Normally just invalidating the followingProvider should be enough to trigger a screen refresh.

Perhaps you could take the account preferences notifier as an example:

class AccountPreferences extends _$AccountPreferences {

It works the same way: the initial data is fetched async from the server, and methods that update the state trigger an invalidateSelf to force fetching new data:

Copy link
Contributor Author

@papo1011 papo1011 Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I understand.
But if we add await Future.delayed(const Duration(seconds: 1)); before line 89 in the account_preferences, simulating a slow POST request, the delay will affect the toggle component, causing it to wait for 1 second before switching. The same behavior would occur when removing a user tile on the following screen.

Copy link
Contributor

@veloce veloce Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's not perfect, I agree, but in the vast majority of cases it will work smoothly.

UX can be improved I guess: set an opacity, or any other way to indicate something is loading. It will have the big advantage to be simple, compared to complex caching.

(I should do the same for the switches)

@veloce
Copy link
Contributor

veloce commented Nov 16, 2023

Too bad the diff includes already merged commits... dunno how to fix that.

@papo1011
Copy link
Contributor Author

Too bad the diff includes already merged commits... dunno how to fix that.

Here main...papo1011:mobile:feature/friends-popup-242 the three dots diff shows the difference between the two branches, displaying the correct commits.

@veloce veloce merged commit 32cfd5b into lichess-org:main Nov 18, 2023
3 checks passed
@papo1011 papo1011 deleted the feature/friends-popup-242 branch November 19, 2023 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants