Skip to content

Commit

Permalink
Extract common reset code
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Oct 28, 2024
1 parent 98efccf commit 9296394
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions TwitchDownloaderWPF/WindowMassDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class WindowMassDownload : Window
public ObservableCollection<TaskData> videoList { get; set; } = new ObservableCollection<TaskData>();
public readonly List<TaskData> selectedItems = new List<TaskData>();
public readonly List<string> cursorList = new List<string>();
public int cursorIndex = -1;
public int cursorIndex = 0;
public string currentChannel = "";
public string period = "";
public int videoCount = 50;
Expand All @@ -49,12 +49,18 @@ private async void btnChannel_Click(object sender, RoutedEventArgs e)
await ChangeCurrentChannel();
}

private Task ChangeCurrentChannel()
private void ResetLists()
{
currentChannel = textChannel.Text;
videoList.Clear();
cursorList.Clear();
cursorIndex = -1;
cursorList.Add("");
cursorIndex = 0;
}

private Task ChangeCurrentChannel()
{
currentChannel = textChannel.Text;
ResetLists();
return UpdateList();
}

Expand All @@ -69,9 +75,7 @@ private async Task UpdateList()
{
// Pretend we are doing something so the status icon has time to show
await Task.Delay(50);
videoList.Clear();
cursorList.Clear();
cursorIndex = -1;
ResetLists();
StatusImage.Visibility = Visibility.Hidden;
return;
}
Expand Down Expand Up @@ -125,7 +129,7 @@ private async Task UpdateList()
});
}

btnPrev.IsEnabled = res.data.user.videos.pageInfo.hasPreviousPage;
btnPrev.IsEnabled = cursorIndex > 0;
if (res.data.user.videos.pageInfo.hasNextPage)
{
string newCursor = res.data.user.videos.edges.FirstOrDefault()?.cursor;
Expand Down Expand Up @@ -189,7 +193,7 @@ private async Task UpdateList()
});
}

btnPrev.IsEnabled = cursorIndex >= 0;
btnPrev.IsEnabled = cursorIndex > 0;
if (res.data.user.clips.pageInfo.hasNextPage)
{
string newCursor = res.data.user.clips.edges.FirstOrDefault(x => x.cursor != null)?.cursor;
Expand Down Expand Up @@ -278,9 +282,7 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
private async void ComboSortByDate_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
period = ((ComboBoxItem)ComboSortByDate.SelectedItem).Tag.ToString();
videoList.Clear();
cursorList.Clear();
cursorIndex = -1;
ResetLists();
await UpdateList();
}

Expand Down Expand Up @@ -330,9 +332,7 @@ private async void TextChannel_OnKeyDown(object sender, KeyEventArgs e)
private async void ComboVideoCount_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
videoCount = int.Parse((string)((ComboBoxItem)ComboVideoCount.SelectedValue).Content);
videoList.Clear();
cursorList.Clear();
cursorIndex = -1;
ResetLists();
await UpdateList();
}

Expand Down

0 comments on commit 9296394

Please sign in to comment.