Skip to content

Commit

Permalink
Support cache for activity indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Strypper committed Mar 24, 2024
2 parents cbb8bc5 + 52de297 commit b24d754
Show file tree
Hide file tree
Showing 37 changed files with 4,883 additions and 2,138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,47 @@ public class GitHubIssueLocalDbService : SQLitePCLRawService<GitHubIssueLocalDbM
{
#region [ CTor ]

public GitHubIssueLocalDbService(DatabaseSettings settings) : base(settings) {
public GitHubIssueLocalDbService(DatabaseSettings settings) : base(settings)
{

}


#endregion

#region [ Methods - Get Single ]
public async Task<GitHubIssueLocalDbModel?> GetByIssueUrlAsync(string issueUrl) {
try {
if (string.IsNullOrEmpty(issueUrl)) {
public async Task<GitHubIssueLocalDbModel?> GetByIssueUrlAsync(string issueUrl)
{
try
{
if (string.IsNullOrEmpty(issueUrl))
{
return default;
}

return await _connection.Table<GitHubIssueLocalDbModel>().FirstOrDefaultAsync(x => x.IssueLinkUrl == issueUrl);
}
catch (Exception ex) {
catch (Exception ex)
{
throw;
}
}
#endregion

#region [ Methods - Get List ]
public async Task<IEnumerable<GitHubIssueLocalDbModel>?> GetByControlNameAsync(string controlName) {
try {
if (string.IsNullOrEmpty(controlName)) {
public async Task<IEnumerable<GitHubIssueLocalDbModel>?> GetByControlNameAsync(string controlName)
{
try
{
if (string.IsNullOrEmpty(controlName))
{
return default;
}

return await _connection.Table<GitHubIssueLocalDbModel>().Where(x => x.ControlName == controlName).ToListAsync();
}
catch (Exception ex) {
catch (Exception ex)
{
throw;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Presentations/Windows/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
ContentTemplate="{DataTemplate app:HomePage}"
Icon="{x:StaticResource HomeIcon}"
Route="homePage" />
<ShellContent
<!--<ShellContent
Title="Chat"
ContentTemplate="{DataTemplate app:ChatPage}"
Icon="{x:StaticResource ChatIcon}"
Route="chatPage" />
Route="chatPage" />-->
<ShellContent
Title="Gallery"
ContentTemplate="{DataTemplate app:GalleryPage}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ async Task RefreshAsync()
}
#endregion


#region [ Methods ]

async Task RefreshControlIssues(bool forced)
Expand All @@ -126,13 +125,15 @@ async Task RefreshControlIssues(bool forced)

// First: sync from local db.
// TODO: how to get control name?
var allLocalDbIssues = await GetIssueByControlNameFromLocalDb("");
var allLocalDbIssues = await GetIssueByControlNameFromLocalDb(ControlInformation.ControlName);

// If localdb version is not null & not outdated => use local version.
if (allLocalDbIssues != null && allLocalDbIssues.Any() && !allLocalDbIssues.Any(x => (now - x.LastUpdated).TotalHours > 1))
{
if (ControlIssues is null || forced) {
ControlIssues = new(allLocalDbIssues.Select(x => new ControlIssueModel() {
if (ControlIssues is null || forced)
{
ControlIssues = new(allLocalDbIssues.Select(x => new ControlIssueModel()
{
IssueId = x.IssueId,
Title = x.Title,
IssueLinkUrl = x.IssueLinkUrl,
Expand All @@ -143,6 +144,7 @@ async Task RefreshControlIssues(bool forced)
LastUpdated = x.LastUpdated
}));
}
IsBusy = false;

// Done.
return;
Expand All @@ -159,7 +161,8 @@ async Task RefreshControlIssues(bool forced)
var issues = result.AsT0.AttachedData as IEnumerable<GitHubIssueModel>;

// Save to localdb.
foreach(var issue in issues) {
foreach (var issue in issues)
{
await UpdateLocalIssue(issue);
}

Expand All @@ -171,6 +174,7 @@ async Task RefreshControlIssues(bool forced)
{
IssueId = x.Id,
Title = x.Title,

IssueLinkUrl = x.HtmlUrl,
MileStone = x.Milestone is null ? "No mile stone" : x.Milestone.Title,
OwnerName = x.User.Login,
Expand All @@ -197,30 +201,37 @@ await AppNavigator.ShowSnackbarAsync(error.ErrorDetail,
#endregion

#region [ Methods - GitHub Issues - LocalDb ]
private async Task<IEnumerable<GitHubIssueLocalDbModel>> GetIssueByControlNameFromLocalDb(string controlName) {
try {
private async Task<IEnumerable<GitHubIssueLocalDbModel>> GetIssueByControlNameFromLocalDb(string controlName)
{
try
{
var now = DateTime.UtcNow;

return await gitHubIssueLocalDbService.GetByControlNameAsync(controlName);
}
catch (Exception) {
catch (Exception)
{
// Treat as nothing found.
return default;
}
}

private async Task UpdateLocalIssue(GitHubIssueModel issue) {
try {
private async Task UpdateLocalIssue(GitHubIssueModel issue)
{
try
{
var now = DateTime.UtcNow;

var localIssue = await gitHubIssueLocalDbService.GetByIssueUrlAsync(issue.Url);

if(localIssue is null) {
await gitHubIssueLocalDbService.AddAsync(new() {
if (localIssue is null)
{
await gitHubIssueLocalDbService.AddAsync(new()
{
IssueId = issue.Id,
Title = issue.Title,
IssueLinkUrl = issue.Url,
ControlName = "",
ControlName = ControlInformation.ControlName,
MileStone = issue.Milestone?.Title,
OwnerName = issue.User?.Login,
UserAvatarUrl = issue.User?.AvatarUrl,
Expand All @@ -236,7 +247,8 @@ await gitHubIssueLocalDbService.AddAsync(new() {

await gitHubIssueLocalDbService.UpdateAsync(localIssue);
}
catch (Exception) {
catch (Exception)
{
// TODO: should do something.
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Padding="10"
x:DataType="app:ImageButtonPageViewModel"
BackgroundColor="Transparent">

<core:BasePage.ToolbarItems>
<ToolbarItem
Command="{x:Binding OpenUrlCommand}"
Expand All @@ -27,6 +28,10 @@
The .NET Multi-platform App UI (.NET MAUI) Button displays text and responds to a tap or click that directs the app to carry out a task. A Button usually displays a short text string indicating a command, but it can also display a bitmap image, or a combination of text and an image. When the Button is pressed with a finger or clicked with a mouse it initiates that command.
</x:String>

<x:String x:Key="ReportIssueToMauiTeamLink">
https://github.com/dotnet/maui/issues/new/choose
</x:String>

<x:String x:Key="PropertiesListHeader">
Button defines the following properties:
</x:String>
Expand Down Expand Up @@ -200,7 +205,7 @@
</VerticalStackLayout>
</Border>
</Grid>
<VerticalStackLayout Spacing="20">
<VerticalStackLayout Grid.Column="1" Spacing="20">
<Border Padding="20" StrokeShape="RoundRectangle 4">
<Label FontSize="Subtitle" Text="{x:StaticResource ControlInfo}" />
</Border>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ImageButtonPageViewModel(IAppNavigator appNavigator,
#region [ Properties ]

[ObservableProperty]
string emptyViewText = "No issues found for this control";
string emptyViewText = "Fetching issues";

[ObservableProperty]
string gitHubAPIRateLimit = "https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public SliderPageViewModel(IAppNavigator appNavigator,
#region [ Properties ]

[ObservableProperty]
string emptyViewText = "No issues found for this control";
string emptyViewText = "Fetching issues";

[ObservableProperty]
string gitHubAPIRateLimit = "https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28";
Expand Down Expand Up @@ -64,12 +64,6 @@ protected override void OnInit(IDictionary<string, object> query)
ControlInformation = query.GetData<IBuiltInGalleryCardInfo>();

}

public override async Task OnAppearingAsync()
{
await base.OnAppearingAsync();
await RefreshAsync();
}
#endregion

#region [Relay Commands]
Expand All @@ -85,7 +79,6 @@ async Task RefreshAsync()
}
#endregion


#region [ Methods ]

async Task RefreshControlIssues(bool forced)
Expand Down
Loading

0 comments on commit b24d754

Please sign in to comment.