-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
+AutoZen (Closes #12537) #13154
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
+AutoZen (Closes #12537) #13154
Conversation
-Rem one unused arg in radios
* master: (55 commits)
globally import cats.{Eq, Show, data.NonEmptyList}
scala tweaks
fix Long to Int
globally import cats.syntax.all.*
tweak tournament top cache
scala tweaks
use union type after lichess-org#13134
neater cats syntax after lichess-org#13134
New Crowdin updates (lichess-org#13167)
use ReadPref.priTemp
Fix wrong rewrite by scalafmt
fix ublog page title when editing
Update git blame ignore revs
Fix scalafmt crashes
Run scalafmtAll again
Fix compiling error
Run scalafmtAll
reduce some youtube streamer log statement priorities
Bump scalafmt 3.7.7 and add rewrite config
remove last references to ReadPreference
...
modules/pref/src/main/Pref.scala
Outdated
| value match | ||
| case "1" => 1 | ||
| case "2" => 2 | ||
| case "3" => 3 |
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.
3? in which case do we want to set it to 3?
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.
Hi,
I was trying to do as you said here : #12537 (comment)
To use 4 values of zen, while displaying 3 in the preference menu/ui. The user, if let's say he's in a puzzle and press 'z' while on value '2', would be having it's zen set to 3.
app/views/account/bits.scala
Outdated
| def setting(name: Frag, body: Frag) = st.section(h2(name), body) | ||
|
|
||
| def radios[A](field: play.api.data.Field, options: Iterable[(A, String)], prefix: String = "ir") = | ||
| def radios[A](field: play.api.data.Field, options: Iterable[(A, String)], valueAliases: Option[Map[Option[String], Option[String]]] = None) = |
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.
... what
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.
(following the other comment above)
The valueAliases is specifically to to make is so what of those 4 values is equaled to the other (3->2) for the user when he looks at the menu of pref/ui. This allows to keep the old behavior of zen toggling.
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.
then it would be better to avoid using this radios function, rather than adding this strange complexity no other caller needs.
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.
I see; would making a function radios_with_aliases do the job ?
| val id = s"$prefix${field.id}_$key" | ||
| val checked = field.value has key.toString | ||
| val id = s"ir${field.id}_$key" | ||
| val checked = (field.value has key.toString) || (~((~valueAliases).get(field.value)) has key.toString) |
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.
not sure what's going on here but there has to be a better way
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.
(following the other comment above)
By splitting the pref into 2 bools, I am able to do like you said in your comment in the issue, to have 4 separate values, while being able to toggle one of those values (so zen in game being automatic remains independant from using zen in another place)
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.
radios_with_aliases is not a scala function name, look around for conventions.
Option[Map[Option[String], Option[String]]] looks very wrong and causes the implementation to be unnecessary complicated
|
|
||
| private def saveZen()(value: String, ctx: Context): Fu[Cookie] = | ||
| //Discard 0-1 bit, then add 0-1 bit with wanted value | ||
| var newVal = ctx.pref.zenInt & ~1 | value.toInt |
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 is quite cryptic, even with the comment. Why?
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.
Zen.GAME_AUTO (=2) was initially Zen.Automatic_Bit [with Zen.Game_On ('3') and Zen.Game_Off, with same '2' value] when I started developping it ; this helped understand that it is a bit functionality (I had 3 var, but 2 were unused so no point in keeping them in the end).
This makes it so the user can keep toggling it's zen, and that whatever he does, when he toggles it, it will only affect the "yes-no" part of it, and never the "Automatic-in-game" part of it (while can only be activated/deactivated via the pref menu).
This reduces the knowledge one needs regarding toggling zen, and allows to not have on every zenable page conditionnal setting of value (e.g. if zen is automatically-in-game or not).
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.
I see but the problem with this is that it leaks the zen storage binary subtleties to the Pref controller.
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.
Do you mean file-wise or execution-wise ? Would moving saveZen in a helper file solve this ? Or should I put more conditional logic in the .ts ?
|
Not a fan of what that introduces in the code. I can already hear future me swear while refactoring it. |
|
Here's the explanation on the issue page:
Somehow that doesn't help me understand what's going on here. Only thing I can say is that indeed saving zen on each game start and end would be a terrible idea. |
Would you prefer if I removed the saveZen scala logic (app/controllers/Pref.scala would be fully like before) and push more conditionnal logic into the various zenable .ts (change the various "const zen = $('body').toggleClass('zen').hasClass('zen'); [...] setZen(zen);") ? EDIT : Also possibly one part of the misunderstanding is that I'm trying to keep the old Zen behavior, because I still believe that someone may want for instance to use zen doing puzzle, while still keeping it automatic in games. Do we want to prevent that and force in-game only and prevent zen mode outside of games with Zen-mode auto ? |
|
If the user selects "In-game only" then it's fair to only set zen in games, and not in puzzles. The use case here is probably to avoid being distracted by opponent ratings, something specific to games. |
By this do you mean to prevent using 'zen' in puzzles ? As I understand, and as you said here #12443 (comment) it may breaks user workflow when not allowing the togglability/toggling zen anymore. Plus what if you're in game and cannot use zen anymore ? (Since from what you're saying is to enforce the "In-game only" from what I'm understanding; I still believe the user should be able to toggle everywhere) Shouldn't 'z' / zen toggle be kept everywhere ? |
|
Yes we want to preserve the feature in every place of the site that supports it. I was saying that if the user selects "in-game only" then it's ok to only use it in games. |
586e86d to
3a44361
Compare
3a44361 to
27e94d6
Compare
27e94d6 to
c3fc269
Compare
|
Hi @ornicar ! Thanks for the comments :) ! 1- I am a bit confused…
Perhaps I should rename the button "in-game only" to "Automatic in-game" then, and also keep zen every where in every cases. That way there is less loss of functionality for the user everywhere. Because the issue itself isn't to make it only in-game, but to make it toggle automatic in-game… 2- I did rename "radios" function to "radios_with_aliases". 3- Could you tell me about #13154 (comment) ? Thank you ! |
|
The whole thing looks sketchy and I feel like it would be better for me to start over and try to find a simple solution, than to try to slowly fix this. Unfortunately I have more important stuff in the oven atm. I'm not even sure an elegant solution that would make the feature simple enough to be acceptable even exists. |
|
I have in mind of removing the 4th state mentioned (zen==3), and that would simplify everything. It would remove the pref-controller complexity, the alias complexity and the bit complexity. Then to compensate I'd just put the "zen-automatic" (if pref ==2) whenever something is zenable, and simply not Xhr call when "zen-automatic". So toggling would still work everywhere I believe, just not be saved in prefs, when in automatic. I think it would be much more peaceful code-wise. I'll probably do that on ~next week. |
|
Closed in favor of #13304 |
-Rem one unused arg in radios