Skip to content

Commit

Permalink
Implementiran delay prema PR prijedlogu
Browse files Browse the repository at this point in the history
  • Loading branch information
vlovric21 committed Jun 15, 2024
1 parent 4b70bdd commit e8ea20d
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion Software/E_Libra/PresentationLayer/UcAddNewBook.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace PresentationLayer
{
//Viktor Lovrić
public partial class UcAddNewBook : UserControl
{
string checkboxValue;
private DispatcherTimer genreSearchTimer = new DispatcherTimer();
private DispatcherTimer authorSearchTimer = new DispatcherTimer();
public UcAddNewBook()
{
InitializeComponent();

genreSearchTimer.Interval = TimeSpan.FromMilliseconds(300);
genreSearchTimer.Tick += GenreSearchTimer_Tick;

authorSearchTimer.Interval = TimeSpan.FromMilliseconds(500);
authorSearchTimer.Tick += AuthorSearchTimer_Tick;
}

private void btnCancel_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -218,6 +227,30 @@ private void UcNewGenre_ButtonClicked(object sender, EventArgs e)
}

private void txtSearchGenre_TextChanged(object sender, TextChangedEventArgs e)
{
genreSearchTimer.Stop();
genreSearchTimer.Start();
}

private void txtSearchAuthor_TextChanged(object sender, TextChangedEventArgs e)
{
authorSearchTimer.Stop();
authorSearchTimer.Start();
}

private void GenreSearchTimer_Tick(object sender, EventArgs e)
{
genreSearchTimer.Stop();
FilterGenres();
}

private void AuthorSearchTimer_Tick(object sender, EventArgs e)
{
authorSearchTimer.Stop();
FilterAuthors();
}

private void FilterGenres()
{
string search = txtSearchGenre.Text;
if (string.IsNullOrEmpty(search))
Expand All @@ -231,7 +264,7 @@ private void txtSearchGenre_TextChanged(object sender, TextChangedEventArgs e)
}
}

private void txtSearchAuthor_TextChanged(object sender, TextChangedEventArgs e)
private void FilterAuthors()
{
string search = txtSearchAuthor.Text;
if (string.IsNullOrEmpty(search))
Expand All @@ -244,5 +277,6 @@ private void txtSearchAuthor_TextChanged(object sender, TextChangedEventArgs e)
cmbAuthor.ItemsSource = authorService.SearchAuthors(search);
}
}

}
}

0 comments on commit e8ea20d

Please sign in to comment.