Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions WheelWizard/Views/Patterns/VrHistoryGraph.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,18 @@
<TextBlock Classes="TinyText" FontSize="11" Text="{Binding DateRangeText}" />
</StackPanel>

<StackPanel Grid.Column="1" Orientation="Horizontal">
<StackPanel Grid.Column="1" Orientation="Horizontal" Spacing="10" VerticalAlignment="Center">
<components:LoadingIcon Margin="3,3,6,3" VerticalAlignment="Center" IsVisible="{Binding IsLoading}" Width="18" Height="18" Foreground="{StaticResource Neutral500}" />

<CheckBox Classes="Switch"
Content="Matches"
IsChecked="{Binding UseMatchesAsXAxis}"
FontSize="12"
VerticalAlignment="Center"/>

<ComboBox x:Name="HistoryDaysDropdown"
MinWidth="145"
VerticalAlignment="Top"
VerticalAlignment="Center"
SelectionChanged="HistoryDaysDropdown_OnSelectionChanged" />
</StackPanel>
</Grid>
Expand Down
63 changes: 52 additions & 11 deletions WheelWizard/Views/Patterns/VrHistoryGraph.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public partial class VrHistoryGraph : UserControlBase, INotifyPropertyChanged
private int _reloadVersion;
private bool _isInitializingDaysDropdown;
private int _selectedHistoryDays = DefaultHistoryDays;
private bool _useMatchesAsXAxis;
private RwfcPlayerVrHistoryResponse? _lastHistoryResponse;
private Geometry? _graphPath;
private Geometry? _graphAreaPath;
private string _graphStartLabel = string.Empty;
Expand All @@ -54,6 +56,22 @@ static VrHistoryGraph()
FriendCodeProperty.Changed.AddClassHandler<VrHistoryGraph>((graph, _) => graph.TriggerHistoryReload());
}

public bool UseMatchesAsXAxis
{
get => _useMatchesAsXAxis;
set
{
if (_useMatchesAsXAxis == value)
return;

_useMatchesAsXAxis = value;
OnPropertyChanged(nameof(UseMatchesAsXAxis));

if (_lastHistoryResponse != null)
ApplyHistoryData(_lastHistoryResponse, _selectedHistoryDays);
}
}
Comment on lines +59 to +73
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Prevent stale cached data from being re-applied during active reloads.

At Line 70-Line 72, toggling can re-render _lastHistoryResponse while IsLoading is true, which can temporarily show stale data from a previous context with the newly selected range.

Suggested fix
 public bool UseMatchesAsXAxis
 {
     get => _useMatchesAsXAxis;
     set
     {
         if (_useMatchesAsXAxis == value)
             return;

         _useMatchesAsXAxis = value;
         OnPropertyChanged(nameof(UseMatchesAsXAxis));

-        if (_lastHistoryResponse != null)
+        if (!IsLoading && _lastHistoryResponse != null)
             ApplyHistoryData(_lastHistoryResponse, _selectedHistoryDays);
     }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public bool UseMatchesAsXAxis
{
get => _useMatchesAsXAxis;
set
{
if (_useMatchesAsXAxis == value)
return;
_useMatchesAsXAxis = value;
OnPropertyChanged(nameof(UseMatchesAsXAxis));
if (_lastHistoryResponse != null)
ApplyHistoryData(_lastHistoryResponse, _selectedHistoryDays);
}
}
public bool UseMatchesAsXAxis
{
get => _useMatchesAsXAxis;
set
{
if (_useMatchesAsXAxis == value)
return;
_useMatchesAsXAxis = value;
OnPropertyChanged(nameof(UseMatchesAsXAxis));
if (!IsLoading && _lastHistoryResponse != null)
ApplyHistoryData(_lastHistoryResponse, _selectedHistoryDays);
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@WheelWizard/Views/Patterns/VrHistoryGraph.axaml.cs` around lines 59 - 73, The
toggle setter for UseMatchesAsXAxis currently re-applies cached
_lastHistoryResponse even when a reload is in progress; update the setter to
skip calling ApplyHistoryData(_lastHistoryResponse, _selectedHistoryDays) when
IsLoading is true (or when a backing flag like _isLoading indicates an active
load), or clear/ignore _lastHistoryResponse during loads so stale data isn't
rendered; specifically modify the UseMatchesAsXAxis setter to check IsLoading
(or _isLoading) before invoking ApplyHistoryData and only apply cached data when
not loading.


public string? FriendCode
{
get => GetValue(FriendCodeProperty);
Expand Down Expand Up @@ -372,6 +390,7 @@ private void SetNoFriendCodeState()

private void ApplyHistoryData(RwfcPlayerVrHistoryResponse historyResponse, int days)
{
_lastHistoryResponse = historyResponse;
EmptyStateText = "No VR history found for this range yet.";
StartingVr = historyResponse.StartingVr;
EndingVr = historyResponse.EndingVr;
Expand Down Expand Up @@ -408,19 +427,40 @@ private void ApplyHistoryData(RwfcPlayerVrHistoryResponse historyResponse, int d

GraphMinVrText = minVr.ToString("N0");
GraphMaxVrText = maxVr.ToString("N0");
var labelFormat = days >= 7 ? "MMM d" : "MMM d HH:mm";
GraphStartLabel = graphStart.ToLocalTime().ToString(labelFormat);
GraphMidLabel = graphStart.AddSeconds(totalSeconds / 2).ToLocalTime().ToString(labelFormat);
GraphEndLabel = graphEnd.ToLocalTime().ToString(labelFormat);

if (UseMatchesAsXAxis)
{
GraphStartLabel = "Match 1";
GraphMidLabel = $"Match {(orderedByDate.Count / 2) + 1}";
GraphEndLabel = $"Match {orderedByDate.Count}";
}
else
{
var labelFormat = days >= 7 ? "MMM d" : "MMM d HH:mm";
GraphStartLabel = graphStart.ToLocalTime().ToString(labelFormat);
GraphMidLabel = graphStart.AddSeconds(totalSeconds / 2).ToLocalTime().ToString(labelFormat);
GraphEndLabel = graphEnd.ToLocalTime().ToString(labelFormat);
}

var points = orderedByDate
.Select(entry =>
{
var seconds = (entry.Date - graphStart).TotalSeconds;
var x = seconds / totalSeconds * GraphWidth;
var y = GraphHeight - (entry.TotalVr - minVr) / (double)vrRange * GraphHeight;
return new Point(x, y);
})
.Select(
(entry, i) =>
{
double x;
if (UseMatchesAsXAxis)
{
x = orderedByDate.Count > 1 ? (double)i / (orderedByDate.Count - 1) * GraphWidth : 0;
}
else
{
var seconds = (entry.Date - graphStart).TotalSeconds;
x = seconds / totalSeconds * GraphWidth;
}

var y = GraphHeight - (entry.TotalVr - minVr) / (double)vrRange * GraphHeight;
return new Point(x, y);
}
)
Comment thread
patchzyy marked this conversation as resolved.
.ToList();

GraphPath = BuildLineGeometry(points);
Expand All @@ -430,6 +470,7 @@ private void ApplyHistoryData(RwfcPlayerVrHistoryResponse historyResponse, int d

private void ResetGraph()
{
_lastHistoryResponse = null;
GraphPath = null;
GraphAreaPath = null;
GraphStartLabel = string.Empty;
Expand Down
Loading