Skip to content

Commit

Permalink
fix: post template
Browse files Browse the repository at this point in the history
  • Loading branch information
gutche committed Mar 7, 2023
1 parent 971cee9 commit 3b4be67
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 73 deletions.
14 changes: 13 additions & 1 deletion back/src/main/java/net/daw/alist/controllers/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.data.domain.Page;

@Controller
Expand All @@ -17,9 +18,20 @@ public class HomeController {

@GetMapping("/")
public String home(Model model) {
Page<Post> posts = postService.getPosts(0,2);
Page<Post> posts = postService.getPosts(0, 2);
model.addAttribute("posts", posts);
return "home";
}

@GetMapping("/posts")
public String getNewPosts(Model model, @RequestParam int page) {

Page<Post> newPage = postService.getPosts(page, 1);

model.addAttribute("posts", newPage);

return "post";
}


}
19 changes: 0 additions & 19 deletions back/src/main/java/net/daw/alist/controllers/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,17 @@
import net.daw.alist.models.Post;
import net.daw.alist.services.PostService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RestController
public class PostController {

@Autowired
private PostService postService;

@GetMapping("/posts")
@ResponseBody
public Page<Post> getNewPosts(@RequestParam int page) {

Page<Post> newPage = postService.getPosts(page, 1);


return newPage;
/* if (newPage != null) {
return ResponseEntity.ok(newPage);
} else {
return ResponseEntity.notFound().build();
}
*/
}

}
3 changes: 2 additions & 1 deletion back/src/main/resources/static/scripts/load-on-scroll.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
page = 1;
page = 0;

$(window).scroll(function () {
if ($(window).scrollTop() + $(window).height() == $(document).height()) {
page++;
$('.spinner-border').removeClass('invisible').addClass('visible');
$.get('https://localhost:8443/posts', { page }, data => {
console.log(data);
Expand Down
3 changes: 1 addition & 2 deletions back/src/main/resources/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<link rel="stylesheet" type="text/css" href="/styles/bootstrap/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/styles/styles.css">
<link rel="stylesheet" type="text/css" href="/styles/home.css">
<link rel="stylesheet" type="text/css" href="/styles/top-list.css">
<script src="https://code.jquery.com/jquery-3.6.3.js" integrity="sha256-nQLuAZGRRcILA+6dMBOvcRh5Pe310sBpanc6+QBmyVM="
crossorigin="anonymous"></script>
<script src="/scripts/bootstrap/bootstrap.bundle.min.js"></script>
Expand All @@ -23,9 +24,7 @@
<body>
{{>navbar}}
<div class="feed-container pt-3">
{{#posts}}
{{>post}}
{{/posts}}
<div class="text-center my-5">
<div class="spinner-border text-white invisible" role="status">
</div>
Expand Down
88 changes: 38 additions & 50 deletions back/src/main/resources/templates/post.html
Original file line number Diff line number Diff line change
@@ -1,57 +1,45 @@
<!DOCTYPE html>

<head>
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css"
integrity="sha512-MV7K8+y+gLIBoVD59lQIYicR65iaqukzvf/nwasF0nqhPay5w/9lJmVM2hMDcnK1OnMGCdVK+iQrJ7lzPJQd1w=="
crossorigin="anonymous" referrerpolicy="no-referrer">
<link rel="stylesheet" type="text/css" href="/styles/bootstrap/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/styles/styles.css">
<link rel="stylesheet" type="text/css" href="/styles/top-list.css">
</head>

<body>
<div class="post mt-3 mb-3">
<div class="postInfo border bg-white d-flex gap-3 py-3">
<img src={{author.imagePath}} alt="Profile picture" width="75" height="75"
class="profileImg rounded-circle flex-shrink-0">
<div class="d-flex gap-2 w-100 justify-content-between">
<div>
<div class="d-flex">
{{#topics}}
<h6 class="topics pe-1">
<a class="topic" href="#">@{{name}}</a>
</h6>
{{/topics}}
</div>
<a class="OP text-black text-decoration-none" href="#">
{{author.username}}
</a>
{{#posts}}
<div class="post mt-3 mb-3">
<div class="postInfo border bg-white d-flex gap-3 py-3">
<img src={{author.imagePath}} alt="Profile picture" width="75" height="75"
class="profileImg rounded-circle flex-shrink-0">
<div class="d-flex gap-2 w-100 justify-content-between">
<div>
<div class="d-flex">
{{#topics}}
<h6 class="topics pe-1">
<a class="topic" href="#">@{{name}}</a>
</h6>
{{/topics}}
</div>
<a class="OP text-black text-decoration-none" href="#">
{{author.username}}
</a>
</div>
</div>
<div class="list-group m-auto">
<div class="bg-white text-black d-flex gap-3 py-3 text-center justify-content-*-center align-items-center"
aria-current="true">
<div class="top w-75 m-auto">
<h2 class="topName">{{title}}</h2>
<ol class="m-auto p-0 w-100">
{{#items}}
<li>
{{description}}
<img src={{imagePath}} alt="image" width="45" height="45" class="itemImage rounded-circle">
</li>
{{/items}}
</ol>
</div>
</div>
<div class="list-group m-auto">
<div class="bg-white text-black d-flex gap-3 py-3 text-center justify-content-*-center align-items-center"
aria-current="true">
<div class="top w-75 m-auto">
<h2 class="topName">{{title}}</h2>
<ol class="m-auto p-0 w-100">
{{#items}}
<li>
{{description}}
<img src={{imagePath}} alt="image" width="45" height="45" class="itemImage rounded-circle">
</li>
{{/items}}
</ol>
</div>
<div class="list-group-item d-flex">
<div class="w-auto m-auto">
<img class="upvoteIcon" src="/images/upvoteIcon.svg" alt="" width="35" height="35">
<img class="downvoteIcon" src="/images/downvoteIcon.svg" alt="" width="35" height="35">
</div>
<img class="shareIcon m-auto" src="/images/shareIcon.svg" alt="" width="35" height="35">
</div>
<div class="list-group-item d-flex">
<div class="w-auto m-auto">
<img class="upvoteIcon" src="/images/upvoteIcon.svg" alt="" width="35" height="35">
<img class="downvoteIcon" src="/images/downvoteIcon.svg" alt="" width="35" height="35">
</div>
<img class="shareIcon m-auto" src="/images/shareIcon.svg" alt="" width="35" height="35">
</div>
</div>
</body>
</div>
{{/posts}}

0 comments on commit 3b4be67

Please sign in to comment.