Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-155
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-155
2021-155
Commits
69cf44f2
Commit
69cf44f2
authored
Oct 18, 2021
by
Kamal Thennakoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve leaderboard functionalities
parent
4bd040fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
11 deletions
+35
-11
client/components/portfolio/leaderboard-table/leaderboard-table.js
...mponents/portfolio/leaderboard-table/leaderboard-table.js
+35
-11
No files found.
client/components/portfolio/leaderboard-table/leaderboard-table.js
View file @
69cf44f2
...
@@ -14,6 +14,8 @@ import FirstPageIcon from '@material-ui/icons/FirstPage';
...
@@ -14,6 +14,8 @@ import FirstPageIcon from '@material-ui/icons/FirstPage';
import
KeyboardArrowLeft
from
'
@material-ui/icons/KeyboardArrowLeft
'
;
import
KeyboardArrowLeft
from
'
@material-ui/icons/KeyboardArrowLeft
'
;
import
KeyboardArrowRight
from
'
@material-ui/icons/KeyboardArrowRight
'
;
import
KeyboardArrowRight
from
'
@material-ui/icons/KeyboardArrowRight
'
;
import
LastPageIcon
from
'
@material-ui/icons/LastPage
'
;
import
LastPageIcon
from
'
@material-ui/icons/LastPage
'
;
import
{
TableHead
}
from
'
@material-ui/core
'
;
import
{
useRouter
}
from
'
next/router
'
;
const
useStyles1
=
makeStyles
((
theme
)
=>
({
const
useStyles1
=
makeStyles
((
theme
)
=>
({
root
:
{
root
:
{
...
@@ -80,11 +82,13 @@ TablePaginationActions.propTypes = {
...
@@ -80,11 +82,13 @@ TablePaginationActions.propTypes = {
rowsPerPage
:
PropTypes
.
number
.
isRequired
,
rowsPerPage
:
PropTypes
.
number
.
isRequired
,
};
};
function
createData
(
name
,
calories
,
fat
)
{
function
createData
(
name
,
username
,
points
)
{
return
{
name
,
calories
,
fat
};
return
{
name
,
username
,
points
};
}
}
const
rows
=
[
/* const rows = [
createData('Cupcake', 305, 3.7),
createData('Cupcake', 305, 3.7),
createData('Donut', 452, 25.0),
createData('Donut', 452, 25.0),
createData('Eclair', 262, 16.0),
createData('Eclair', 262, 16.0),
...
@@ -98,7 +102,7 @@ const rows = [
...
@@ -98,7 +102,7 @@ const rows = [
createData('Marshmallow', 318, 0),
createData('Marshmallow', 318, 0),
createData('Nougat', 360, 19.0),
createData('Nougat', 360, 19.0),
createData('Oreo', 437, 18.0),
createData('Oreo', 437, 18.0),
].
sort
((
a
,
b
)
=>
(
a
.
calories
<
b
.
calories
?
-
1
:
1
));
].sort((a, b) => (a.calories < b.calories ? -1 : 1));
*/
const
useStyles2
=
makeStyles
({
const
useStyles2
=
makeStyles
({
table
:
{
table
:
{
...
@@ -106,10 +110,12 @@ const useStyles2 = makeStyles({
...
@@ -106,10 +110,12 @@ const useStyles2 = makeStyles({
},
},
});
});
export
default
function
LeaderBoardTable
()
{
export
default
function
LeaderBoardTable
(
props
)
{
const
router
=
useRouter
()
const
rows
=
props
.
data
.
map
((
user
)
=>
createData
(
user
.
name
,
user
.
username
,
user
.
coding
.
points
.
toFixed
(
3
)))
const
classes
=
useStyles2
();
const
classes
=
useStyles2
();
const
[
page
,
setPage
]
=
React
.
useState
(
0
);
const
[
page
,
setPage
]
=
React
.
useState
(
0
);
const
[
rowsPerPage
,
setRowsPerPage
]
=
React
.
useState
(
5
);
const
[
rowsPerPage
,
setRowsPerPage
]
=
React
.
useState
(
1
5
);
const
emptyRows
=
rowsPerPage
-
Math
.
min
(
rowsPerPage
,
rows
.
length
-
page
*
rowsPerPage
);
const
emptyRows
=
rowsPerPage
-
Math
.
min
(
rowsPerPage
,
rows
.
length
-
page
*
rowsPerPage
);
...
@@ -122,23 +128,41 @@ export default function LeaderBoardTable() {
...
@@ -122,23 +128,41 @@ export default function LeaderBoardTable() {
setPage
(
0
);
setPage
(
0
);
};
};
const
handleClick
=
(
e
,
uname
)
=>
{
e
.
preventDefault
()
router
.
push
(
`/portfolio/
${
uname
}
`
);
}
console
.
log
(
'
inside TABLE
'
,
props
.
data
)
return
(
return
(
<
TableContainer
component
=
{
Paper
}
>
<
TableContainer
component
=
{
Paper
}
>
<
Table
className
=
{
classes
.
table
}
aria
-
label
=
"
custom pagination table
"
>
<
Table
className
=
{
classes
.
table
}
aria
-
label
=
"
custom pagination table
"
>
<
TableHead
>
<
TableRow
>
<
TableCell
>
Rank
<
/TableCell
>
<
TableCell
align
=
"
right
"
>
Name
<
/TableCell
>
<
TableCell
align
=
"
right
"
>
Username
<
/TableCell
>
<
TableCell
align
=
"
right
"
>
Score
<
/TableCell
>
<
/TableRow
>
<
/TableHead
>
<
TableBody
>
<
TableBody
>
{(
rowsPerPage
>
0
{(
rowsPerPage
>
0
?
rows
.
slice
(
page
*
rowsPerPage
,
page
*
rowsPerPage
+
rowsPerPage
)
?
rows
.
slice
(
page
*
rowsPerPage
,
page
*
rowsPerPage
+
rowsPerPage
)
:
rows
:
rows
).
map
((
row
)
=>
(
).
map
((
row
,
id
)
=>
(
<
TableRow
key
=
{
row
.
name
}
>
<
TableRow
onClick
=
{(
e
)
=>
handleClick
(
e
,
row
.
username
)}
hover
role
=
"
checkbox
"
key
=
{
row
.
user
name
}
>
<
TableCell
component
=
"
th
"
scope
=
"
row
"
>
<
TableCell
component
=
"
th
"
scope
=
"
row
"
>
{
id
+
1
}
<
/TableCell
>
<
TableCell
style
=
{{
width
:
160
}}
align
=
"
right
"
>
{
row
.
name
}
{
row
.
name
}
<
/TableCell
>
<
/TableCell
>
<
TableCell
style
=
{{
width
:
160
}}
align
=
"
right
"
>
<
TableCell
style
=
{{
width
:
160
}}
align
=
"
right
"
>
{
row
.
calories
}
{
row
.
username
}
<
/TableCell
>
<
/TableCell
>
<
TableCell
style
=
{{
width
:
160
}}
align
=
"
right
"
>
<
TableCell
style
=
{{
width
:
160
}}
align
=
"
right
"
>
{
row
.
fat
}
{
row
.
points
}
<
/TableCell
>
<
/TableCell
>
<
/TableRow
>
<
/TableRow
>
))}
))}
...
@@ -152,7 +176,7 @@ export default function LeaderBoardTable() {
...
@@ -152,7 +176,7 @@ export default function LeaderBoardTable() {
<
TableFooter
>
<
TableFooter
>
<
TableRow
>
<
TableRow
>
<
TablePagination
<
TablePagination
rowsPerPageOptions
=
{[
5
,
10
,
25
,
{
label
:
'
All
'
,
value
:
-
1
}]}
rowsPerPageOptions
=
{[
5
,
10
,
15
,
25
,
{
label
:
'
All
'
,
value
:
-
1
}]}
colSpan
=
{
3
}
colSpan
=
{
3
}
count
=
{
rows
.
length
}
count
=
{
rows
.
length
}
rowsPerPage
=
{
rowsPerPage
}
rowsPerPage
=
{
rowsPerPage
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment