Skip to content
Snippets Groups Projects
Commit 3de11167 authored by GustafWallstrom's avatar GustafWallstrom
Browse files

The user can see it's own matches

parent 8b9257b7
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ export class AddPostService {
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
var todayString = String(dd + '-' + mm + '-' + yyyy);
var todayString = String(yyyy + '-' + mm + '-' + dd);
var currUser = localStorage.getItem('currentUser');
return this.http.post('/api/post/createPost',{
......
......@@ -26,6 +26,7 @@
padding-top: 1.5rem;
color: #777;
border-top: .05rem solid #e5e5e5;
float: bottom;
}
/* Customize container */
......@@ -80,4 +81,4 @@
.btn{
text-decoration:none;
cursor: pointer;
}
\ No newline at end of file
}
......@@ -24,5 +24,4 @@
</main>
<footer class="footer">
<p>&copy; Author Gustaf Wallström 2020</p>
</footer>
\ No newline at end of file
@media (min-width: 1000px) {
#your-matches{
width: 45%;
float: left;
}
#all-matches{
float:right;
width: 45%;
float: right;
}
}
.list-group{
margin-right: 2rem;
margin-top: 2rem;
}
.list-group-item{
max-width: 90%;
padding: 0.5rem;
border-top: 1px solid !important;
border-left: 0px;
border-right: 0px;
}
.your-list{
max-width: 90%;
padding: 0rem;
}
.post-item{
max-width: 90%;
border-top: 1px solid;
}
<div class="list-group" id="your-matches">
<div class ="list-containder">
<h5> {{getCurrUser()}}s matches </h5>
<ng-container *ngIf="posts">
<a *ngFor="let post of posts" href="#" class="list-group-item list-group-item-action flex-column align-items-start">
<div class="list-group" id="your-matches">
<h5> {{getCurrUser()}}'s matches </h5>
<div *ngIf="!hasPosts()">Are you sure you have been throwing discs? We can't find any matches! :(</div>
<ng-container *ngFor="let post of posts; let i=index" class="your-list flex-column align-items-start">
<div *ngIf="posts[i].name == getCurrUser()">
<div class="d-flex w-100 justify-content-between post-item">
<h6 class="mb-1">Course: <span style="color:#850505">{{post.title}}</span></h6>
<small>{{post.date}}</small>
</div>
<p class="mb-1">Number of throws: <span style="color:#850505">{{post.description}}</span></p>
</div>
</ng-container>
</div>
<div class="list-group" id="all-matches">
<h5>All matches</h5>
<a *ngFor="let post of posts" class="list-group-item flex-column align-items-start">
<h6>Player: <span style="color:#850505">{{post.name}}</span></h6>
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">Course: <span style="color:#850505">{{post.title}}</span></h5>
<h6 class="mb-1">Course: <span style="color:#850505">{{post.title}}</span></h6>
<small>{{post.date}}</small>
</div>
<p class="mb-1">Number of strokes: <span style="color:#850505">{{post.description}}</span></p>
<small>Click for more details</small>
</a>
</ng-container>
</div>
<div class="list-group" id="all matches">
<h5>All matches</h5>
<a *ngFor="let post of posts" href="#" class="list-group-item list-group-item-action flex-column align-items-start">
<h6>Player : <span style="color:#850505">{{post.name}}</span></h6>
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">Course: <span style="color:#850505">{{post.title}}</span></h5>
<small>{{post.date}}</small>
</div>
<p class="mb-1">Number of strokes: <span style="color:#850505">{{post.description}}</span></p>
<small>Click for more details</small>
</a>
<p class="mb-1">Number of throws: <span style="color:#850505">{{post.description}}</span></p>
</a>
</div>
</div>
\ No newline at end of file
......@@ -17,14 +17,22 @@ export class ShowPostComponent implements OnInit {
}
getCurrUser(){
hasPosts(){
if(this.posts){
for (let index = 0; index < this.posts.length; index++) {
const element = this.posts[index].name;
if(element == this.getCurrUser()) return true;
}
return false;
}
}
getCurrUser(){
return localStorage.getItem('currentUser');
}
ngOnInit(){
this.getCurrUser();
console.log('Current user is: ' + this.getCurrUser().toString());
this.getAllPost();
this.commonService.postAdded_Observable.subscribe(res => {
......@@ -32,11 +40,9 @@ export class ShowPostComponent implements OnInit {
});
}
getAllPost(){
this.showPostService.getAllPost().subscribe(result => {
this.posts = result['data'];
this.posts = result['data'];
});
}
......
......@@ -106,7 +106,7 @@ app.post('/api/post/getAllPost', (req, res) => {
if (err) throw err;
Post.find({}, [], {
sort: {
_id: -1
date: -1
}
}, (err, doc) => {
if (err) throw err;
......
......@@ -11,6 +11,7 @@
"dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.2",
"mongoose": "^5.7.0"
"mongoose": "^5.7.0",
"nodemon": "^2.0.4"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment