From a4915a65018cea8a2949d94edc5e199e138b4d26 Mon Sep 17 00:00:00 2001 From: itepechi <72330683+itepechi@users.noreply.github.com> Date: Sun, 17 Sep 2023 05:50:09 +0900 Subject: [PATCH] Please don't switch tabs left and right when searching --- src/components/search/search.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/components/search/search.js b/src/components/search/search.js index 710e04a5..c6640d27 100644 --- a/src/components/search/search.js +++ b/src/components/search/search.js @@ -36,6 +36,7 @@ const Search = { media: [], hashtags: [], currenResultTab: 'statuses', + preferredTab : 'statuses', statusesOffset: 0, lastStatusFetchCount: 0, @@ -162,17 +163,26 @@ const Search = { }, onResultTabSwitch (key) { this.currenResultTab = key + this.preferredTab = key this.loading = false }, getActiveTab () { - if (this.visibleStatuses.length > 0) { - return 'statuses' - } else if (this.visibleMedia.length > 0) { - return 'media' - } else if (this.users.length > 0) { - return 'people' - } else if (this.hashtags.length > 0) { - return 'hashtags' + const available = { + statuses: this.visibleStatuses.length > 0, + media: this.visibleMedia.length > 0, + people: this.users.length > 0, + hashtags: this.hashtags.length > 0, + } + + if (available[this.preferredTab]) { + return this.preferredTab + } + + const tabOrder = ['statuses', 'media', 'people', 'hashtags'] + for (const tab of tabOrder) { + if (available[tab]) { + return tab + } } return 'statuses'