2025-07-23 18:25:15 +00:00
|
|
|
'use client';
|
|
|
|
|
|
2025-05-28 23:08:42 +00:00
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
import { useDomain } from "@/hooks/useDomain";
|
|
|
|
|
import { useCallback } from "react";
|
2025-10-18 23:31:22 +00:00
|
|
|
import { getBrowsePath, GetBrowsePathProps } from "./utils";
|
2025-07-23 18:25:15 +00:00
|
|
|
|
2025-05-28 23:08:42 +00:00
|
|
|
export const useBrowseNavigation = () => {
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const domain = useDomain();
|
|
|
|
|
|
|
|
|
|
const navigateToPath = useCallback(({
|
|
|
|
|
repoName,
|
|
|
|
|
revisionName = 'HEAD',
|
|
|
|
|
path,
|
|
|
|
|
pathType,
|
|
|
|
|
highlightRange,
|
|
|
|
|
setBrowseState,
|
2025-07-23 18:25:15 +00:00
|
|
|
}: Omit<GetBrowsePathProps, 'domain'>) => {
|
|
|
|
|
const browsePath = getBrowsePath({
|
|
|
|
|
repoName,
|
|
|
|
|
revisionName,
|
|
|
|
|
path,
|
|
|
|
|
pathType,
|
|
|
|
|
highlightRange,
|
|
|
|
|
setBrowseState,
|
|
|
|
|
domain,
|
|
|
|
|
});
|
2025-05-28 23:08:42 +00:00
|
|
|
|
2025-07-23 18:25:15 +00:00
|
|
|
router.push(browsePath);
|
2025-05-28 23:08:42 +00:00
|
|
|
}, [domain, router]);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
navigateToPath,
|
|
|
|
|
};
|
|
|
|
|
};
|