-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyposts.html
More file actions
150 lines (131 loc) · 3.47 KB
/
myposts.html
File metadata and controls
150 lines (131 loc) · 3.47 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Posts - Artisan Echoes</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f5f5f5;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
margin-bottom: 30px;
color: #333;
}
.posts-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 20px;
padding: 20px;
}
.post-card {
background: #fff;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
transition: transform 0.2s, box-shadow 0.2s;
}
.post-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 18px rgba(0,0,0,0.15);
}
.post-image {
width: 100%;
height: 180px;
object-fit: cover;
}
.post-content {
padding: 15px;
}
.post-title {
font-size: 18px;
font-weight: bold;
margin: 0 0 10px;
color: #222;
}
.post-desc {
font-size: 14px;
color: #555;
margin-bottom: 15px;
}
.delete-btn {
display: inline-block;
padding: 8px 12px;
border: none;
border-radius: 6px;
background: #ff4d4d;
color: white;
font-size: 14px;
cursor: pointer;
transition: background 0.2s;
}
.delete-btn:hover {
background: #cc0000;
}
.empty-message {
text-align: center;
font-size: 16px;
color: #777;
margin-top: 40px;
}
.back-btn {
display: block;
margin: 0 auto 20px;
padding: 10px 20px;
background: #FD7B6B;
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
cursor: pointer;
}
.back-btn:hover {
background: #e66a5c;
}
</style>
</head>
<body>
<h1>My Posts</h1>
<button class="back-btn" onclick="window.location.href='index.html'">⬅ Back to Home</button>
<div id="posts-container" class="posts-container"></div>
<p id="empty-message" class="empty-message" style="display: none;">You haven’t posted anything yet.</p>
<script>
const postsContainer = document.getElementById("posts-container");
const emptyMessage = document.getElementById("empty-message");
let storedPosts = JSON.parse(localStorage.getItem("artisanPosts")) || [];
function renderMyPosts() {
postsContainer.innerHTML = "";
if (storedPosts.length === 0) {
emptyMessage.style.display = "block";
return;
}
storedPosts.forEach((post, index) => {
const card = document.createElement("div");
card.classList.add("post-card");
card.innerHTML = `
<img src="${post.image}" class="post-image" alt="Post Image">
<div class="post-content">
<h3 class="post-title">${post.title}</h3>
<p class="post-desc">${post.description}</p>
<button class="delete-btn" data-index="${index}">Delete</button>
</div>
`;
postsContainer.appendChild(card);
});
// Attach delete functionality
document.querySelectorAll(".delete-btn").forEach(btn => {
btn.addEventListener("click", (e) => {
const index = e.target.getAttribute("data-index");
storedPosts.splice(index, 1);
localStorage.setItem("artisanPosts", JSON.stringify(storedPosts));
renderMyPosts();
});
});
}
renderMyPosts();
</script>
</body>
</html>