Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { usePathname, useSearchParams } from "next/navigation";
import { useI18n } from "@/components/providers/i18n-provider/use-i18n";
import { ALL_FILTER_VALUE, DEFAULT_FILTERS } from "./defaults";
import { buildServerFilters } from "./server-filters";
Expand Down Expand Up @@ -28,7 +28,6 @@ export function useOpportunitiesScreenController({
forcedRepository,
forcedAuthor,
}: OpportunitiesScreenProps) {
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
const { locale, messages } = useI18n();
Expand Down Expand Up @@ -94,10 +93,12 @@ export function useOpportunitiesScreenController({
nextSearchParams.delete("job");
const nextSearch = nextSearchParams.toString();

router.replace(nextSearch ? `${pathname}?${nextSearch}` : pathname, {
scroll: false,
});
}, [pathname, router, searchParams, setSelectedOpportunityId]);
window.history.replaceState(
null,
"",
nextSearch ? `${pathname}?${nextSearch}` : pathname,
);
}, [pathname, searchParams, setSelectedOpportunityId]);
const handleBeforeReload = React.useCallback(() => {
setSelectedOpportunityId(null);
setFilters((previous) => (previous.page === 1 ? previous : { ...previous, page: 1 }));
Expand Down Expand Up @@ -168,7 +169,6 @@ export function useOpportunitiesScreenController({
!remote.isLoading &&
!remote.hasLoadError,
pathname,
router,
currentSearch: searchParams.toString(),
filtersForUrl,
preservedParams: preservedParamsForUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as React from "react";
import type { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
import { buildSearchParamsFromFilters } from "./url-filters";
import type { OpportunityFiltersState } from "@/app/opportunities/_components/opportunities-screen/types";

interface UseUrlSyncParams {
enabled?: boolean;
pathname: string;
currentSearch: string;
router: AppRouterInstance;
filtersForUrl: OpportunityFiltersState;
preservedParams?: Record<string, string | null | undefined>;
defaultCountry?: string;
Expand Down Expand Up @@ -52,7 +50,6 @@ export function useUrlSync({
enabled = true,
pathname,
currentSearch,
router,
filtersForUrl,
preservedParams,
defaultCountry,
Expand Down Expand Up @@ -93,14 +90,13 @@ export function useUrlSync({
}

pendingReplaceRef.current = { href, currentSearch };
router.replace(href, { scroll: false });
window.history.replaceState(null, "", href);
}, [
currentSearch,
enabled,
normalizedCurrentSearch,
normalizedSerializedFilters,
pathname,
router,
serializedSearch,
]);
}