From 3117623f3000eed03ec7828c3ed112bd67366620 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis <vaartis@kotobank.ch>
Date: Mon, 16 Aug 2021 21:30:07 +0300
Subject: Implement loading more statuses when searching

---
 src/components/search/search.vue | 40 +++++++++++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 7 deletions(-)

(limited to 'src/components/search/search.vue')

diff --git a/src/components/search/search.vue b/src/components/search/search.vue
index b7bfc1f3..5d8a6715 100644
--- a/src/components/search/search.vue
+++ b/src/components/search/search.vue
@@ -55,12 +55,6 @@
     </div>
     <div class="panel-body">
       <div v-if="currenResultTab === 'statuses'">
-        <div
-          v-if="visibleStatuses.length === 0 && !loading && loaded"
-          class="search-result-heading"
-        >
-          <h4>{{ $t('search.no_results') }}</h4>
-        </div>
         <Status
           v-for="status in visibleStatuses"
           :key="status.id"
@@ -71,6 +65,33 @@
           :statusoid="status"
           :no-heading="false"
         />
+        <button
+          v-if="!loading && loaded && lastStatusFetchCount > 0"
+          class="more-statuses-button button-unstyled -link -fullwidth"
+          @click.prevent="search(searchTerm)"
+        >
+          <div class="new-status-notification text-center">
+            {{ $t('search.load_more') }}
+          </div>
+        </button>
+        <div
+          v-else-if="loading && statusesOffset > 0"
+          class="text-center loading-icon"
+        >
+          <FAIcon
+            icon="circle-notch"
+            spin
+            size="lg"
+          />
+        </div>
+        <div
+          v-if="(visibleStatuses.length === 0 || lastStatusFetchCount === 0) && !loading && loaded"
+          class="search-result-heading"
+        >
+          <h4>
+            {{ $t('search.no_results') }}
+          </h4>
+        </div>
       </div>
       <div v-else-if="currenResultTab === 'people'">
         <div
@@ -208,6 +229,11 @@
     color: $fallback--text;
     color: var(--text, $fallback--text);
   }
-}
+  }
+
+  .more-statuses-button {
+    height: 3.5em;
+    line-height: 3.5em;
+  }
 
 </style>
-- 
cgit v1.2.3-70-g09d2


From ca7fa67997de81710f96944ccdbd080dcd3b0bf9 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis <vaartis@kotobank.ch>
Date: Sun, 22 Aug 2021 15:36:03 +0300
Subject: Amend status search results, and introduce searchType

Use searchType to only search for statuses when searching for more results
---
 src/components/search/search.js  | 16 ++++++++++------
 src/components/search/search.vue |  2 +-
 2 files changed, 11 insertions(+), 7 deletions(-)

(limited to 'src/components/search/search.vue')

diff --git a/src/components/search/search.js b/src/components/search/search.js
index 6347febf..751a9c37 100644
--- a/src/components/search/search.js
+++ b/src/components/search/search.js
@@ -63,28 +63,32 @@ const Search = {
       this.$router.push({ name: 'search', query: { query } })
       this.$refs.searchInput.focus()
     },
-    search (query) {
+    search (query, searchType = null) {
       if (!query) {
         this.loading = false
         return
       }
 
       this.loading = true
-      this.userIds = []
-      this.hashtags = []
       this.$refs.searchInput.blur()
       if (this.lastQuery !== query) {
+        this.userIds = []
+        this.hashtags = []
         this.statuses = []
+
         this.statusesOffset = 0
         this.lastStatusFetchCount = 0
       }
 
-      this.$store.dispatch('search', { q: query, resolve: true, offset: this.statusesOffset })
+      this.$store.dispatch('search', { q: query, resolve: true, offset: this.statusesOffset, 'type': searchType })
         .then(data => {
           this.loading = false
-          this.userIds = map(data.accounts, 'id')
+
+          // Always append to old results. If new results are empty, this doesn't change anything
+          this.userIds = this.userIds.concat(map(data.accounts, 'id'))
           this.statuses = this.statuses.concat(data.statuses)
-          this.hashtags = data.hashtags
+          this.hashtags = this.hashtags.concat(data.hashtags)
+
           this.currenResultTab = this.getActiveTab()
           this.loaded = true
 
diff --git a/src/components/search/search.vue b/src/components/search/search.vue
index 5d8a6715..f3076f65 100644
--- a/src/components/search/search.vue
+++ b/src/components/search/search.vue
@@ -68,7 +68,7 @@
         <button
           v-if="!loading && loaded && lastStatusFetchCount > 0"
           class="more-statuses-button button-unstyled -link -fullwidth"
-          @click.prevent="search(searchTerm)"
+          @click.prevent="search(searchTerm, 'statuses')"
         >
           <div class="new-status-notification text-center">
             {{ $t('search.load_more') }}
-- 
cgit v1.2.3-70-g09d2


From b247a917241cd62f1f5f02c5f8c1fab67421f2a9 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis <vaartis@kotobank.ch>
Date: Sun, 22 Aug 2021 16:12:36 +0300
Subject: Ensure uniqueness of found statuses & ensure only one loading circle

---
 src/components/search/search.js  | 11 ++++++++---
 src/components/search/search.vue |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)

(limited to 'src/components/search/search.vue')

diff --git a/src/components/search/search.js b/src/components/search/search.js
index 751a9c37..7f64b0f7 100644
--- a/src/components/search/search.js
+++ b/src/components/search/search.js
@@ -7,6 +7,7 @@ import {
   faCircleNotch,
   faSearch
 } from '@fortawesome/free-solid-svg-icons'
+import { uniqBy } from 'lodash'
 
 library.add(
   faCircleNotch,
@@ -84,16 +85,20 @@ const Search = {
         .then(data => {
           this.loading = false
 
+          let oldLength = this.statuses.length
+
           // Always append to old results. If new results are empty, this doesn't change anything
           this.userIds = this.userIds.concat(map(data.accounts, 'id'))
-          this.statuses = this.statuses.concat(data.statuses)
+          this.statuses = uniqBy(this.statuses.concat(data.statuses), 'id')
           this.hashtags = this.hashtags.concat(data.hashtags)
 
           this.currenResultTab = this.getActiveTab()
           this.loaded = true
 
-          this.statusesOffset += data.statuses.length
-          this.lastStatusFetchCount = data.statuses.length
+          // Offset from whatever we already have
+          this.statusesOffset = this.statuses.length
+          // Because the amount of new statuses can actually be zero, compare to old lenght instead
+          this.lastStatusFetchCount = this.statuses.length - oldLength
           this.lastQuery = query
         })
     },
diff --git a/src/components/search/search.vue b/src/components/search/search.vue
index f3076f65..4373a94b 100644
--- a/src/components/search/search.vue
+++ b/src/components/search/search.vue
@@ -22,7 +22,7 @@
       </button>
     </div>
     <div
-      v-if="loading"
+      v-if="loading && statusesOffset == 0"
       class="text-center loading-icon"
     >
       <FAIcon
-- 
cgit v1.2.3-70-g09d2


From b09912d2f91a410a3b50ee408dd4a0621eba2ff4 Mon Sep 17 00:00:00 2001
From: Tusooa Zhu <tusooa@kazv.moe>
Date: Fri, 15 Jul 2022 20:26:05 -0400
Subject: Make search say No more results when there are current results

---
 src/components/search/search.vue | 2 +-
 src/i18n/en.json                 | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

(limited to 'src/components/search/search.vue')

diff --git a/src/components/search/search.vue b/src/components/search/search.vue
index 4373a94b..6fc6a0de 100644
--- a/src/components/search/search.vue
+++ b/src/components/search/search.vue
@@ -89,7 +89,7 @@
           class="search-result-heading"
         >
           <h4>
-            {{ $t('search.no_results') }}
+            {{ visibleStatuses.length === 0 ? $t('search.no_results') : $t('search.no_more_results') }}
           </h4>
         </div>
       </div>
diff --git a/src/i18n/en.json b/src/i18n/en.json
index 6026b33e..167a3e0f 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -828,6 +828,7 @@
     "person_talking": "{count} person talking",
     "people_talking": "{count} people talking",
     "no_results": "No results",
+    "no_more_results": "No more results",
     "load_more": "Load more results"
   },
   "password_reset": {
-- 
cgit v1.2.3-70-g09d2

