Please don't switch tabs left and right when searching

This commit is contained in:
itepechi 2023-09-17 05:50:09 +09:00
parent 7042d0f4b6
commit a4915a6501
1 changed files with 18 additions and 8 deletions

View File

@ -36,6 +36,7 @@ const Search = {
media: [], media: [],
hashtags: [], hashtags: [],
currenResultTab: 'statuses', currenResultTab: 'statuses',
preferredTab : 'statuses',
statusesOffset: 0, statusesOffset: 0,
lastStatusFetchCount: 0, lastStatusFetchCount: 0,
@ -162,17 +163,26 @@ const Search = {
}, },
onResultTabSwitch (key) { onResultTabSwitch (key) {
this.currenResultTab = key this.currenResultTab = key
this.preferredTab = key
this.loading = false this.loading = false
}, },
getActiveTab () { getActiveTab () {
if (this.visibleStatuses.length > 0) { const available = {
return 'statuses' statuses: this.visibleStatuses.length > 0,
} else if (this.visibleMedia.length > 0) { media: this.visibleMedia.length > 0,
return 'media' people: this.users.length > 0,
} else if (this.users.length > 0) { hashtags: this.hashtags.length > 0,
return 'people' }
} else if (this.hashtags.length > 0) {
return 'hashtags' 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' return 'statuses'