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
35 changes: 35 additions & 0 deletions JitHub.WinUI.Tests/XamlBindingPatternTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,41 @@ public void LooseResourceDictionariesDoNotUseXBind()
string.Join(Environment.NewLine, violations));
}

[Fact]
public void ContainerStyleIsOnlyAppliedToBorders()
{
string winuiRoot = FindWinUIProjectRoot();
List<string> violations = [];

foreach (string path in Directory.EnumerateFiles(winuiRoot, "*.xaml", SearchOption.AllDirectories).Order())
{
string relativePath = Path.GetRelativePath(winuiRoot, path);
string text = File.ReadAllText(path);

foreach (Match match in Regex.Matches(
text,
"<(?<element>[\\w:]+)\\b(?<attrs>[^>]*\\bStyle\\s*=\\s*\"\\{(?:ThemeResource|StaticResource)\\s+Container\\}\"[^>]*)>",
RegexOptions.Singleline))
{
string element = match.Groups["element"].Value;
if (string.Equals(element, "Border", StringComparison.Ordinal) ||
element.EndsWith(":Border", StringComparison.Ordinal))
{
continue;
}

int line = GetLineNumber(text, match.Index);
violations.Add($"{relativePath}:{line}: {element}");
}
}

Assert.True(
violations.Count == 0,
"The shared Container style targets Border and crashes XAML parsing when applied to another element:" +
Environment.NewLine +
string.Join(Environment.NewLine, violations));
}

private static bool IsWholeObjectOrFrameworkBinding(string expression)
{
if (string.IsNullOrWhiteSpace(expression))
Expand Down
54 changes: 53 additions & 1 deletion JitHub.WinUI/ViewModels/Pages/RepoManagePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
using CommunityToolkit.Mvvm.ComponentModel;
using JitHub.Models.GitHub;
using JitHub.Services;
using Microsoft.UI.Xaml.Data;

namespace JitHub.WinUI.ViewModels.Pages;

[Bindable]
public sealed partial class RepoManagePageViewModel : ViewModelBase
{
private readonly IAuthService _authService;
Expand All @@ -30,6 +32,12 @@ public RepoManagePageViewModel()

public ObservableCollection<GitHubRepositorySelectionItem> Repositories { get; } = [];

public string PageTitle => GetString("RepoManage.PageTitle", "Manage repositories");

public string PageDescription => GetString(
"RepoManage.PageDescription",
"Review and delete repositories from your GitHub account.");

public string DeleteSelectedButtonText => GetString("RepoManage.DeleteSelectedButton", "Delete selected");

public string ClearSelectionButtonText => GetString("RepoManage.ClearSelectionButton", "Clear selection");
Expand Down Expand Up @@ -64,6 +72,9 @@ public RepoManagePageViewModel()
[ObservableProperty]
public partial bool IsDeletionProgressVisible { get; set; }

[ObservableProperty]
public partial bool IsLoadingRepositories { get; set; }

[ObservableProperty]
public partial double DeletionProgressValue { get; set; }

Expand All @@ -82,6 +93,7 @@ public async Task LoadRepositoriesAsync()

try
{
IsLoadingRepositories = true;
StatusText = GetString("RepoManage.LoadingRepositories", "Loading repositories...");
Repositories.Clear();
AreRepositoriesVisible = false;
Expand Down Expand Up @@ -135,6 +147,19 @@ public async Task LoadRepositoriesAsync()
"Dashboard.RepositoriesNetworkError",
"JitHub could not reach GitHub to load your repositories.");
}
catch (Exception ex)
{
AreRepositoriesVisible = false;
IsEmptyStateVisible = true;
StatusText = FormatString(
"RepoManage.LoadFailureStatus",
"JitHub could not load repositories: {0}",
ex.Message);
}
finally
{
IsLoadingRepositories = false;
}
}

public void ClearSelection()
Expand Down Expand Up @@ -203,6 +228,10 @@ await _gitHubClientService.DeleteRepositoryAsync(
{
failures.Add($"{repositoryItem.Repository.FullName}: {GetString("RepoManage.DeleteFailureNetworkErrorShort", "network error")}");
}
catch (Exception ex)
{
failures.Add($"{repositoryItem.Repository.FullName}: {ex.Message}");
}
}

await LoadRepositoriesAsync();
Expand Down Expand Up @@ -231,9 +260,32 @@ public string FormatDeleteDialogContent(int selectedRepositoryCount)
selectedRepositoryCount);
}

public void ShowUnexpectedError(Exception exception)
{
AreRepositoriesVisible = Repositories.Count > 0;
IsEmptyStateVisible = Repositories.Count == 0;
StatusText = FormatString(
"RepoManage.UnexpectedErrorStatus",
"JitHub could not manage repositories: {0}",
exception.Message);
IsInteractionEnabled = true;
IsDeletionProgressVisible = false;
IsLoadingRepositories = false;
}

private bool TryGetActiveToken(out string token)
{
token = GetActiveToken() ?? string.Empty;
try
{
token = GetActiveToken() ?? string.Empty;
}
catch (Exception ex)
{
token = string.Empty;
ShowUnexpectedError(ex);
return false;
}

if (!string.IsNullOrWhiteSpace(token))
{
return true;
Expand Down
4 changes: 2 additions & 2 deletions JitHub.WinUI/Views/DataTemplates/Repository/ForkRepo.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</Button>
</DataTemplate>
<DataTemplate x:Key="SelectableForkRepo">
<Grid Style="{ThemeResource Container}">
<Border Style="{ThemeResource Container}">
<CheckBox IsChecked="{Binding Selected, Mode=TwoWay}">
<Grid Margin="16,0,0,0">
<Grid.ColumnDefinitions>
Expand All @@ -85,7 +85,7 @@
</StackPanel>
</Grid>
</CheckBox>
</Grid>
</Border>
</DataTemplate>
</ResourceDictionary>

Expand Down
4 changes: 2 additions & 2 deletions JitHub.WinUI/Views/DataTemplates/Repository/PrivateRepo.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</Button>
</DataTemplate>
<DataTemplate x:Key="SelectablePrivateRepo">
<Grid Style="{ThemeResource Container}">
<Border Style="{ThemeResource Container}">
<CheckBox IsChecked="{Binding Selected, Mode=TwoWay}">
<Grid Margin="16,0,0,0">
<Grid.ColumnDefinitions>
Expand All @@ -85,7 +85,7 @@
</StackPanel>
</Grid>
</CheckBox>
</Grid>
</Border>
</DataTemplate>
</ResourceDictionary>

Expand Down
4 changes: 2 additions & 2 deletions JitHub.WinUI/Views/DataTemplates/Repository/PublicRepo.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</Button>
</DataTemplate>
<DataTemplate x:Key="SelectablePublicRepo">
<Grid Style="{ThemeResource Container}">
<Border Style="{ThemeResource Container}">
<CheckBox IsChecked="{Binding Selected, Mode=TwoWay}">
<Grid Margin="16,0,0,0">
<Grid.ColumnDefinitions>
Expand All @@ -89,7 +89,7 @@
</StackPanel>
</Grid>
</CheckBox>
</Grid>
</Border>
</DataTemplate>
</ResourceDictionary>

Expand Down
Loading
Loading