Reaperxxxx commited on
Commit
ee5c484
·
verified ·
1 Parent(s): b37b962

Update index.html

Browse files
Files changed (1) hide show
  1. 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
- <form id="authForm" enctype="multipart/form-data">
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
- document.getElementById('authForm').addEventListener('submit', async (e) => {
18
- e.preventDefault();
19
- const formData = new FormData(e.target);
20
- const res = await fetch('/api/auth', {
21
- method: 'POST',
22
- body: formData,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  });
24
- const data = await res.json();
25
- if (data.success) {
26
- const profilePicture = formData.get('profilePicture');
27
- if (profilePicture.size > 0) {
28
- const pictureForm = new FormData();
29
- pictureForm.append('file', profilePicture);
30
- pictureForm.append('username', data.user.username);
31
- await fetch('/api/profile-picture', { method: 'POST', body: pictureForm });
 
 
 
 
 
 
 
32
  }
33
- localStorage.setItem('username', data.user.username);
34
- window.location.href = '/home';
35
- } else {
36
- alert(data.message);
 
 
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>