Skip to content

Commit c901b3c

Browse files
committed
Added Contest List Feature
1 parent cc9109d commit c901b3c

File tree

7 files changed

+179
-5
lines changed

7 files changed

+179
-5
lines changed

public/stylesheets/tablestyle.css

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
html,
2+
body,
3+
.intro {
4+
height: 100%;
5+
}
6+
7+
table td,
8+
table th {
9+
text-overflow: ellipsis;
10+
white-space: nowrap;
11+
overflow: hidden;
12+
}
13+
14+
thead th {
15+
color: #fff;
16+
}
17+
18+
.card {
19+
border-radius: .5rem;
20+
}
21+
22+
.table-scroll {
23+
border-radius: .5rem;
24+
}
25+
26+
.table-scroll table thead th {
27+
font-size: 1.25rem;
28+
}
29+
30+
.pagination {
31+
display: inline-block;
32+
}
33+
34+
.pagination a {
35+
color: black;
36+
float: left;
37+
padding: 8px 16px;
38+
text-decoration: none;
39+
}
40+
41+
.pagination a.active {
42+
background-color: #5bc0de ;
43+
color: white;
44+
}
45+
46+
.pagination a:hover:not(.active) {background-color: #ddd;}

routes/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
const express = require('express')
2+
const contest = require('../models/contest')
3+
const { fetchContest } = require('../services/contests')
24
const router = express.Router()
35

46
router.get('/',(req,res)=> {
57
res.render("index")
68
})
9+
//fetchContest()
10+
11+
router.get('/contests',async (req,res) => {
12+
try {
13+
let contests = await contest.find({})
14+
res.render('contests/index',{contests:contests})
15+
}
16+
catch(error) {
17+
console.log("SHITTT")
18+
res.send(error.message)
19+
}
20+
})
721

822
module.exports = router

services/contests.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const getContestRankings = async function(contestSlug) {
6161
}
6262

6363

64+
6465
const fetchContest = async () => {
6566

6667
try {
@@ -97,11 +98,17 @@ const fetchContest = async () => {
9798
}
9899
let newContest = new Contest({
99100
_id: contest.titleSlug,
100-
startTime: contest.startTime,
101+
startTime: contest.startTime*1000,
101102
endTime: startTime + contest.duration*1000,
102103
lastUpdated: Date.now(),
103104
})
104-
await newContest.save()
105+
let oldContest = await Contest.findById(contest.titleSlug)
106+
if(oldContest==null){
107+
await newContest.save()
108+
}
109+
else{
110+
Contest.findByIdAndUpdate(contest.titleSlug,newContest)
111+
}
105112
}
106113
return res.data.allContests
107114
}
@@ -117,9 +124,6 @@ const fetchContest = async () => {
117124

118125

119126

120-
121-
122-
123127
module.exports.getContestRankings = getContestRankings
124128
module.exports.fetchContest = fetchContest
125129

views/contests/index.ejs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
<link rel="stylesheet" href="/stylesheets/tablestyle.css">
3+
4+
<section class="intro" >
5+
<h1 class="mb-5 mt-5" style="text-align: center; ">Leetcode Contests</h1>
6+
<div class="bg-image h-100" >
7+
<div class="mask d-flex align-items-center h-100">
8+
<div class="container">
9+
<div class="row justify-content-center">
10+
<div class="col-12">
11+
<div class="card">
12+
<div class="card-body p-0">
13+
<div class="table-responsive table-scroll" data-mdb-perfect-scrollbar="true" style="position: relative; height: 700px">
14+
<table id="data" class="table table-striped mb-0">
15+
<thead style="background-color: #002d72;">
16+
<tr>
17+
<th scope="col">Contest Name</th>
18+
<th scope="col">Type</th>
19+
<th scope="col">Start Time</th>
20+
<th scope="col">Duration</th>
21+
22+
</tr>
23+
</thead>
24+
<tbody>
25+
<% for( let contest of contests ) { %>
26+
<tr>
27+
<td><%= contest._id %> </td>
28+
<% if (contest.startTime>Date.now()) { %>
29+
<td>Upcoming</td>
30+
<% } else { %>
31+
<td>Virtual</td>
32+
<% } %>
33+
<td><%= contest.startTime %></td>
34+
<td>1.5 Hours </td>
35+
36+
</tr>
37+
<% } %>
38+
39+
40+
</tbody>
41+
</table>
42+
</div>
43+
</div>
44+
</div>
45+
</div>
46+
</div>
47+
</div>
48+
</div>
49+
</div>
50+
</section>
51+
<script>
52+
$(document).ready(function(){
53+
$('#data').after('<div id="nav" class="pagination"></div>');
54+
var rowsShown = 50;
55+
var rowsTotal = $('#data tbody tr').length;
56+
var numPages = rowsTotal/rowsShown;
57+
for(i = 0;i < numPages;i++) {
58+
var pageNum = i + 1;
59+
$('#nav').append('<a href="#" rel="'+i+'">'+pageNum+'</a> ');
60+
}
61+
$('#data tbody tr').hide();
62+
$('#data tbody tr').slice(0, rowsShown).show();
63+
$('#nav a:first').addClass('active');
64+
$('#nav a').bind('click', function(){
65+
66+
$('#nav a').removeClass('active');
67+
$(this).addClass('active');
68+
var currPage = $(this).attr('rel');
69+
var startItem = currPage * rowsShown;
70+
var endItem = startItem + rowsShown;
71+
$('#data tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
72+
css('display','table-row').animate({opacity:1}, 300);
73+
});
74+
});
75+
</script>

views/index.ejs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="container">
2+
<h1>Welcome to Leetcode Rating Predictor</h1>
3+
</div>

views/layouts/layout.ejs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
<meta charset="UTF-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
8+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
9+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
710
<title>Leetcode rating predictor</title>
811
</head>
912
<body>
13+
<%- include('./navbar.ejs') %>
1014
<%- body %>
15+
16+
17+
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
18+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js" integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT" crossorigin="anonymous"></script>
1119
</body>
1220
</html>

views/layouts/navbar.ejs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark">
2+
<div class="container-fluid">
3+
<a class="navbar-brand" href="#">Navbar</a>
4+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
5+
<span class="navbar-toggler-icon"></span>
6+
</button>
7+
<div class="collapse navbar-collapse" id="navbarNav">
8+
<ul class="navbar-nav">
9+
<li class="nav-item">
10+
<a class="nav-link active" aria-current="page" href="/">Home</a>
11+
</li>
12+
<li class="nav-item">
13+
<a class="nav-link" href="/contests">Contests</a>
14+
</li>
15+
<li class="nav-item">
16+
<a class="nav-link" href="#">Pricing</a>
17+
</li>
18+
<li class="nav-item">
19+
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
20+
</li>
21+
</ul>
22+
</div>
23+
</div>
24+
</nav>

0 commit comments

Comments
 (0)