From 8cbca8f290192477e46f417caac0be85d2e8e250 Mon Sep 17 00:00:00 2001
From: Tsanie Lily <tsorgy@gmail.com>
Date: Thu, 14 May 2020 23:30:14 +0800
Subject: [PATCH] little adjustment about load more logic

---
 Pixiview/Illust/RelatedIllustsPage.xaml.cs | 18 ++++++++++++++----
 Pixiview/Utils/Stores.cs                   |  6 +++++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/Pixiview/Illust/RelatedIllustsPage.xaml.cs b/Pixiview/Illust/RelatedIllustsPage.xaml.cs
index 84c4da0..d8defd3 100644
--- a/Pixiview/Illust/RelatedIllustsPage.xaml.cs
+++ b/Pixiview/Illust/RelatedIllustsPage.xaml.cs
@@ -9,6 +9,8 @@ namespace Pixiview.Illust
 {
     public partial class RelatedIllustsPage : IllustRecommendsCollectionPage
     {
+        private const int STEP = 18;
+
         private readonly IllustItem illustItem;
         private int startIndex;
         private int nextIndex;
@@ -53,15 +55,16 @@ namespace Pixiview.Illust
                 {
                     return null;
                 }
-                var ids = illustIds.Skip(startIndex).Take(18).ToArray();
-                nextIndex = startIndex + ids.Length;
+                var ids = illustIds.Skip(startIndex).Take(STEP).ToArray();
+                data = Stores.LoadIllustRecommendsListData(illustItem.Id, ids);
+                nextIndex = startIndex + STEP;
                 if (ids.Length == 0 || nextIndex >= illustIds.Length)
                 {
                     // done
+
                     App.DebugPrint($"download completed: {startIndex}");
-                    return null;
+                    startIndex = nextIndex;
                 }
-                data = Stores.LoadIllustRecommendsListData(illustItem.Id, ids);
             }
             return data;
         }
@@ -96,6 +99,13 @@ namespace Pixiview.Illust
             {
                 return;
             }
+            // release
+            var collection = IllustCollection;
+            if (collection != null)
+            {
+                collection.Running = false;
+                IllustCollection = null;
+            }
             startIndex = -1;
             nextIndex = 0;
             illustIds = null;
diff --git a/Pixiview/Utils/Stores.cs b/Pixiview/Utils/Stores.cs
index 266fde4..ecfec5b 100644
--- a/Pixiview/Utils/Stores.cs
+++ b/Pixiview/Utils/Stores.cs
@@ -266,6 +266,10 @@ namespace Pixiview.Utils
 
         public static IllustRecommendsData LoadIllustRecommendsListData(string id, string[] ids)
         {
+            if (ids == null || ids.Length == 0)
+            {
+                return null;
+            }
             var ps = string.Concat(ids.Select(i => $"illust_ids%5B%5D={i}&"));
             var result = HttpUtility.LoadObject<IllustRecommendsData>(
                 null,
@@ -458,7 +462,7 @@ namespace Pixiview.Utils
         public static string UrlIllust => Prefix + "artworks/{0}";
         public static string UrlIllustRanking => Prefix + "ranking.php?{0}";
         public static string UrlIllustUserAll => Prefix + "ajax/user/{0}/profile/all?lang=zh";
-        public static string UrlIllustUserArtworks => Prefix + "ajax/user/{0}/profile/illusts?{1}work_category=illustManga&is_first_page={2}&lang=zh";
+        public static string UrlIllustUserArtworks => Prefix + "ajax/user/{0}/profile/illusts?{1}work_category=illust&is_first_page={2}&lang=zh";
         public static string UrlIllustPage => Prefix + "ajax/illust/{0}/pages?lang=zh";
         public static string UrlIllustUgoira => Prefix + "ajax/illust/{0}/ugoira_meta?lang=zh";
         public static string UrlIllustRecommendsInit => Prefix + "ajax/illust/{0}/recommend/init?limit=18&lang=zh";