Skip to content

Commit

Permalink
code cleanup (issues reported by sonarlint)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankhale committed Aug 27, 2020
1 parent 9e15848 commit bb44c00
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 31 deletions.
9 changes: 2 additions & 7 deletions server/Components/CommandInput.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,16 @@ private async Task<SearchResult> CreateResult<T>(SearchResultType type, Message
return result;
}

private async void OnKeyPress(string key)
private async Task OnKeyPress(string key)
{
static bool MatchesCommandList(string value, params string[] commands) => commands.Where(x => x == value).FirstOrDefault() != null;
static bool MatchesCommandList(string value, params string[] commands) => commands.FirstOrDefault(x => x == value) != null;

if (key == "Enter" && !string.IsNullOrEmpty(SearchTerm))
{
var searchValue = SearchTerm.ToLower().Split(new char[] { ' ' }, 2);

var result = searchValue switch
{
//_ when MatchesCommandList(searchValue[0], "/t", "/test") =>
// CreateResult(SearchResultType.Command,
// () => {
// return new Message() { Value = "This is a test message...", Type = "alert-warning" };
// }),
_ when MatchesCommandList(searchValue[0], "/clear") => CreateResult(SearchResultType.Search, new List<Video>()),
_ when MatchesCommandList(searchValue[0], "/mg", "/manage") => CreateResult(SearchResultType.Manage, await videos.AllVideosAsync()),
_ when MatchesCommandList(searchValue[0], "/mgg", "/manage-groups") => CreateResult(SearchResultType.ManageGroups, await videos.AllGroupsAsync()),
Expand Down
5 changes: 2 additions & 3 deletions server/Components/GroupManagement.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void OnCheckboxClicked(string name, object checkedValue)
}
}

DeleteButtonDisabled = (GroupsToDelete.Count > 0) ? false : true;
DeleteButtonDisabled = GroupsToDelete.Count <= 0;
}

private async Task OnDeleteButtonClicked()
Expand Down Expand Up @@ -101,8 +101,7 @@ private async Task OnDeleteButtonClicked()
private async Task OnAddButtonClicked()
{
await videos.AddGroupAsync(SearchTerm);
Groups = await videos.AllGroupsAsync();
// FIXME: This is not working, boo! Can't bind value and do on-input stupid fucking this doesn't work...!!!?!?!?!?!?!?!
Groups = await videos.AllGroupsAsync();
SearchTerm = string.Empty;
await OnSearchTermChanged(new ChangeEventArgs() { Value = String.Empty });
}
Expand Down
2 changes: 1 addition & 1 deletion server/Components/Notification.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private async Task CallClose()
await OnClose.InvokeAsync(null);
}

private async void OnCloseButtonClick()
private async Task OnCloseButtonClick()
{
await CallClose();
}
Expand Down
13 changes: 2 additions & 11 deletions server/Components/VideoPagination.razor.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using Google.Apis.YouTube.v3.Data;
using Microsoft.AspNetCore.Components;
using System;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TobyBlazor.Data;
using TobyBlazor.Models;
using TobyBlazor.Other;

namespace TobyBlazor.Components
Expand Down Expand Up @@ -74,17 +71,11 @@ private async Task InitializePages(bool resetCurrentPage = false)
}

TogglePrevNextButtonsDisabled();

//Console.WriteLine("Total Videos = {0}", Videos.Count);
//Console.WriteLine("Total Pages = {0}", Pages.Count);
//Console.WriteLine("Total Page Indicies = {0}", PageIndices.Count);
//Console.WriteLine("Total Link Pages = {0}", Pages.Count / ChunkSize);
//Console.WriteLine("Total Links Left Over = {0}", Pages.Count % ChunkSize);
}

private void TogglePrevNextButtonsDisabled()
{
PreviousButtonDisabled = CurrentPageLinkPage != 1 ? false : true;
PreviousButtonDisabled = CurrentPageLinkPage == 1;
NextButtonDisabled = CurrentPageLinkPage >= PageIndices.Count;
}

Expand Down
2 changes: 1 addition & 1 deletion server/Components/VideoPopup.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<bool> IsAddedToFavorites(Video video)
return true;
}

public async void OnModalCloseClicked()
public async Task OnModalCloseClicked()
{
await JSRuntime.InvokeVoidAsync("closeModal", "ytModal");
await OnPopupClosed.InvokeAsync(EventCallback.Empty);
Expand Down
11 changes: 4 additions & 7 deletions server/Data/VideoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,10 @@ public async Task UpdateVideoGroupAsync(string ytid, string group)
{
var foundVideo = await db.Videos.Where(x => x.YTId == ytid && x.Group != "Recently Played").FirstOrDefaultAsync();

if (foundVideo != null)
if (foundVideo != null && !string.IsNullOrEmpty(group))
{
if (!String.IsNullOrEmpty(group))
{
foundVideo.Group = group;
await db.SaveChangesAsync();
}
foundVideo.Group = group;
await db.SaveChangesAsync();
}
}
#endregion
Expand Down Expand Up @@ -306,7 +303,7 @@ public async Task SetCurrentVideoPage(bool recentlyPlayed, int page, int linkPag
}
else
{
if (recentlyPlayed)
if (recentlyPlayed)
{
preferences.CurrentRecentlyPlayedVideoPage = page;
}
Expand Down
2 changes: 1 addition & 1 deletion server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace TobyBlazor
{
public class Program
public static class Program
{
public static void Main(string[] args)
{
Expand Down
Binary file modified server/videos.db
Binary file not shown.

0 comments on commit bb44c00

Please sign in to comment.