mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Fix navigation inside tabs with a tableview replacing all query param… (#1218)
* fix navigation inside tabs with a tableview replacing all query params in url * fix copilot suggested issues relating to encoding urls
This commit is contained in:
@@ -419,7 +419,11 @@ export const TableView = <T extends MRT_RowData>({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildTableStateUrl = () => `${location.pathname}?${TABLE_STATE_URL_PARAM}=${encodeURIComponent(tableStateId)}`
|
const buildTableStateUrl = () => {
|
||||||
|
const params = new URLSearchParams(location.search)
|
||||||
|
params.set(TABLE_STATE_URL_PARAM, tableStateId)
|
||||||
|
return `${location.pathname}?${params.toString()}`
|
||||||
|
}
|
||||||
|
|
||||||
const loadStateFromUrl = <TState extends MRT_ColumnFiltersState | MRT_SortingState | MRT_PaginationState>(
|
const loadStateFromUrl = <TState extends MRT_ColumnFiltersState | MRT_SortingState | MRT_PaginationState>(
|
||||||
state: TableStateInUrl,
|
state: TableStateInUrl,
|
||||||
|
|||||||
@@ -18,15 +18,13 @@ export const useSyncTabSearch = (tab: number) => {
|
|||||||
}, [location.key, location.state])
|
}, [location.key, location.state])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const nextSearch = `?tab=${tab}`
|
const params = new URLSearchParams(location.search)
|
||||||
if (location.search === nextSearch) {
|
if (params.get('tab') === String(tab)) return
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
navigate(
|
navigate(
|
||||||
{
|
{
|
||||||
pathname: location.pathname,
|
pathname: location.pathname,
|
||||||
search: nextSearch,
|
search: `?tab=${tab}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
replace: true,
|
replace: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user