Code cleanup

This commit is contained in:
ahjephson
2024-06-03 08:04:09 +01:00
parent b7c057468d
commit f49b876666
48 changed files with 73 additions and 87 deletions

View File

@@ -44,4 +44,4 @@ namespace Lantean.QBTMudBlade.Components.Dialogs
MudDialog.Close(Tags);
}
}
}
}

View File

@@ -19,7 +19,7 @@ namespace Lantean.QBTMudBlade.Components.Dialogs
public IEnumerable<string> Hashes { get; set; } = [];
protected HashSet<string> Categories { get; set; } = [];
protected IList<string> TorrentCategories { get; private set; } = [];
protected override async Task OnInitializedAsync()

View File

@@ -1,7 +1,6 @@
using Lantean.QBitTorrentClient;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using static MudBlazor.CategoryTypes;
namespace Lantean.QBTMudBlade.Components.Dialogs
{
@@ -20,7 +19,7 @@ namespace Lantean.QBTMudBlade.Components.Dialogs
public IEnumerable<string> Hashes { get; set; } = [];
protected HashSet<string> Tags { get; set; } = [];
protected IList<IReadOnlyList<string>> TorrentTags { get; private set; } = [];
protected override async Task OnInitializedAsync()

View File

@@ -1,10 +1,6 @@
using Blazored.LocalStorage;
using Lantean.QBitTorrentClient.Models;
using Lantean.QBTMudBlade.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using System.Data.Common;
using static MudBlazor.CategoryTypes;
namespace Lantean.QBTMudBlade.Components
{
@@ -237,7 +233,7 @@ namespace Lantean.QBTMudBlade.Components
protected string RowStyleFuncInternal(T item, int index)
{
var style = "user-select: none; cursor: pointer;";
//EqualityComparer<T>.Default.Equals(item, SelectedItem) ||
//EqualityComparer<T>.Default.Equals(item, SelectedItem) ||
if (SelectedItems.Contains(item))
{
style += " background-color: var(--mud-palette-grey-dark); color: var(--mud-palette-grey-light) !important;";

View File

@@ -35,4 +35,4 @@ namespace Lantean.QBTMudBlade.Components
await ErrorBoundary.RecoverAndClearErrors();
}
}
}
}

View File

@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using MudBlazor;
using MudBlazor.Utilities;
@@ -32,7 +31,6 @@ namespace Lantean.QBTMudBlade.Components
[Parameter]
public Color IconColor { get; set; } = Color.Default;
[Parameter]
public string? Target { get; set; }
@@ -69,4 +67,4 @@ namespace Lantean.QBTMudBlade.Components
await OnClick.InvokeAsync(ev);
}
}
}
}

View File

@@ -192,7 +192,7 @@ namespace Lantean.QBTMudBlade.Components
{
files = await ApiClient.GetTorrentContents(Hash);
}
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden)
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden || exception.StatusCode == HttpStatusCode.NotFound)
{
_timerCancellationToken.CancelIfNotDisposed();
return;
@@ -332,7 +332,7 @@ namespace Lantean.QBTMudBlade.Components
}
return FileList!.Values.Where(f => f.Name.StartsWith(contentItem.Name + Extensions.DirectorySeparator) && !f.IsFolder);
}
}
private IEnumerable<ContentItem> GetChildren(ContentItem folder, int level)
{

View File

@@ -1,8 +1,6 @@
using Blazored.LocalStorage;
using Lantean.QBTMudBlade.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using static MudBlazor.Colors;
namespace Lantean.QBTMudBlade.Components
{
@@ -68,14 +66,13 @@ namespace Lantean.QBTMudBlade.Components
await CategoryChanged.InvokeAsync(category);
}
var tag = await LocalStorage.GetItemAsStringAsync(_tagSelectionStorageKey);
if (tag is not null)
{
Tag = tag;
await TagChanged.InvokeAsync(tag);
}
var tracker = await LocalStorage.GetItemAsStringAsync(_trackerSelectionStorageKey);
if (tracker is not null)
{

View File

@@ -70,7 +70,7 @@ namespace Lantean.QBTMudBlade.Components
Pieces = await ApiClient.GetTorrentPieceStates(Hash);
Properties = await ApiClient.GetTorrentProperties(Hash);
}
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden)
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden || exception.StatusCode == HttpStatusCode.NotFound)
{
_timerCancellationToken.CancelIfNotDisposed();
return;

View File

@@ -1,7 +1,6 @@
using Lantean.QBitTorrentClient;
using Lantean.QBitTorrentClient.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using MudBlazor;
namespace Lantean.QBTMudBlade.Components

View File

@@ -21,7 +21,7 @@ namespace Lantean.QBTMudBlade.Components
public bool Disabled { get; set; }
/// <inheritdoc cref="MudBlazor.MudFormComponent{T}.Validation"/>
[Parameter]
[Parameter]
public object? Validation { get; set; }
/// <inheritdoc cref="MudBlazor.MudField.HelperText"/>
@@ -34,4 +34,4 @@ namespace Lantean.QBTMudBlade.Components
await ValueChanged.InvokeAsync(value);
}
}
}
}

View File

@@ -13,4 +13,4 @@ namespace Lantean.QBTMudBlade.Components
[Parameter]
public RenderFragment? ChildContent { get; set; }
}
}
}

View File

@@ -55,7 +55,7 @@
return null;
};
protected Func<int, string?> SlowTorrentDlRateThresholdValidation = value =>
{
if (value < 1)
@@ -150,7 +150,7 @@
MaxSeedingTimeEnabled = false;
MaxSeedingTime = 1440;
}
MaxRatioAct = Preferences.MaxRatioAct;
if (Preferences.MaxInactiveSeedingTimeEnabled)

View File

@@ -1,6 +1,4 @@
using System.Numerics;
namespace Lantean.QBTMudBlade.Components.Options
namespace Lantean.QBTMudBlade.Components.Options
{
public partial class ConnectionOptions : Options
{
@@ -97,7 +95,7 @@ namespace Lantean.QBTMudBlade.Components.Options
MaxConnecEnabled = false;
MaxConnec = 500;
}
if (Preferences.MaxConnecPerTorrent > 0)
{
MaxConnecPerTorrentEnabled = true;
@@ -179,7 +177,7 @@ namespace Lantean.QBTMudBlade.Components.Options
protected void MaxConnecEnabledChanged(bool value)
{
MaxConnecEnabled = value;
MaxConnecEnabled = value;
}
protected async Task MaxConnecChanged(int value)

View File

@@ -1,6 +1,4 @@
using ByteSizeLib;
namespace Lantean.QBTMudBlade.Components.Options
namespace Lantean.QBTMudBlade.Components.Options
{
public partial class SpeedOptions : Options
{
@@ -149,7 +147,7 @@ namespace Lantean.QBTMudBlade.Components.Options
{
return;
}
ScheduleFrom = value.Value;
bool hasChanged = false;
if (value.Value.Hours != Preferences?.ScheduleFromHour)

View File

@@ -408,4 +408,4 @@ namespace Lantean.QBTMudBlade.Components.Options
await JSRuntime.Open(url, true);
}
}
}
}

View File

@@ -71,7 +71,7 @@ namespace Lantean.QBTMudBlade.Components
{
peers = await ApiClient.GetTorrentPeersData(Hash, _requestId);
}
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden)
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden || exception.StatusCode == HttpStatusCode.NotFound)
{
_timerCancellationToken.CancelIfNotDisposed();
return;

View File

@@ -2,8 +2,8 @@
using Lantean.QBTMudBlade.Interop;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MudBlazor.Services;
using MudBlazor;
using MudBlazor.Services;
namespace Lantean.QBTMudBlade.Components
{
@@ -25,7 +25,7 @@ namespace Lantean.QBTMudBlade.Components
[EditorRequired]
public IReadOnlyList<PieceState> Pieces { get; set; } = [];
[CascadingParameter(Name = "IsDarkMode")]
[CascadingParameter(Name = "IsDarkMode")]
public bool IsDarkMode { get; set; }
[CascadingParameter]
@@ -100,4 +100,4 @@ namespace Lantean.QBTMudBlade.Components
GC.SuppressFinalize(this);
}
}
}
}

View File

@@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Components;
using MudBlazor;
using MudBlazor.Utilities;
using static MudBlazor.CategoryTypes;
namespace Lantean.QBTMudBlade.Components
{
@@ -54,7 +53,6 @@ namespace Lantean.QBTMudBlade.Components
return;
}
SortDirection sortDirection;
switch (SortDirection)
{

View File

@@ -4,7 +4,6 @@ using Lantean.QBTMudBlade.Interop;
using Lantean.QBTMudBlade.Models;
using Lantean.QBTMudBlade.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.JSInterop;
using MudBlazor;
@@ -207,7 +206,7 @@ namespace Lantean.QBTMudBlade.Components
{
{ nameof(ManageTagsDialog.Hashes), Hashes }
};
await DialogService.ShowAsync<ManageTagsDialog>("Manage Torrent Tags", parameters, DialogHelper.FormDialogOptions);
}
@@ -327,22 +326,27 @@ namespace Lantean.QBTMudBlade.Components
/// Renders toolbar contents without the <see cref="MudToolBar"/> wrapper.
/// </summary>
ToolbarContents,
/// <summary>
/// Renders a <see cref="MudToolBar"/>.
/// </summary>
Toolbar,
/// <summary>
/// Renders a <see cref="MudMenu"/>.
/// </summary>
Menu,
/// <summary>
/// Renders a <see cref="MudToolBar"/> with <see cref="MudIconButton"/> for basic actions and a <see cref="MudMenu"/> for actions with children.
/// </summary>
MixedToolbarContents,
/// <summary>
/// Renders toolbar contents without the <see cref="MudToolBar"/> wrapper with <see cref="MudIconButton"/> for basic actions and a <see cref="MudMenu"/> for actions with children.
/// </summary>
MixedToolbar,
InitialIconsOnly,
Children,
}

View File

@@ -24,4 +24,4 @@ namespace Lantean.QBTMudBlade.Components
return torrent;
}
}
}
}

View File

@@ -59,7 +59,7 @@ namespace Lantean.QBTMudBlade.Components
{
Trackers = await ApiClient.GetTorrentTrackers(Hash);
}
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden)
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden || exception.StatusCode == HttpStatusCode.NotFound)
{
_timerCancellationToken.CancelIfNotDisposed();
return;

View File

@@ -65,7 +65,7 @@ namespace Lantean.QBTMudBlade.Components
{
WebSeeds = await ApiClient.GetTorrentWebSeeds(Hash);
}
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden)
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden || exception.StatusCode == HttpStatusCode.NotFound)
{
_timerCancellationToken.CancelIfNotDisposed();
return;

View File

@@ -4,7 +4,6 @@ using Lantean.QBTMudBlade.Components.Dialogs;
using Lantean.QBTMudBlade.Filter;
using Lantean.QBTMudBlade.Models;
using MudBlazor;
using System.Collections.Generic;
namespace Lantean.QBTMudBlade
{
@@ -265,7 +264,7 @@ namespace Lantean.QBTMudBlade
return default;
}
return ((HashSet<string>, Dictionary<string, int?>))result.Data;
return ((HashSet<string>, Dictionary<string, int?>))result.Data;
}
public static async Task InvokeRssRulesDialog(this IDialogService dialogService)
@@ -286,4 +285,4 @@ namespace Lantean.QBTMudBlade
await dialogService.ShowAsync<SubMenuDialog>(parent.Name, parameters, FormDialogOptions);
}
}
}
}

View File

@@ -2,7 +2,6 @@
using Lantean.QBTMudBlade.Models;
using MudBlazor;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
namespace Lantean.QBTMudBlade
@@ -341,32 +340,43 @@ namespace Lantean.QBTMudBlade
case "forcedMetaDL":
case "downloading":
return (Icons.Material.Filled.Downloading, Color.Success);
case "forcedUP":
case "uploading":
return (Icons.Material.Filled.Upload, Color.Info);
case "stalledUP":
return (Icons.Material.Filled.KeyboardDoubleArrowUp, Color.Info);
case "stalledDL":
return (Icons.Material.Filled.KeyboardDoubleArrowDown, Color.Success);
case "pausedDL":
return (Icons.Material.Filled.Pause, Color.Success);
case "pausedUP":
return (Icons.Material.Filled.Pause, Color.Info);
case "queuedDL":
case "queuedUP":
return (Icons.Material.Filled.Queue, Color.Default);
case "checkingDL":
case "checkingUP":
return (Icons.Material.Filled.Loop, Color.Info);
case "queuedForChecking":
case "checkingResumeData":
return (Icons.Material.Filled.Loop, Color.Warning);
case "moving":
return (Icons.Material.Filled.Moving, Color.Info);
case "error":
case "unknown":
case "missingFiles":
return (Icons.Material.Filled.Error, Color.Error);
default:
return (Icons.Material.Filled.QuestionMark, Color.Warning);
}

View File

@@ -81,7 +81,7 @@ namespace Lantean.QBTMudBlade
var propertyExpression = Expression.Property(parameterExpression, propertyInfo);
var convertExpression = Expression.Convert(propertyExpression, typeof(object));
return (Expression.Lambda<Func<T, object?>>(convertExpression, parameterExpression), propertyInfo.PropertyType);
return (Expression.Lambda<Func<T, object?>>(convertExpression, parameterExpression), propertyInfo.PropertyType);
}
}

View File

@@ -1,5 +1,4 @@
using Lantean.QBTMudBlade;
using Lantean.QBTMudBlade.Models;
using Lantean.QBTMudBlade.Models;
namespace Lantean.QBTMudBlade
{

View File

@@ -41,7 +41,7 @@ namespace Lantean.QBTMudBlade.Filter
propertyExpression.Modify<T>((Expression<Func<object?, bool>>)(x => (string?)x != null && value != null && ((string)x).StartsWith(value, stringComparer))),
FilterOperator.String.EndsWith =>
propertyExpression.Modify<T>((Expression<Func<object?, bool>>)(x => (string?)x != null && value != null && ((string)x).EndsWith(value, stringComparer))),
FilterOperator.String.Empty =>
FilterOperator.String.Empty =>
propertyExpression.Modify<T>((Expression<Func<string?, bool>>)(x => string.IsNullOrWhiteSpace(x))),
FilterOperator.String.NotEmpty =>
propertyExpression.Modify<T>((Expression<Func<string?, bool>>)(x => !string.IsNullOrWhiteSpace(x))),

View File

@@ -171,7 +171,6 @@ namespace Lantean.QBTMudBlade
public static bool FilterStatus(string state, long uploadSpeed, Status status)
{
bool inactive = false;
switch (status)
{

View File

@@ -26,7 +26,7 @@ namespace Lantean.QBTMudBlade.Interop
public static async Task RenderPiecesBar(this IJSRuntime runtime, string id, string hash, int[] pieces, string? downloadingColor = null, string? haveColor = null, string? borderColor = null)
{
await runtime.InvokeVoidAsync("qbt.renderPiecesBar", id, hash, pieces, downloadingColor, haveColor, borderColor );
await runtime.InvokeVoidAsync("qbt.renderPiecesBar", id, hash, pieces, downloadingColor, haveColor, borderColor);
}
}
}

View File

@@ -18,7 +18,6 @@ namespace Lantean.QBTMudBlade.Layout
[CascadingParameter(Name = "SortDirection")]
public SortDirection SortDirection { get; set; }
protected string? SelectedTorrent { get; set; }
protected override void OnParametersSet()
@@ -34,4 +33,4 @@ namespace Lantean.QBTMudBlade.Layout
}
}
}
}
}

View File

@@ -23,4 +23,4 @@ namespace Lantean.QBTMudBlade.Layout
[CascadingParameter(Name = "SearchTermChanged")]
public EventCallback<string> SearchTermChanged { get; set; }
}
}
}

View File

@@ -21,7 +21,7 @@ namespace Lantean.QBTMudBlade.Models
Index = index;
Priority = priority;
Progress = progress;
Size = size;
Size = priority == Priority.DoNotDownload ? 0 : size;
Availability = availability;
IsFolder = isFolder;
Level = level;

View File

@@ -32,11 +32,11 @@ namespace Lantean.QBTMudBlade.Pages
NavigationManager.NavigateTo("/");
}
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.BadRequest)
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.BadRequest)
{
ApiError = "Invalid username or password.";
}
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden)
{
ApiError = "Requests from this client are currently unavailable.";
}
@@ -47,10 +47,12 @@ namespace Lantean.QBTMudBlade.Pages
}
#if DEBUG
protected override async Task OnInitializedAsync()
{
await DoLogin("admin", "23mIDZhvT");
}
#endif
}

View File

@@ -129,6 +129,4 @@ namespace Lantean.QBTMudBlade.Pages
UpdatePreferences = null;
}
}
}
}

View File

@@ -1,10 +1,9 @@
using Blazored.LocalStorage;
using Lantean.QBitTorrentClient;
using Lantean.QBTMudBlade.Services;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MudBlazor.Services;
using Blazored;
using Blazored.LocalStorage;
namespace Lantean.QBTMudBlade
{
@@ -52,4 +51,4 @@ namespace Lantean.QBTMudBlade
await builder.Build().RunAsync();
}
}
}
}

View File

@@ -28,4 +28,4 @@
}
}
}
}
}

View File

@@ -16,4 +16,4 @@ namespace Lantean.QBTMudBlade.Services
await _jSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text);
}
}
}
}

View File

@@ -615,7 +615,6 @@ namespace Lantean.QBTMudBlade.Services
downloaded = downloadingContents.Sum(c => c.Value.Downloaded);
progress = (float)downloaded / size;
}
if (!contents.TryGetValue(key, out var dir))
{

View File

@@ -46,4 +46,4 @@ namespace Lantean.QBTMudBlade.Services
elapsed.TotalMilliseconds.ToString("F1"));
}
}
}
}

View File

@@ -4,4 +4,4 @@
{
Task WriteToClipboard(string text);
}
}
}

View File

@@ -85,9 +85,9 @@ code {
padding-bottom: 0 !important;
}
.table-progress .progress-expand {
height: 28px !important;
}
.table-progress .progress-expand {
height: 28px !important;
}
td.no-wrap {
white-space: nowrap; /* Prevent text from wrapping to the next line */
@@ -109,7 +109,6 @@ td.no-wrap {
}
.field-switch {
}
.piecesbarWrapper {

View File

@@ -49,6 +49,6 @@ window.qbt.renderPiecesBar = (id, hash, pieces, downloadingColor, haveColor, bor
const el = window.qbt.piecesBar.createElement();
parentElement.appendChild(el);
}
window.qbt.piecesBar.setPieces(pieces);
}

View File

@@ -44,7 +44,6 @@ class PiecesBar {
MAX_CANVAS_WIDTH = 4096;
constructor(pieces, parameters) {
this.id = 'piecesbar_' + (window.qbt.piecesBarUniqueId++);
this.width = 0;
this.height = 0;
@@ -270,4 +269,4 @@ class PiecesBar {
window.qbt.PiecesBar = PiecesBar;
Object.freeze(window.qbt.PiecesBar);
Object.freeze(window.qbt.PiecesBar);

View File

@@ -1,5 +1,4 @@
using Lantean.QBitTorrentClient.Models;
using System;
using System.Net;
using System.Net.Http.Json;
using System.Text.Json;

View File

@@ -120,7 +120,6 @@ namespace Lantean.QBitTorrentClient
{
return apiClient.AddTorrentTags([tag], null, hashes.ToArray());
}
public static Task RecheckTorrent(this IApiClient apiClient, string hash)
{

View File

@@ -12,4 +12,4 @@
return httpClient.GetAsync($"{requestUrl}{builder.ToQueryString()}");
}
}
}
}

View File

@@ -1,5 +1,4 @@

namespace Lantean.QBitTorrentClient.Models
namespace Lantean.QBitTorrentClient.Models
{
public class SaveLocation
{
@@ -79,4 +78,4 @@ namespace Lantean.QBitTorrentClient.Models
return ToValue().ToString();
}
}
}
}