Spaces:
Running
Running
Update index.html
Browse files- index.html +46 -34
index.html
CHANGED
|
@@ -1,41 +1,53 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html lang="en">
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Login / Sign Up</title>
|
| 7 |
-
<link rel="stylesheet" href="style.css"> <!-- Link to external CSS -->
|
| 8 |
-
</head>
|
| 9 |
<body>
|
| 10 |
-
<
|
| 11 |
-
<input type="text" name="username" placeholder="Username" required>
|
| 12 |
-
<input type="password" name="password" placeholder="Password" required>
|
| 13 |
-
<input type="file" name="profilePicture">
|
| 14 |
-
<button type="submit">Login / Sign Up</button>
|
| 15 |
-
</form>
|
| 16 |
<script>
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
});
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
});
|
|
|
|
|
|
|
| 39 |
</script>
|
| 40 |
-
</body>
|
| 41 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<body>
|
| 2 |
+
<div id="posts"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
<script>
|
| 4 |
+
let page = 0;
|
| 5 |
+
const limit = 5;
|
| 6 |
+
|
| 7 |
+
async function loadPosts() {
|
| 8 |
+
const res = await fetch('/api/posts');
|
| 9 |
+
const posts = await res.json();
|
| 10 |
+
|
| 11 |
+
const paginatedPosts = posts.slice(page * limit, (page + 1) * limit);
|
| 12 |
+
if (paginatedPosts.length === 0) return;
|
| 13 |
+
|
| 14 |
+
const postsContainer = document.getElementById('posts');
|
| 15 |
+
paginatedPosts.forEach(post => {
|
| 16 |
+
const postHTML = `
|
| 17 |
+
<div class="post">
|
| 18 |
+
<h3>${post.username}</h3>
|
| 19 |
+
<p>${post.caption}</p>
|
| 20 |
+
${post.file ? `<img src="${post.file}" alt="Post Image">` : ''}
|
| 21 |
+
<button onclick="followUser('${post.username}')">Follow</button>
|
| 22 |
+
</div>
|
| 23 |
+
`;
|
| 24 |
+
postsContainer.innerHTML += postHTML;
|
| 25 |
});
|
| 26 |
+
|
| 27 |
+
page++;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
function followUser(target) {
|
| 31 |
+
const username = localStorage.getItem('username');
|
| 32 |
+
fetch('/api/follow', {
|
| 33 |
+
method: 'POST',
|
| 34 |
+
headers: { 'Content-Type': 'application/json' },
|
| 35 |
+
body: JSON.stringify({ username, target }),
|
| 36 |
+
}).then(res => res.json()).then(data => {
|
| 37 |
+
if (data.success) {
|
| 38 |
+
alert(`You are now following ${target}!`);
|
| 39 |
+
} else {
|
| 40 |
+
alert(data.message);
|
| 41 |
}
|
| 42 |
+
});
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
window.addEventListener('scroll', () => {
|
| 46 |
+
if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
|
| 47 |
+
loadPosts();
|
| 48 |
}
|
| 49 |
});
|
| 50 |
+
|
| 51 |
+
loadPosts();
|
| 52 |
</script>
|
| 53 |
+
</body>
|
|
|