@@ -13,46 +13,15 @@ export type BrowseHighlightRange = {
13
13
14
14
export const HIGHLIGHT_RANGE_QUERY_PARAM = 'highlightRange' ;
15
15
16
- export interface GetBrowsePathProps {
16
+ interface NavigateToPathOptions {
17
17
repoName : string ;
18
18
revisionName ?: string ;
19
19
path : string ;
20
20
pathType : 'blob' | 'tree' ;
21
21
highlightRange ?: BrowseHighlightRange ;
22
22
setBrowseState ?: Partial < BrowseState > ;
23
- domain : string ;
24
23
}
25
24
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
-
56
25
export const useBrowseNavigation = ( ) => {
57
26
const router = useRouter ( ) ;
58
27
const domain = useDomain ( ) ;
@@ -64,18 +33,24 @@ export const useBrowseNavigation = () => {
64
33
pathType,
65
34
highlightRange,
66
35
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
+ }
77
52
78
- router . push ( browsePath ) ;
53
+ router . push ( `/ ${ domain } /browse/ ${ repoName } @ ${ revisionName } /-/ ${ pathType } / ${ path } ? ${ params . toString ( ) } ` ) ;
79
54
} , [ domain , router ] ) ;
80
55
81
56
return {
0 commit comments