mirror of
https://github.com/m1ngsama/FUJI.git
synced 2025-12-24 10:51:27 +00:00
feat: add URL query params for page and status filter in repair admin
- Initialize page and statusFilter from URL query parameters on mount - Update URL when page or statusFilter state changes - Support comma-separated status values in URL - Enables sharing specific page/filter state via URL - Preserves state on page refresh
This commit is contained in:
parent
f767fce6ef
commit
96964f4f00
1 changed files with 30 additions and 4 deletions
|
|
@ -188,12 +188,27 @@ export const validateRepairRole = (roles: string[]) => {
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
const [page, setPage] = useState(1)
|
|
||||||
|
// Initialize state from URL query params
|
||||||
|
const getInitialPage = () => {
|
||||||
|
const params = new URLSearchParams(window.location.search)
|
||||||
|
const pageParam = params.get('page')
|
||||||
|
return pageParam ? parseInt(pageParam, 10) : 1
|
||||||
|
}
|
||||||
|
|
||||||
|
const getInitialStatusFilter = () => {
|
||||||
|
const params = new URLSearchParams(window.location.search)
|
||||||
|
const statusParam = params.get('status')
|
||||||
|
if (statusParam) {
|
||||||
|
return statusParam.split(',').filter(Boolean)
|
||||||
|
}
|
||||||
|
return UserEventStatus.filter(v => v.status !== EventStatus.cancelled).map(v => v.status)
|
||||||
|
}
|
||||||
|
|
||||||
|
const [page, setPage] = useState(getInitialPage())
|
||||||
const rowsPerPage = 10
|
const rowsPerPage = 10
|
||||||
const [totalCount, setTotalCount] = useState(0)
|
const [totalCount, setTotalCount] = useState(0)
|
||||||
const [statusFilter, setStatusFilter] = useState<string[]>(
|
const [statusFilter, setStatusFilter] = useState<string[]>(getInitialStatusFilter())
|
||||||
UserEventStatus.filter(v => v.status !== EventStatus.cancelled).map(v => v.status),
|
|
||||||
)
|
|
||||||
const { isOpen, onOpen, onOpenChange } = useDisclosure()
|
const { isOpen, onOpen, onOpenChange } = useDisclosure()
|
||||||
const [userInfo, setUserInfo] = useState<UserInfoResponse>()
|
const [userInfo, setUserInfo] = useState<UserInfoResponse>()
|
||||||
const [currentMember, setCurrentMember] = useState<PublicMember>()
|
const [currentMember, setCurrentMember] = useState<PublicMember>()
|
||||||
|
|
@ -282,6 +297,17 @@ export default function App() {
|
||||||
return Math.ceil(totalCount / rowsPerPage)
|
return Math.ceil(totalCount / rowsPerPage)
|
||||||
}, [totalCount, rowsPerPage])
|
}, [totalCount, rowsPerPage])
|
||||||
|
|
||||||
|
// Update URL query params when page or statusFilter changes
|
||||||
|
useEffect(() => {
|
||||||
|
const params = new URLSearchParams()
|
||||||
|
params.set('page', page.toString())
|
||||||
|
if (statusFilter.length > 0) {
|
||||||
|
params.set('status', statusFilter.join(','))
|
||||||
|
}
|
||||||
|
const newUrl = `${window.location.pathname}?${params.toString()}`
|
||||||
|
window.history.replaceState({}, '', newUrl)
|
||||||
|
}, [page, statusFilter])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPage(1)
|
setPage(1)
|
||||||
list.reload()
|
list.reload()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue