-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting.html
70 lines (63 loc) · 2.73 KB
/
listing.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create New Blog</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
</head>
<body style="background-color: #F1F1F1;">
<div class="container p-2">
<h1 class="my-3 fs-4 roboto-medium">
Blog Listing
</h1>
<div class="card p-2">
<div class="card-body">
<ol class="list-group list-group-none m-0" id="listing">
</ol>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script>
let listing = $('#listing')
fetch("/blogs", {
method: "GET",
headers: {
"Content-Type": "application/json"
},
}).then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
response.json().then(res => {
console.log(res)
let listhtml = ``
res.forEach(blog => {
listhtml = `
<li class="list-group-item d-flex justify-content-between align-items-center cursor-pointer">
<img src='${blog.featured_image}' class="img-fluid" width="100"/>
<div class="ms-2 me-auto">
<div class="fw-bold">${blog.title}</div>
${blog.expert}
</div>
<div class="d-flex gap-2">
<a href="/blogs/${blog.slug}/edit" class="btn btn-sm btn-primary">Edit</a>
<button class="btn btn-sm btn-danger" onclick="deleteBlog(${blog.id})">Delete</button>
</div>
</li>`
listing.append(listhtml)
})
})
});
</script>
</body>
</html>