Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
project_ss23_gameunity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Yusuf Akgül
project_ss23_gameunity
Commits
6266f286
Commit
6266f286
authored
1 year ago
by
Serdar D
Browse files
Options
Downloads
Patches
Plain Diff
Sort Function Implemented.
parent
1e94febc
No related branches found
Branches containing commit
No related tags found
1 merge request
!6
Sort + Search UI
Pipeline
#34202
passed
1 year ago
Stage: build
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
components/Sort.tsx
+37
-8
37 additions, 8 deletions
components/Sort.tsx
with
37 additions
and
8 deletions
components/Sort.tsx
+
37
−
8
View file @
6266f286
import
{
Box
,
Card
,
CardContent
,
FormControl
,
FormHelperText
,
MenuItem
,
Select
,
SelectChangeEvent
,
Typography
}
from
"
@mui/material
"
;
import
{
useState
}
from
"
react
"
;
import
{
useState
,
useEffect
}
from
"
react
"
;
import
{
getGame
,
getGames
}
from
"
@/lib/igdb
"
;
import
{
IGame
}
from
"
@/types/types
"
;
import
Image
from
"
next/image
"
;
// this is a single sorting helper-component, only for design purposes
export
default
function
Sort
()
{
const
[
select
,
setSelct
]
=
useState
(
''
);
const
[
select
,
setSelect
]
=
useState
(
''
);
const
[
games
,
setGames
]
=
useState
<
IGame
[]
>
([]);
useEffect
(()
=>
{
async
function
fetchGames
()
{
//spiele werden über getGames geholt und in den state gesetzt
const
fetchedGames
=
await
getGames
();
setGames
(
fetchedGames
);
}
fetchGames
();
},
[]);
const
handleChange
=
(
event
:
SelectChangeEvent
)
=>
{
setSelct
(
event
.
target
.
value
);
setSelect
(
event
.
target
.
value
);
};
const
sortGames
=
()
=>
{
if
(
select
===
"
name
"
)
{
// Sortiert die Spiele nach namen (aufsteigend)
return
games
.
sort
((
a
,
b
)
=>
a
.
name
.
localeCompare
(
b
.
name
));
}
// returned unsortierte games
return
games
;
};
const
sortedGames
=
sortGames
();
return
(
<
Box
sx
=
{
{
position
:
'
sticky
'
,
top
:
0
}
}
>
<
Card
variant
=
"outlined"
>
<
Card
variant
=
"outlined"
>
<
CardContent
>
<
Typography
>
Filter
</
Typography
>
<
FormControl
fullWidth
>
<
FormHelperText
>
Sort
y
By
</
FormHelperText
>
<
FormHelperText
>
Sort By
</
FormHelperText
>
<
Select
value
=
{
select
}
onChange
=
{
handleChange
}
...
...
@@ -26,12 +50,17 @@ export default function Sort() {
<
MenuItem
value
=
""
>
<
em
>
Any
</
em
>
</
MenuItem
>
<
MenuItem
value
=
{
1
}
>
Rating
</
MenuItem
>
<
MenuItem
value
=
{
2
}
>
Release Date
</
MenuItem
>
<
MenuItem
value
=
"name"
>
Name
</
MenuItem
>
</
Select
>
</
FormControl
>
</
CardContent
>
</
Card
>
{
/* Zeigt sortierte liste */
}
{
sortedGames
.
map
(
game
=>
(
<
div
key
=
{
game
.
id
}
>
{
game
.
name
}
</
div
>
))
}
</
Box
>
)
}
\ No newline at end of file
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