mirror of
https://github.com/makeplane/plane.git
synced 2025-12-23 07:09:34 +01:00
[WEB-2293] feat: pages version history (#5417)
* chore: project page version * feat: page version history implemented * chore: hide save button when version history overlay is active * refactor: updated navigation logic * chore: added error states --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
This commit is contained in:
committed by
GitHub
parent
d802316c5c
commit
a0ed51c845
39
web/core/hooks/use-query-params.ts
Normal file
39
web/core/hooks/use-query-params.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { useSearchParams, usePathname } from "next/navigation";
|
||||
|
||||
type TParamsToAdd = {
|
||||
[key: string]: string;
|
||||
};
|
||||
|
||||
export const useQueryParams = () => {
|
||||
// next navigation
|
||||
const searchParams = useSearchParams();
|
||||
const pathname = usePathname();
|
||||
|
||||
const updateQueryParams = ({
|
||||
paramsToAdd = {},
|
||||
paramsToRemove = [],
|
||||
}: {
|
||||
paramsToAdd?: TParamsToAdd;
|
||||
paramsToRemove?: string[];
|
||||
}) => {
|
||||
const currentParams = new URLSearchParams(searchParams.toString());
|
||||
|
||||
// add or update query parameters
|
||||
Object.keys(paramsToAdd).forEach((key) => {
|
||||
currentParams.set(key, paramsToAdd[key]);
|
||||
});
|
||||
|
||||
// remove specified query parameters
|
||||
paramsToRemove.forEach((key) => {
|
||||
currentParams.delete(key);
|
||||
});
|
||||
|
||||
// construct the new route with the updated query parameters
|
||||
const newRoute = `${pathname}?${currentParams.toString()}`;
|
||||
return newRoute;
|
||||
};
|
||||
|
||||
return {
|
||||
updateQueryParams,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user