Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bielefeld-CeBiTec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
2024 Competition
Bielefeld-CeBiTec
Commits
796654fb
Commit
796654fb
authored
4 months ago
by
Liliana Sanfilippo
Browse files
Options
Downloads
Patches
Plain Diff
fixed?
parent
6bbd61a3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/utils/TabNavigation.ts
+20
-3
20 additions, 3 deletions
src/utils/TabNavigation.ts
with
20 additions
and
3 deletions
src/utils/TabNavigation.ts
+
20
−
3
View file @
796654fb
import
{
useEffect
,
useState
}
from
'
react
'
;
import
{
useLocation
}
from
'
react-router-dom
'
;
import
{
useLocation
,
useNavigate
}
from
'
react-router-dom
'
;
import
{
openFromOtherPage
}
from
'
./openFromOtherpAge
'
;
import
{
handleScroll
}
from
'
./handleScroll
'
;
import
{
openNestedTab
}
from
'
./openNestedTab
'
;
...
...
@@ -9,14 +9,25 @@ import { openTabInCollapsible } from './opentabincollapsible';
// Custom Hook for central tab navigation
export
const
useTabNavigation
=
()
=>
{
const
location
=
useLocation
();
const
navigate
=
useNavigate
();
const
[
activeTab
,
setActiveTab
]
=
useState
<
string
|
null
>
(
null
);
const
[
activeSubTab
,
setActiveSubTab
]
=
useState
<
string
|
null
>
(
null
);
const
[,
setActiveCollapsible
]
=
useState
<
string
|
null
>
(
null
);
// tab change and url update
const
handleTabChange
=
(
tabId
:
string
,
subTabId
?:
string
)
=>
{
setActiveTab
(
tabId
);
setActiveSubTab
(
subTabId
||
null
);
// updatung the url
let
newUrl
=
`
${
location
.
pathname
}
?tab=
${
tabId
}
`
;
if
(
subTabId
)
{
newUrl
+=
`&subTab=
${
subTabId
}
`
;
}
navigate
(
newUrl
,
{
replace
:
true
});
}
useEffect
(()
=>
{
console
.
log
(
"
Use Effect
"
)
const
params
=
new
URLSearchParams
(
location
.
search
);
...
...
@@ -26,7 +37,11 @@ export const useTabNavigation = () => {
const
scrollToId
=
params
.
get
(
'
scrollTo
'
);
const
changeTo
=
params
.
get
(
'
changeTo
'
);
const
colTab
=
params
.
get
(
'
colTab
'
);
// const navigate = useNavigate();
// scrolls to a specific collapsible element
if
(
collapseId
)
{
setActiveCollapsible
(
collapseId
);
...
...
@@ -77,11 +92,13 @@ export const useTabNavigation = () => {
}
}
setActiveTab
(
tabId
);
setActiveSubTab
(
subTabId
||
null
);
},
[
location
.
search
]);
return
{
activeTab
,
activeSubTab
};
return
{
activeTab
,
activeSubTab
,
handleTabChange
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment