fix(SPA): activity list saves pagination too
This commit is contained in:
1 parent
9d9453c1b3
commit
c41e6dbca5
5 files changed
+193
-4
No files matched your search
@@ -1,12 +1,15 @@
|
||||
import { computed, onBeforeUnmount, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ApiError } from '@/composables/useApi'
|
||||
import { useActivity, type PersonOptions } from '@/composables/useActivity'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
import { ACTIVITY_PAGE_SIZE_KEY, resolvePageSize, storePageSize } from '@/lib/pageSizeMemory'
|
||||
import {
|
||||
activeChips,
|
||||
clearChip,
|
||||
defaultFilters,
|
||||
DEFAULT_PAGE_SIZE,
|
||||
PAGE_SIZES,
|
||||
summaryRangeChanged,
|
||||
type ActivityFilters,
|
||||
type ActivityItem,
|
||||
@@ -45,11 +48,20 @@ function delayedFlag() {
|
||||
|
||||
export function useActivityPage() {
|
||||
const session = useSessionStore()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { listActivity, getSummary, listPeople } = useActivity()
|
||||
|
||||
const filters = ref<ActivityFilters>(defaultFilters())
|
||||
const page = ref(1)
|
||||
const size = ref(DEFAULT_PAGE_SIZE)
|
||||
const size = ref(
|
||||
resolvePageSize(
|
||||
route.query.size,
|
||||
ACTIVITY_PAGE_SIZE_KEY,
|
||||
[...PAGE_SIZES],
|
||||
DEFAULT_PAGE_SIZE,
|
||||
),
|
||||
)
|
||||
const items = ref<ActivityItem[]>([])
|
||||
const total = ref(0)
|
||||
const listState = ref<ListState>('idle')
|
||||
@@ -192,9 +204,20 @@ export function useActivityPage() {
|
||||
fetchPage(next)
|
||||
}
|
||||
|
||||
function syncSizeQuery() {
|
||||
const { size: current, ...rest } = route.query
|
||||
const wanted = size.value === DEFAULT_PAGE_SIZE ? undefined : String(size.value)
|
||||
if (current === wanted) return
|
||||
router.replace({ query: wanted === undefined ? rest : { ...rest, size: wanted } })
|
||||
}
|
||||
|
||||
syncSizeQuery()
|
||||
|
||||
function setSize(next: number) {
|
||||
if (next === size.value) return
|
||||
size.value = next
|
||||
storePageSize(ACTIVITY_PAGE_SIZE_KEY, next)
|
||||
syncSizeQuery()
|
||||
fetchPage(1)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user