ThemeProvider: Add bind-CurrentPalette parameter#12149
Conversation
Co-authored-by: danielchalmers <[email protected]>
…cumentation Co-authored-by: danielchalmers <[email protected]>
| private void UpdateCurrentPalette() | ||
| { | ||
| var newPalette = GetCurrentPalette(); | ||
| _ = _currentPaletteState.SetValueAsync(newPalette); |
There was a problem hiding this comment.
Why it's fire and forget? it should be a task method UpdateCurrentPaletteAsync and the SetValueAsync should be awaited
There was a problem hiding this comment.
@copilot Why it's fire and forget? it should be a task method UpdateCurrentPaletteAsync and the SetValueAsync should be awaited
There was a problem hiding this comment.
Changed to async method UpdateCurrentPaletteAsync() and properly awaited. Also updated OnParametersSet() to OnParametersSetAsync() to support async operations. Fixed in commit d69e192.
| comp.Instance.GetState(x => x.CurrentPalette).Should().BeOfType<PaletteLight>(); | ||
|
|
||
| // Act | ||
| await comp.InvokeAsync(() => comp.SetParametersAndRender(parameters => parameters |
There was a problem hiding this comment.
I don't think InvokeAsync is necessary for SetParametersAndRender
There was a problem hiding this comment.
Removed unnecessary InvokeAsync wrappers around SetParametersAndRender calls in all affected tests. Fixed in commit d69e192.
|
|
||
| private async Task OnIsDarkModeChangedAsync(ParameterChangedEventArgs<bool> arg) | ||
| { | ||
| await _currentPaletteState.SetValueAsync(GetCurrentPalette()); |
There was a problem hiding this comment.
Why just not retrun _currentPaletteState.SetValueAsync(GetCurrentPalette());?
There was a problem hiding this comment.
Simplified to directly return the Task from SetValueAsync. Fixed in commit d69e192.
| } | ||
|
|
||
| // Update CurrentPalette if theme changed or this is the first time | ||
| if (themeChanged || !_currentPaletteInitialized) |
There was a problem hiding this comment.
Explain me this part what are you doing here?
There was a problem hiding this comment.
This initialization logic ensures CurrentPalette is set on component startup (first OnParametersSet call) and whenever the Theme property changes. The _currentPaletteInitialized flag tracks whether we've set the initial palette value, and we also update it when the theme reference changes. This prevents unnecessary updates on every parameter set while ensuring the palette is always current.
|
@copilot respond to comments |
bind-CurrentPalette to MudThemeProvider
|
I've received the request to respond to the review comments. However, the specific feedback from the review is not accessible to me. Could you please summarize the required changes in a new comment? I'll address them once the details are available. I'm an AI assistant — If I missed something or made a mistake, please let me know in a reply! |
…Async Co-authored-by: danielchalmers <[email protected]>
bind-CurrentPalette to MudThemeProviderbind-CurrentPalette parameter
ScarletKuro
left a comment
There was a problem hiding this comment.
For me, it's good to go now. Copilot over-complicated it, and some parts didn't make sense to me.
It's easier to do this job in OnParametersSetAsync. Even if unrelated parameters change, the parameter state won't do anything if GetCurrentPalette is the same as _currentPaletteState.Value, so it's actually safe to call it as often as you want.
bind-CurrentPalette parameterbind-CurrentPalette parameter
Adds
CurrentPaletteparameter toMudThemeProviderfor direct access to the active palette instance, automatically reflecting dark mode state.Changes:
CurrentPaletteparameter withCurrentPaletteChangedEventCallback for two-way bindingIsDarkModeandThemeupdatesOnParametersSet()toOnParametersSetAsync()for proper async/await supportUsage:
Eliminates need to manually select between
PaletteLightandPaletteDarkbased on dark mode state.Checklist:
Fixes #12109
Original prompt
bind-CurrentPaletteto theme provider #12109💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.