mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-06 00:05:30 +00:00
Merge pull request #8142 from qhmhyp/fix/account-filter-persistence
fix(accounts): persist platform and status filters
This commit is contained in:
1 file changed
+39
-2
@@ -496,6 +496,7 @@ import { useI18n } from 'vue-i18n'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { adminAPI } from '@/api/admin'
|
||||
import { CONCRETE_PLATFORM_OPTIONS } from '@/constants/platforms'
|
||||
import { useTableLoader } from '@/composables/useTableLoader'
|
||||
import { useSwipeSelect, type SwipeSelectVirtualContext } from '@/composables/useSwipeSelect'
|
||||
import { useTableSelection } from '@/composables/useTableSelection'
|
||||
@@ -653,6 +654,31 @@ const HIDDEN_COLUMNS_KEY = 'account-hidden-columns'
|
||||
const HIDDEN_COLUMNS_VERSION_KEY = 'account-hidden-columns-version'
|
||||
const HIDDEN_COLUMNS_CURRENT_VERSION = 'scheduler-score-hidden-by-default'
|
||||
|
||||
// Account filter settings
|
||||
const ACCOUNT_FILTER_STORAGE_KEY = 'account-filter-values'
|
||||
type AccountFilterValues = {
|
||||
platform: string
|
||||
status: string
|
||||
}
|
||||
const loadInitialAccountFilterValues = (): AccountFilterValues => {
|
||||
const fallback: AccountFilterValues = { platform: '', status: '' }
|
||||
try {
|
||||
const raw = localStorage.getItem(ACCOUNT_FILTER_STORAGE_KEY)
|
||||
if (!raw) return fallback
|
||||
const parsed: unknown = JSON.parse(raw)
|
||||
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) return fallback
|
||||
const values = parsed as Record<string, unknown>
|
||||
return {
|
||||
platform: typeof values.platform === 'string' && CONCRETE_PLATFORM_OPTIONS.some(option => option.value === values.platform)
|
||||
? values.platform : '',
|
||||
status: typeof values.status === 'string' && ['active', 'inactive', 'error', 'rate_limited', 'temp_unschedulable', 'unschedulable'].includes(values.status)
|
||||
? values.status : ''
|
||||
}
|
||||
} catch {
|
||||
return fallback
|
||||
}
|
||||
}
|
||||
|
||||
// Sorting settings
|
||||
const ACCOUNT_SORT_STORAGE_KEY = 'account-table-sort'
|
||||
type AccountSortOrder = 'asc' | 'desc'
|
||||
@@ -1084,9 +1110,8 @@ const {
|
||||
} = useTableLoader<AccountListItem, any>({
|
||||
fetchFn: adminAPI.accounts.list,
|
||||
initialParams: {
|
||||
platform: '',
|
||||
...loadInitialAccountFilterValues(),
|
||||
type: '',
|
||||
status: '',
|
||||
privacy_mode: '',
|
||||
group: '',
|
||||
search: '',
|
||||
@@ -1292,7 +1317,19 @@ const refreshUpstreamBillingSortedList = async (force = false) => {
|
||||
|
||||
useIntervalFn(() => { void refreshUpstreamBillingRates() }, 5 * 60_000, { immediate: false })
|
||||
|
||||
const saveAccountFilterValues = () => {
|
||||
try {
|
||||
localStorage.setItem(ACCOUNT_FILTER_STORAGE_KEY, JSON.stringify({
|
||||
platform: params.platform,
|
||||
status: params.status
|
||||
}))
|
||||
} catch {
|
||||
// Filtering must remain available when browser storage is unavailable.
|
||||
}
|
||||
}
|
||||
|
||||
const debouncedReload = () => {
|
||||
saveAccountFilterValues()
|
||||
clearSelection()
|
||||
syncAccountListDerivedParams()
|
||||
hasPendingListSync.value = false
|
||||
|
||||
Reference in new issue
Block a user