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
339041e7
Commit
339041e7
authored
3 months ago
by
Liliana Sanfilippo
Browse files
Options
Downloads
Patches
Plain Diff
so funktoionier es gerade
parent
ad616978
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#531600
failed
3 months ago
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/utils/TabNavigation.ts
+13
-18
13 additions, 18 deletions
src/utils/TabNavigation.ts
src/utils/handleScroll.ts
+1
-1
1 addition, 1 deletion
src/utils/handleScroll.ts
src/utils/opentabincollapsible.ts
+35
-0
35 additions, 0 deletions
src/utils/opentabincollapsible.ts
with
49 additions
and
19 deletions
src/utils/TabNavigation.ts
+
13
−
18
View file @
339041e7
import
{
useEffect
,
useState
}
from
'
react
'
;
import
{
useNavigate
,
useLocation
}
from
'
react-router-dom
'
;
import
{
useLocation
}
from
'
react-router-dom
'
;
import
{
openFromOtherPage
}
from
'
./openFromOtherpAge
'
;
import
{
handleScroll
}
from
'
./handleScroll
'
;
import
{
openNestedTab
}
from
'
./openNestedTab
'
;
...
...
@@ -7,24 +7,13 @@ import { openTab } from './openTab';
// Custom Hook for central tab navigation
export
const
useTabNavigation
=
()
=>
{
const
navigate
=
useNavigate
();
const
location
=
useLocation
();
const
[
activeTab
,
setActiveTab
]
=
useState
<
string
|
null
>
(
null
);
const
[
activeSubTab
,
setActiveSubTab
]
=
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
"
)
...
...
@@ -35,6 +24,15 @@ export const useTabNavigation = () => {
const
scrollToId
=
params
.
get
(
'
scrollTo
'
);
const
changeTo
=
params
.
get
(
'
changeTo
'
);
// scrolls to a specific collapsible element
if
(
collapseId
)
{
const
collapsible
=
document
.
getElementById
(
collapseId
);
if
(
collapsible
&&
collapsible
.
classList
.
contains
(
'
collapsed
'
))
{
collapsible
.
classList
.
remove
(
'
collapsed
'
);
// Open the collapsible
}
handleScroll
(
collapseId
);
// This triggers the scroll action
}
// opens main and (if necessary) subtab
if
(
tabId
)
{
let
tab
=
document
.
getElementById
(
tabId
);
...
...
@@ -48,10 +46,7 @@ export const useTabNavigation = () => {
}
}
// scrolls to a specific collapsible element
if
(
collapseId
)
{
handleScroll
(
collapseId
);
}
// opens tab on another page
if
(
tabId
)
{
...
...
@@ -81,7 +76,7 @@ export const useTabNavigation = () => {
setActiveSubTab
(
subTabId
||
null
);
},
[
location
.
search
]);
return
{
activeTab
,
activeSubTab
,
handleTabChange
};
return
{
activeTab
,
activeSubTab
};
};
This diff is collapsed.
Click to expand it.
src/utils/handleScroll.ts
+
1
−
1
View file @
339041e7
...
...
@@ -5,7 +5,7 @@ export const handleScroll = (scrollId: string) => {
const
elementTop
=
scrollElement
.
getBoundingClientRect
().
top
+
window
.
pageYOffset
;
const
offset
=
window
.
innerHeight
/
2
-
scrollElement
.
offsetHeight
/
2
;
const
scrollPosition
=
elementTop
-
offset
;
window
.
scrollTo
({
top
:
scrollPosition
,
behavior
:
'
smooth
'
,
...
...
This diff is collapsed.
Click to expand it.
src/utils/opentabincollapsible.ts
0 → 100644
+
35
−
0
View file @
339041e7
import
{
openTab
}
from
"
./openTab
"
;
import
{
handleScroll
}
from
"
./handleScroll
"
;
// Funktion, um einen Tab in einem Collapsible zu öffnen
export
const
openTabInCollapsible
=
(
collapsibleId
:
string
,
// ID des Collapsibles
tabId
:
string
,
// ID des zu öffnenden Tabs
collapsibleClass
:
string
,
// Klasse des Collapsibles (z. B. für das Styling)
tabClass
:
string
// Klasse des Tabs (z. B. für das Styling)
)
=>
{
// Öffne das Collapsible (falls es geschlossen ist)
const
collapsible
=
document
.
getElementById
(
collapsibleId
);
if
(
collapsible
&&
collapsible
.
classList
.
contains
(
'
collapsed
'
))
{
collapsible
.
classList
.
remove
(
'
collapsed
'
);
// Öffne das Collapsible
}
// Stelle sicher, dass wir zu diesem Collapsible scrollen
handleScroll
(
collapsibleId
);
// Öffne den entsprechenden Tab innerhalb des Collapsibles
openTab
(
tabId
,
tabClass
);
// Optional: Wir können auch zu diesem Tab scrollen, wenn nötig
const
selectedTab
=
document
.
getElementById
(
tabId
);
if
(
selectedTab
)
{
const
elementTop
=
selectedTab
.
getBoundingClientRect
().
top
+
window
.
pageYOffset
;
const
offset
=
window
.
innerHeight
/
2
-
selectedTab
.
offsetHeight
/
2
;
const
scrollPosition
=
elementTop
-
offset
;
window
.
scrollTo
({
top
:
scrollPosition
,
behavior
:
'
smooth
'
,
});
}
};
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