-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessagePage.xaml.cs
82 lines (73 loc) · 2.45 KB
/
MessagePage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using Microsoft.UI.Xaml.Controls;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace GithubApp
{
public class MessageInfo()
{
public string Title { get; set; }
public string Info { get; set; }
public IReadOnlyList<Octokit.Label> Labels { get; set; }
}
public sealed partial class MessagePage : Page
{
public static string Status;
public static GitClient client = HomePage.client;
public ObservableCollection<MessageInfo> messages = [];
public MessagePage()
{
this.InitializeComponent();
MessageType.Text = Status;
if (Status == "Issues")
{
LoadIssuesData();
}
else
{
LoadPullRequestsData();
}
}
public async void LoadIssuesData()
{
var issues = await client.GetIssuesAsync();
messages = new(issues.Select(x => new MessageInfo()
{
Title = x.Title,
Info = $"# {x.Number} opened {Utils.FormatTimeSpan(x.CreatedAt.LocalDateTime)} by {x.User.Login}",
Labels = x.Labels
}));
MessageView.ItemsSource = messages;
SearchBox.IsEnabled = true;
}
public async void LoadPullRequestsData()
{
var pulls = await client.GetPullRequestsAsync();
messages = new(pulls.Select(x => new MessageInfo()
{
Title= x.Title,
Info = $"# {x.Number} opened {Utils.FormatTimeSpan(x.CreatedAt.LocalDateTime)} by {x.User.Login}",
Labels = x.Labels
}));
MessageView.ItemsSource= messages;
SearchBox.IsEnabled = true;
}
private void SearchMessage(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
SearchBox.IsEnabled = false;
if (SearchBox.Text.Trim() != string.Empty)
{
var result = messages.Where(info => info.Title.Contains(SearchBox.Text.Trim()));
MessageView.ItemsSource = result;
}
else
{
MessageView.ItemsSource = messages;
}
SearchBox.IsEnabled = true;
}
}
}
}