Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
teknikattan-scoring-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tddd96-grupp1
teknikattan-scoring-system
Commits
ac64afe9
Commit
ac64afe9
authored
3 years ago
by
Albin Henriksson
Browse files
Options
Downloads
Patches
Plain Diff
Select correct tab when refreshing admin
parent
61632253
No related branches found
Branches containing commit
No related tags found
1 merge request
!144
Select correct tab when refreshing admin
Pipeline
#45542
passed with warnings
3 years ago
Stage: setup
Stage: test
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/src/pages/admin/AdminPage.tsx
+21
-24
21 additions, 24 deletions
client/src/pages/admin/AdminPage.tsx
with
21 additions
and
24 deletions
client/src/pages/admin/AdminPage.tsx
+
21
−
24
View file @
ac64afe9
...
...
@@ -17,7 +17,7 @@ import LocationCityIcon from '@material-ui/icons/LocationCity'
import
PeopleIcon
from
'
@material-ui/icons/People
'
import
SettingsOverscanIcon
from
'
@material-ui/icons/SettingsOverscan
'
import
React
,
{
useEffect
}
from
'
react
'
import
{
Link
,
Route
,
Switch
,
useRouteMatch
}
from
'
react-router-dom
'
import
{
Link
,
Route
,
Switch
,
useLocation
,
useRouteMatch
}
from
'
react-router-dom
'
import
{
getCities
}
from
'
../../actions/cities
'
import
{
setEditorLoading
}
from
'
../../actions/competitions
'
import
{
setEditorSlideId
}
from
'
../../actions/editor
'
...
...
@@ -59,6 +59,7 @@ const useStyles = makeStyles((theme: Theme) =>
const
AdminView
:
React
.
FC
=
()
=>
{
const
classes
=
useStyles
()
const
location
=
useLocation
()
const
[
openIndex
,
setOpenIndex
]
=
React
.
useState
(
0
)
const
{
path
,
url
}
=
useRouteMatch
()
const
currentUser
=
useAppSelector
((
state
)
=>
state
.
user
.
userInfo
)
...
...
@@ -79,33 +80,29 @@ const AdminView: React.FC = () => {
dispatch
(
setEditorSlideId
(
-
1
))
},
[])
useEffect
(()
=>
{
setActiveTabFromUrl
()
},
[
isAdmin
])
const
setActiveTabFromUrl
=
()
=>
{
let
activeIndex
if
(
isAdmin
)
activeIndex
=
menuAdminItems
.
findIndex
((
menuItem
)
=>
location
.
pathname
.
endsWith
(
menuItem
.
route
))
else
activeIndex
=
menuEditorItems
.
findIndex
((
menuItem
)
=>
location
.
pathname
.
endsWith
(
menuItem
.
route
))
console
.
log
(
activeIndex
,
isAdmin
,
location
.
pathname
,
menuEditorItems
)
if
(
activeIndex
!==
-
1
)
setOpenIndex
(
activeIndex
)
}
const
menuAdminItems
=
[
{
text
:
'
Startsida
'
,
icon
:
DashboardIcon
},
{
text
:
'
Regioner
'
,
icon
:
LocationCityIcon
},
{
text
:
'
Användare
'
,
icon
:
PeopleIcon
},
{
text
:
'
Tävlingshanterare
'
,
icon
:
SettingsOverscanIcon
},
{
text
:
'
Startsida
'
,
icon
:
DashboardIcon
,
route
:
'
dashboard
'
},
{
text
:
'
Regioner
'
,
icon
:
LocationCityIcon
,
route
:
'
regions
'
},
{
text
:
'
Användare
'
,
icon
:
PeopleIcon
,
route
:
'
users
'
},
{
text
:
'
Tävlingshanterare
'
,
icon
:
SettingsOverscanIcon
,
route
:
'
competition-manager
'
},
]
const
menuEditorItems
=
[
{
text
:
'
Startsida
'
,
icon
:
DashboardIcon
},
{
text
:
'
Tävlingshanterare
'
,
icon
:
SettingsOverscanIcon
},
{
text
:
'
Startsida
'
,
icon
:
DashboardIcon
,
route
:
'
dashboard
'
},
{
text
:
'
Tävlingshanterare
'
,
icon
:
SettingsOverscanIcon
,
route
:
'
competition-manager
'
},
]
const
getPathName
=
(
tabName
:
string
)
=>
{
switch
(
tabName
)
{
case
'
Startsida
'
:
return
'
dashboard
'
case
'
Regioner
'
:
return
'
regions
'
case
'
Användare
'
:
return
'
users
'
case
'
Tävlingshanterare
'
:
return
'
competition-manager
'
default
:
return
''
}
}
const
renderItems
=
()
=>
{
const
menuItems
=
isAdmin
?
menuAdminItems
:
menuEditorItems
return
menuItems
.
map
((
value
,
index
)
=>
(
...
...
@@ -114,7 +111,7 @@ const AdminView: React.FC = () => {
button
component
=
{
Link
}
key
=
{
value
.
text
}
to
=
{
`
${
url
}
/
${
getPathName
(
value
.
text
)
}
`
}
to
=
{
`
${
url
}
/
${
value
.
route
}
`
}
selected
=
{
index
===
openIndex
}
onClick
=
{
()
=>
setOpenIndex
(
index
)
}
>
...
...
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