-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
Bookmark games #1302
base: main
Are you sure you want to change the base?
Bookmark games #1302
Conversation
Signed-off-by: ZTL-UwU <[email protected]>
Signed-off-by: ZTL-UwU <[email protected]>
Signed-off-by: ZTL-UwU <[email protected]>
Signed-off-by: ZTL-UwU <[email protected]>
Signed-off-by: ZTL-UwU <[email protected]>
Signed-off-by: ZTL-UwU <[email protected]>
Signed-off-by: ZTL-UwU <[email protected]>
32d8755
to
40ef91a
Compare
Thanks for taking this over. In order to land this feature we also need the filter to display bookmarked games in the game list. This filter is not yet available server side, so you should create an issue on Lila about it. |
d7fb43e
to
fdac26b
Compare
fdac26b
to
50ccaf2
Compare
I went with creating a new provider that store the changes made by the user. I am not really happy with this solution because this provider needs the |
|
||
/// A provider to store the bookmark value of a game when it was changed by the user. | ||
@Riverpod(keepAlive: true) | ||
class GameBookmark extends _$GameBookmark { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This provider looks dubious, I think it is not necessary and this state can be store elsewhere (probably a transient widget state is enough).
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final bookmarkCurrentState = ref.watch(gameBookmarkProvider(id)) ?? bookmarked; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, prefer a StatefulWidget. This state should stay local.
@@ -111,6 +117,10 @@ class _ContextMenu extends ConsumerWidget { | |||
|
|||
final customColors = Theme.of(context).extension<CustomColors>(); | |||
|
|||
final isLoggedIn = ref.watch(isLoggedInProvider); | |||
|
|||
final bookmarkValue = ref.watch(gameBookmarkProvider(game.id)) ?? game.bookmarked!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again: make it a StatefulWidget and don't use a provider for this.
@@ -170,15 +175,55 @@ class _BodyState extends ConsumerState<_Body> { | |||
); | |||
} | |||
|
|||
return ExtendedGameListTile( | |||
final game = list[index].game; | |||
final bookmarkValue = ref.watch(gameBookmarkProvider(game.id)) ?? game.bookmarked!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StatefulWidget, not provider
Indeed this provider needs to be removed as I said in the comments. |
Well there is a reason why I created this provider. If you use only All the game providers are cached so we really need to store the state locally as if no new requests are made, the game providers cannot know about a new bookmark value. |
We don't want to store the state of whether a game is bookmarked globally in the app. The source of truth here is the server, not the app, so each time we want to know if a game is bookmarked, the server must provide this information. If you want to store temporarily a "bookmarked" state while waiting for a server response, then a local state in a StatefulWidget is the way to go. |
The games HTTP requests are cached and so is the bookmark value. If we don't want to store the state of whether a game is bookmarked then we would have to remove the HTTP requests cache for games. |
As I guess we don't want to remove the game cache, the only other option I see is too add a new endpoint just for bookmarks, this way we don't have to reask the server all game information with it. |
You mean cached by the provider right? Then you must invalidate the provider to refetch the data when changing bookmark status. |
So on each screen where you can bookmark a game I have to invalidate something like 4 or 5 providers that store games with the bookmark field ? |
Not sure to understand the problem. Can you please list here these providers that store games? |
There are currently only the first two providers that are needed because I didn't add the bookmark option on the home tab recent games list, I did it only for the user game history and game/archived screen but there will probably be even more screens where we will need the bookmark option (analysis screen, study screen, broadcast screen ...).
So when a game is bookmarked I will need to call |
I see. So the various caches I added were not a problem so far. But now they are since we're modifying the bookmark state from the app. Now you need to rebase to the last main commit, where I removed the caches. So now all the listed providers above won't cause a problem anymore. Only in the |
I will probably still need to invalidate some providers as the providers on top of the route stack will not get their providers disposed |
providers so it is possible to remove the bookmark provider
I suppose you meant below in the stack? Like if you bookmark a game in the game screen and then pop the screen to go back to the game list screen? In that case indeed the game won't be bookmarked in that list. We probably need a centralised service to bookmark games. This service would be aware of all the notifiers that implement the |
Yes sorry this is what I meant. The bookmark provider that I had created was an attempt to centralize bookmark values but I agree it had some flaws. If we decide to create a centralized service for bookmarks I think the removal of cache for games provider is not useful anymore so maybe that commit can be reverted ? |
@veloce hopefully it's okay to briefly hijack. Would this be similar to if you run analysis and then go back to game screen and it doesn't reflect it in game list that this is a game that has had analysis run until you pull down to refresh. And if so is it worth filing a new ticket to improve that (if it's even possible) in the same way? |
Yes it's ok to create an issue for that. |
No we should still avoid caching here, that will simplify things. |
Do you have an idea on how this should be implemented ? |
Close #594
Continuation of #868
bookmark.webm