Fix formatting and some warnings

This commit is contained in:
Stone_Red
2024-05-16 19:37:18 +02:00
parent a9bd9c8854
commit 657dbffcd0
3 changed files with 122 additions and 125 deletions
+6 -6
View File
@@ -1,17 +1,18 @@
using Markdowser.ViewModels;
using System.Collections.Generic;
namespace Markdowser.Utilities
{
namespace Markdowser.Utilities;
public class CacheService
{
private Dictionary<string, ContentViewModelBase> cache = new Dictionary<string, ContentViewModelBase>();
private readonly Dictionary<string, ContentViewModelBase> cache = [];
public ContentViewModelBase? Get(string url)
{
if (cache.ContainsKey(url))
if (cache.TryGetValue(url, out ContentViewModelBase? value))
{
return cache[url];
return value;
}
else
{
@@ -24,4 +25,3 @@ using System.Collections.Generic;
cache[url] = content;
}
}
}
@@ -104,7 +104,6 @@ public partial class MainWindowViewModel : ViewModelBase
public ICommand Browse => ReactiveCommand.Create(() => FetchUrl(true));
public ICommand Reload => ReactiveCommand.Create(() => FetchUrl(false));
public ICommand Back => ReactiveCommand.Create(() =>
{
if (GlobalState.BackHistory.Count > 0)
@@ -244,8 +243,8 @@ private void FetchUrl(bool useCache = true)
try
{
ContentViewModelBase cachedContent = cacheService.Get(Url);
if (cachedContent != null && useCache)
ContentViewModelBase? cachedContent = cacheService.Get(Url);
if (cachedContent is not null && useCache)
{
Content = cachedContent;
}
@@ -316,5 +315,4 @@ private void FetchUrl(bool useCache = true)
}
});
}
}
+1 -2
View File
@@ -83,9 +83,8 @@
<Grid IsEnabled="{Binding !IsBusy}" ColumnDefinitions="Auto, Auto, Auto, Auto, *, Auto">
<Button Grid.Column="0" i:Attached.Icon="fa-solid fa-caret-left" IsEnabled="{Binding BackEnabled}" Command="{Binding Back}" />
<Button Grid.Column="1" i:Attached.Icon="fa-solid fa-caret-right" IsEnabled="{Binding ForwardEnabled}" Command="{Binding Forward}" />
<Button Grid.Column="2" i:Attached.Icon="fa-solid fa-rotate-right" Command="{Binding Browse}" />
<Button Grid.Column="2" i:Attached.Icon="fa-solid fa-rotate-right" Command="{Binding Reload}" />
<Button Grid.Column="3" i:Attached.Icon="fa-solid fa-house" Command="{StaticResource HomeCommand}" />
<Button Grid.Column="4" i:Attached.Icon="fa-solid fa-sync" Command="{Binding Reload}" />
<Grid Grid.Column="4">
<TextBox IsVisible="{Binding !IsBusy}" Watermark="Search or type a URL" Text="{Binding Url}" BorderThickness="0">