Skip to content

Commit ef304f0

Browse files
Revert "Add useBrowsePath"
This reverts commit 5f0bd5a.
1 parent 5f0bd5a commit ef304f0

File tree

2 files changed

+18
-75
lines changed

2 files changed

+18
-75
lines changed

packages/web/src/app/[domain]/browse/hooks/useBrowseNavigation.ts

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,15 @@ export type BrowseHighlightRange = {
1313

1414
export const HIGHLIGHT_RANGE_QUERY_PARAM = 'highlightRange';
1515

16-
export interface GetBrowsePathProps {
16+
interface NavigateToPathOptions {
1717
repoName: string;
1818
revisionName?: string;
1919
path: string;
2020
pathType: 'blob' | 'tree';
2121
highlightRange?: BrowseHighlightRange;
2222
setBrowseState?: Partial<BrowseState>;
23-
domain: string;
2423
}
2524

26-
export const getBrowsePath = ({
27-
repoName,
28-
revisionName = 'HEAD',
29-
path,
30-
pathType,
31-
highlightRange,
32-
setBrowseState,
33-
domain,
34-
}: GetBrowsePathProps) => {
35-
const params = new URLSearchParams();
36-
37-
if (highlightRange) {
38-
const { start, end } = highlightRange;
39-
40-
if ('column' in start && 'column' in end) {
41-
params.set(HIGHLIGHT_RANGE_QUERY_PARAM, `${start.lineNumber}:${start.column},${end.lineNumber}:${end.column}`);
42-
} else {
43-
params.set(HIGHLIGHT_RANGE_QUERY_PARAM, `${start.lineNumber},${end.lineNumber}`);
44-
}
45-
}
46-
47-
if (setBrowseState) {
48-
params.set(SET_BROWSE_STATE_QUERY_PARAM, JSON.stringify(setBrowseState));
49-
}
50-
51-
const browsePath = `/${domain}/browse/${repoName}@${revisionName}/-/${pathType}/${path}${params.keys.length > 0 ? `?${params.toString()}` : ''}`;
52-
return browsePath;
53-
}
54-
55-
5625
export const useBrowseNavigation = () => {
5726
const router = useRouter();
5827
const domain = useDomain();
@@ -64,18 +33,24 @@ export const useBrowseNavigation = () => {
6433
pathType,
6534
highlightRange,
6635
setBrowseState,
67-
}: Omit<GetBrowsePathProps, 'domain'>) => {
68-
const browsePath = getBrowsePath({
69-
repoName,
70-
revisionName,
71-
path,
72-
pathType,
73-
highlightRange,
74-
setBrowseState,
75-
domain,
76-
});
36+
}: NavigateToPathOptions) => {
37+
const params = new URLSearchParams();
38+
39+
if (highlightRange) {
40+
const { start, end } = highlightRange;
41+
42+
if ('column' in start && 'column' in end) {
43+
params.set(HIGHLIGHT_RANGE_QUERY_PARAM, `${start.lineNumber}:${start.column},${end.lineNumber}:${end.column}`);
44+
} else {
45+
params.set(HIGHLIGHT_RANGE_QUERY_PARAM, `${start.lineNumber},${end.lineNumber}`);
46+
}
47+
}
48+
49+
if (setBrowseState) {
50+
params.set(SET_BROWSE_STATE_QUERY_PARAM, JSON.stringify(setBrowseState));
51+
}
7752

78-
router.push(browsePath);
53+
router.push(`/${domain}/browse/${repoName}@${revisionName}/-/${pathType}/${path}?${params.toString()}`);
7954
}, [domain, router]);
8055

8156
return {

packages/web/src/app/[domain]/browse/hooks/useBrowsePath.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)