Skip to content

Commit

Permalink
Only running search after input is finished (#258)
Browse files Browse the repository at this point in the history
* Adding equipment wait timer

* changes to timing for relics

* Removing excessive logging
  • Loading branch information
PKFire813 authored Feb 18, 2023
1 parent 444012f commit 5cb35b9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
30 changes: 27 additions & 3 deletions WFInfo/EquipmentWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Forms;

namespace WFInfo
{
Expand All @@ -16,6 +17,8 @@ public partial class EquipmentWindow : Window
private Dictionary<string, TreeNode> primeTypes;
private bool searchActive = false;
private bool showAllEqmt = false;
private int searchTimerDurationMS = 500;
public static Timer searchTimer = new Timer();
public static string[] searchText;
public static EquipmentWindow INSTANCE;

Expand All @@ -32,7 +35,8 @@ private void Hide(object sender, RoutedEventArgs e)

public void reloadItems()
{
if (primeTypes != null) {
if (primeTypes != null)
{
foreach (TreeNode category in primeTypes.Values)
{
foreach (TreeNode prime in category.Children)
Expand Down Expand Up @@ -201,6 +205,26 @@ private void VaultedClick(object sender, RoutedEventArgs e)
ReapplyFilters();
}

/// <summary>
/// Starts a timer to wait to apply changes to filters on search bar
/// </summary>
private void StartSearchReapplyTimer()
{
if (searchTimer.Enabled)
{
searchTimer.Stop();
}

searchTimer.Interval = searchTimerDurationMS;
searchTimer.Enabled = true;
searchTimer.Tick += (s, e) =>
{
searchTimer.Enabled = false;
searchTimer.Stop();
ReapplyFilters();
};
}

private void TextboxTextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
searchActive = textBox.Text.Length > 0 && textBox.Text != "Filter Terms";
Expand All @@ -212,7 +236,7 @@ private void TextboxTextChanged(object sender, System.Windows.Controls.TextChang
searchText = textBox.Text.Split(' ');
else
searchText = null;
ReapplyFilters();
StartSearchReapplyTimer();
}
}
}
Expand Down Expand Up @@ -343,6 +367,6 @@ private void WindowLoaded(object sender, RoutedEventArgs e)
{
populate();
}

}
}
23 changes: 22 additions & 1 deletion WFInfo/RelicsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Linq;
using System.Windows.Data;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using WebSocketSharp;

Expand All @@ -20,19 +21,39 @@ public RelicsViewModel()

private bool _initialized = false;
private string _filterText = "";
private int searchTimerDurationMS = 500;
private bool _showAllRelics;
private readonly List<TreeNode> _relicTreeItems;
private int _sortBoxSelectedIndex;
private bool _hideVaulted = true;
private readonly List<TreeNode> _rawRelicNodes = new List<TreeNode>();

public static Timer searchTimer = new Timer();

private void StartSearchReapplyTimer()
{
if (searchTimer.Enabled)
{
searchTimer.Stop();
}

searchTimer.Interval = searchTimerDurationMS;
searchTimer.Enabled = true;
searchTimer.Tick += (s, e) =>
{
searchTimer.Enabled = false;
searchTimer.Stop();
ReapplyFilters();
};
}

public string FilterText
{
get => _filterText;
set
{
this.SetField(ref _filterText, value);
ReapplyFilters();
StartSearchReapplyTimer();
RaisePropertyChanged(nameof(IsFilterEmpty));
}
}
Expand Down

0 comments on commit 5cb35b9

Please sign in to comment.