diff --git a/.circleci/config.yml b/.circleci/config.yml index b83875d..0e710e5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -51,6 +51,9 @@ jobs: command: | set -o pipefail npm run lint + - run: + name: deploy app + command: curl "https://api.render.com/deploy/srv-cqehv6pu0jms739cc6ug?key=WMz-rSxnwhk" workflows: version: 2 diff --git a/README.md b/README.md index f7ef071..2a047cc 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,72 @@ # GameGrid Client ## Project Description + This is the client-side application for GameGrid, a social network for gamers. It provides a user-friendly interface for gamers to connect, share, and compete. ## Deliverables + 1. A Next.js client application. 2. Pages: - - Home page with navigation bar. - - About page with content from the server. - - Login page with basic validation. + - Home page with navigation bar. + - About page with content from the server. + - Login page with basic validation. 3. Linting and testing setup using ESLint and Cypress. 4. CI/CD pipeline for automated testing and deployment. ## How to Install and Run Your Project ### Prerequisites + - Node.js (v14 or higher) - npm (v6 or higher) - Git ### Installation -1. Clone the repository: - ```sh - git clone https://github.com/GameGrid-Team/gamegrid-client - ``` + +1. Clone the repository(branch should be main): + + ```sh + git clone https://github.com/GameGrid-Team/gamegrid-client + ``` 2. Install dependencies: - ```sh - npm install - ``` + ```sh + npm install + ``` ### Running the Client + 1. Start the development server: - ```sh - npm run dev - ``` + + ```sh + npm run dev + ``` 2. The client application should now be running on `http://localhost:3000`. ### Building for Production + 1. Build the project: - ```sh - npm run build - ``` + + ```sh + npm run build + ``` 2. Start the production server: - ```sh - npm start - ``` + ```sh + npm start + ``` ### Linting and Testing + 1. Run ESLint: - ```sh - npm run lint - ``` -2. Run Cypress tests: - ```sh - npm run test - ``` + ```sh + npm run lint + ``` +2. Run Cypress tests: + ```sh + npm run test + ``` diff --git a/src/app/HomePage/LeaderBoard/page.js b/src/app/HomePage/LeaderBoard/page.js index f0c1b3a..9e93e83 100644 --- a/src/app/HomePage/LeaderBoard/page.js +++ b/src/app/HomePage/LeaderBoard/page.js @@ -11,7 +11,7 @@ export default function LeaderBoard() { useEffect(() => { const fetchData = async () => { - const response = await fetch(`http://localhost:3001/api/users/leaderboard`) // Adjust the endpoint to your setup + const response = await fetch(`https://gamegrid-server.onrender.com/api/users/leaderboard`) // Adjust the endpoint to your setup const data = await response.json() setUsers(data.users) } diff --git a/src/app/HomePage/Profile/[id]/Like/page.js b/src/app/HomePage/Profile/[id]/Like/page.js index 8a61c98..56c9ec9 100644 --- a/src/app/HomePage/Profile/[id]/Like/page.js +++ b/src/app/HomePage/Profile/[id]/Like/page.js @@ -10,7 +10,7 @@ export default function ProfileLike({ params }) { useEffect(() => { const fetchUserData = async () => { try { - const response = await fetch(`http://localhost:3001/api/users/${params.id}/data`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/users/${params.id}/data`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, }) diff --git a/src/app/HomePage/Profile/[id]/Save/page.js b/src/app/HomePage/Profile/[id]/Save/page.js index 3278653..0b7f860 100644 --- a/src/app/HomePage/Profile/[id]/Save/page.js +++ b/src/app/HomePage/Profile/[id]/Save/page.js @@ -11,7 +11,7 @@ export default function ProfileSave({ params }) { useEffect(() => { const fetchUserData = async () => { try { - const response = await fetch(`http://localhost:3001/api/users/${params.id}/data`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/users/${params.id}/data`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, }) diff --git a/src/app/HomePage/Profile/[id]/edit/page.js b/src/app/HomePage/Profile/[id]/edit/page.js index 081c1e7..fa96d11 100644 --- a/src/app/HomePage/Profile/[id]/edit/page.js +++ b/src/app/HomePage/Profile/[id]/edit/page.js @@ -3,7 +3,7 @@ import { useState, useEffect } from 'react' import Head from 'next/head' import LoadingOverlay from '@/app/components/loading' import AlertDialog from '@/app/components/Alerts' - +import { logoutbtn } from '../../../../actions' export default function ProfilePage({ params }) { const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) @@ -34,7 +34,7 @@ export default function ProfilePage({ params }) { useEffect(() => { const fetchUserData = async () => { try { - const userResponse = await fetch(`http://localhost:3001/api/users/${params.id}/data`, { + const userResponse = await fetch(`https://gamegrid-server.onrender.com/api/users/${params.id}/data`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, }) @@ -89,7 +89,7 @@ export default function ProfilePage({ params }) { const inputPassword = document.getElementById('passwordInput') let userPassword = '' try { - const response = await fetch(`http://localhost:3001/api/users/${params.id}/data`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/users/${params.id}/data`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, }) @@ -101,19 +101,22 @@ export default function ProfilePage({ params }) { } catch (error) { console.error('Error ', error) } + console.log('1 ', inputPassword.value) + console.log('2 ', userPassword) if (inputPassword.value === userPassword) { try { - const response = await fetch(`http://localhost:3001/api/users/${params.id}/delete`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/users/${params.id}/delete`, { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, }) const data = await response.json() - if (response.ok) { document.getElementById('confirm_modal').close() document.getElementById('alert-success').showModal() await sleep(2000) - window.location.href = '/' + logoutbtn().then(async () => { + window.location.href = '/' + }) } } catch (error) { console.error('Error deleting user data:', error) @@ -138,9 +141,12 @@ export default function ProfilePage({ params }) { reader.readAsDataURL(file) } const deleteAvatar = async () => { - const response = await fetch(`http://localhost:3001/api/users/${params.id}/avatar/remove`, { - method: 'DELETE', - }) + const response = await fetch( + `https://gamegrid-server.onrender.com/api/users/${params.id}/avatar/remove`, + { + method: 'DELETE', + } + ) if (response.ok) { uploadAvatar() } @@ -149,10 +155,13 @@ export default function ProfilePage({ params }) { const formData = new FormData() formData.append('image', userData.avatar) - const response = await fetch(`http://localhost:3001/api/users/${params.id}/avatar/upload`, { - method: 'POST', - body: formData, - }) + const response = await fetch( + `https://gamegrid-server.onrender.com/api/users/${params.id}/avatar/upload`, + { + method: 'POST', + body: formData, + } + ) const data = await response.json() @@ -220,7 +229,7 @@ export default function ProfilePage({ params }) { return } } - if (!inURL.value !== '') { + if (inURL.value !== '') { if (await !isValidUrl(inURL.value)) { inURL.placeholder = 'URL not valid' inURL.value = '' @@ -247,7 +256,7 @@ export default function ProfilePage({ params }) { window.location.href = '/HomePage/Profile/' + params.id } - const response = await fetch(`http://localhost:3001/api/users/${params.id}/update`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/users/${params.id}/update`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/app/HomePage/Profile/[id]/page.js b/src/app/HomePage/Profile/[id]/page.js index 5ab8251..4999c90 100644 --- a/src/app/HomePage/Profile/[id]/page.js +++ b/src/app/HomePage/Profile/[id]/page.js @@ -18,11 +18,11 @@ export default function ProfilePage({ params }) { setUserId(id) try { const [userResponse, followingResponse] = await Promise.all([ - fetch(`http://localhost:3001/api/users/${params.id}/data`, { + fetch(`https://gamegrid-server.onrender.com/api/users/${params.id}/data`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, }), - fetch(`http://localhost:3001/api/users/${params.id}/list/following`, { + fetch(`https://gamegrid-server.onrender.com/api/users/${params.id}/list/following`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, }), diff --git a/src/app/HomePage/Profile/[id]/stats/page.js b/src/app/HomePage/Profile/[id]/stats/page.js index 031226d..dc809be 100644 --- a/src/app/HomePage/Profile/[id]/stats/page.js +++ b/src/app/HomePage/Profile/[id]/stats/page.js @@ -11,16 +11,19 @@ export default function ProfileStats({ params }) { useEffect(() => { const fetchUserData = async () => { try { - const userResponse = await fetch(`http://localhost:3001/api/users/${params.id}/data`, { + const userResponse = await fetch(`https://gamegrid-server.onrender.com/api/users/${params.id}/data`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, }) const user = await userResponse.json() - const postsResponse = await fetch(`http://localhost:3001/api/posts/${params.id}/posts`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' }, - }) + const postsResponse = await fetch( + `https://gamegrid-server.onrender.com/api/posts/${params.id}/posts`, + { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + } + ) const posts = await postsResponse.json() if (userResponse.ok && postsResponse.ok) { diff --git a/src/app/components/HomeNav.js b/src/app/components/HomeNav.js index 90a6230..d143ee1 100644 --- a/src/app/components/HomeNav.js +++ b/src/app/components/HomeNav.js @@ -21,16 +21,19 @@ export const HomeNav = ({ userId }) => { const userResponse = async () => { try { if (userId) { - const response = await fetch(`http://localhost:3001/api/users/${userId}/data`) + const response = await fetch(`https://gamegrid-server.onrender.com/api/users/${userId}/data`) const userData = await response.json() if (response.ok) { setUsername(userData.nickname) setAvatarPreview(userData.avatar) - const userResponse = await fetch(`http://localhost:3001/api/users/${userId}/data`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' }, - }) + const userResponse = await fetch( + `https://gamegrid-server.onrender.com/api/users/${userId}/data`, + { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + } + ) const user = await userResponse.json() const notList = user.notification.map((notification) => notification.message) setNotifyList(notList) @@ -47,7 +50,7 @@ export const HomeNav = ({ userId }) => { const handleSearch = async () => { try { const response = await fetch( - `http://localhost:3001/api/users/search?text=${encodeURIComponent(searchText)}` + `https://gamegrid-server.onrender.com/api/users/search?text=${encodeURIComponent(searchText)}` ) const searchData = await response.json() @@ -116,10 +119,13 @@ export const HomeNav = ({ userId }) => { const clearNotification = async () => { try { - const response = await fetch(`http://localhost:3001/api/users/${userId}/notification/clear`, { - method: 'DELETE', - headers: { 'Content-Type': 'application/json' }, - }) + const response = await fetch( + `https://gamegrid-server.onrender.com/api/users/${userId}/notification/clear`, + { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + } + ) setNumNotify(0) } catch (error) { console.error(error) diff --git a/src/app/components/followButton.js b/src/app/components/followButton.js index 0fc2327..197c8d5 100644 --- a/src/app/components/followButton.js +++ b/src/app/components/followButton.js @@ -7,9 +7,12 @@ export default function FollowButton({ userId, followId, initialIsFollowing }) { const handleClick = async (followId) => { if (isFollowing) { try { - const response = await fetch(`http://localhost:3001/api/users/${userId}/${followId}/unfollow`, { - method: 'POST', - }) + const response = await fetch( + `https://gamegrid-server.onrender.com/api/users/${userId}/${followId}/unfollow`, + { + method: 'POST', + } + ) const data = await response.json() setIsFollowing(false) // Update the state } catch (error) { @@ -17,13 +20,16 @@ export default function FollowButton({ userId, followId, initialIsFollowing }) { } } else { try { - const response = await fetch(`http://localhost:3001/api/users/${userId}/${followId}/follow`, { - method: 'POST', - }) + const response = await fetch( + `https://gamegrid-server.onrender.com/api/users/${userId}/${followId}/follow`, + { + method: 'POST', + } + ) const data = await response.json() setIsFollowing(true) // Update the state const responseNotify = await fetch( - `http://localhost:3001/api/users/${followId}/${userId}/notification/follow`, + `https://gamegrid-server.onrender.com/api/users/${followId}/${userId}/notification/follow`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, diff --git a/src/app/components/newPost.js b/src/app/components/newPost.js index 5adf18a..0fb09b7 100644 --- a/src/app/components/newPost.js +++ b/src/app/components/newPost.js @@ -52,7 +52,7 @@ export default function NewPost() { return } - const response = await fetch(`http://localhost:3001/api/posts/${userId}/post/insert`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/posts/${userId}/post/insert`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -66,10 +66,13 @@ export default function NewPost() { const ImageData = new FormData() ImageData.append('image', imageFile) - const imageResponse = await fetch(`http://localhost:3001/api/posts/${data.post_id}/files/upload`, { - method: 'POST', - body: ImageData, - }) + const imageResponse = await fetch( + `https://gamegrid-server.onrender.com/api/posts/${data.post_id}/files/upload`, + { + method: 'POST', + body: ImageData, + } + ) const imageResponseData = await imageResponse.json() if (imageResponse.ok) { @@ -85,7 +88,6 @@ export default function NewPost() { image: null, }) setImagePreview(null) // Clear the image preview - alert(JSON.stringify(data)) location.reload() } else { alert(JSON.stringify(data)) diff --git a/src/app/components/posts.js b/src/app/components/posts.js index cc6e889..280014f 100644 --- a/src/app/components/posts.js +++ b/src/app/components/posts.js @@ -22,7 +22,7 @@ export default function Posts({ keyPost, item = null, category = null }) { async function sendNotification(user, clickedId, notType) { const response2 = await fetch( - `http://localhost:3001/api/users/${user}/${clickedId}/notification/${notType}`, + `https://gamegrid-server.onrender.com/api/users/${user}/${clickedId}/notification/${notType}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -34,12 +34,15 @@ export default function Posts({ keyPost, item = null, category = null }) { const fetchPosts = async () => { try { if (keyPost === 'following') { - const response = await fetch(`http://localhost:3001/api/posts/${userId}/${keyPost}/posts`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) + const response = await fetch( + `https://gamegrid-server.onrender.com/api/posts/${userId}/${keyPost}/posts`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + } + ) const data = await response.json() if (response.ok) { setPosts(data.posts_list) @@ -48,7 +51,7 @@ export default function Posts({ keyPost, item = null, category = null }) { } if (keyPost === 'all') { - const response = await fetch(`http://localhost:3001/api/posts/${keyPost}posts`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/posts/${keyPost}posts`, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -91,7 +94,7 @@ export default function Posts({ keyPost, item = null, category = null }) { } if (keyPost === 'MyPost') { - const response = await fetch(`http://localhost:3001/api/posts/${userId}/posts`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/posts/${userId}/posts`, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -106,7 +109,7 @@ export default function Posts({ keyPost, item = null, category = null }) { } } if (keyPost === 'MySaved') { - const response = await fetch(`http://localhost:3001/api/posts/${userId}/saved`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/posts/${userId}/saved`, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -121,7 +124,7 @@ export default function Posts({ keyPost, item = null, category = null }) { } if (keyPost === 'MyLiked') { - const response = await fetch(`http://localhost:3001/api/posts/${userId}/liked`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/posts/${userId}/liked`, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -135,7 +138,7 @@ export default function Posts({ keyPost, item = null, category = null }) { } else { } } else if (keyPost !== 'all' && keyPost !== 'MySaved') { - const response = await fetch(`http://localhost:3001/api/posts/${keyPost}/posts`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/posts/${keyPost}/posts`, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -192,15 +195,18 @@ export default function Posts({ keyPost, item = null, category = null }) { if (isSaved) { // User already saved the post, remove the save - response = await fetch(`http://localhost:3001/api/posts/${post._id}/${userId}/unsave`, { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - }, - }) + response = await fetch( + `https://gamegrid-server.onrender.com/api/posts/${post._id}/${userId}/unsave`, + { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + } + ) } else { // User has not saved the post yet, add the save - response = await fetch(`http://localhost:3001/api/posts/${post._id}/${userId}/save`, { + response = await fetch(`https://gamegrid-server.onrender.com/api/posts/${post._id}/${userId}/save`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -256,7 +262,7 @@ export default function Posts({ keyPost, item = null, category = null }) { } } - const response = await fetch(`http://localhost:3001/api/posts/${userId}/post/share`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/posts/${userId}/post/share`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -288,7 +294,7 @@ export default function Posts({ keyPost, item = null, category = null }) { const handleDeleteClick = async (postId) => { try { - const response = await fetch(`http://localhost:3001/api/posts/${postId}/post/delete`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/posts/${postId}/post/delete`, { method: 'DELETE', }) if (response.ok) { @@ -316,7 +322,7 @@ export default function Posts({ keyPost, item = null, category = null }) { const handleSaveEdit = async (index) => { const post = updatedPosts[index] try { - const response = await fetch(`http://localhost:3001/api/posts/${post._id}/post/update`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/posts/${post._id}/post/update`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ @@ -361,7 +367,7 @@ export default function Posts({ keyPost, item = null, category = null }) { // User already liked the post, remove the like try { const response = await fetch( - `http://localhost:3001/api/posts/${posts[postIndex]._id}/${userId}/unlike`, + `https://gamegrid-server.onrender.com/api/posts/${posts[postIndex]._id}/${userId}/unlike`, { method: 'GET', headers: { @@ -384,7 +390,7 @@ export default function Posts({ keyPost, item = null, category = null }) { // Send the updated like status to the server try { const response = await fetch( - `http://localhost:3001/api/posts/${posts[postIndex]._id}/${userId}/like`, + `https://gamegrid-server.onrender.com/api/posts/${posts[postIndex]._id}/${userId}/like`, { method: 'GET', headers: { @@ -417,7 +423,7 @@ export default function Posts({ keyPost, item = null, category = null }) { if (post?.shared) { try { const response = await fetch( - `http://localhost:3001/api/posts/${post.shared_post.original_post}/post`, + `https://gamegrid-server.onrender.com/api/posts/${post.shared_post.original_post}/post`, { method: 'GET', headers: { @@ -443,7 +449,7 @@ export default function Posts({ keyPost, item = null, category = null }) { try { const og_userResponse = await fetch( - `http://localhost:3001/api/users/${post.shared_post.original_owner}/data` + `https://gamegrid-server.onrender.com/api/users/${post.shared_post.original_owner}/data` ) const original_data = await og_userResponse.json() @@ -460,7 +466,9 @@ export default function Posts({ keyPost, item = null, category = null }) { } try { - const userResponse = await fetch(`http://localhost:3001/api/users/${post.user_id}/data`) + const userResponse = await fetch( + `https://gamegrid-server.onrender.com/api/users/${post.user_id}/data` + ) const userData = await userResponse.json() if (userResponse.ok) { diff --git a/src/app/login/page.js b/src/app/login/page.js index 64039f4..be0e5e1 100644 --- a/src/app/login/page.js +++ b/src/app/login/page.js @@ -22,7 +22,7 @@ export default function Login() { //delay for loading components // await new Promise((resolve) => setTimeout(resolve, 2000)) // שליחת בקשת POST לשרת - const response = await fetch(`http://localhost:3001/api/login/${input}`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/login/${input}`, { method: 'GET', headers: { 'Content-Type': 'application/json', diff --git a/src/app/register/page.js b/src/app/register/page.js index 9a20623..d08e944 100644 --- a/src/app/register/page.js +++ b/src/app/register/page.js @@ -67,7 +67,7 @@ export default function Register() { return } // שליחת בקשת POST לשרת - const response = await fetch(`http://localhost:3001/api/users/insert`, { + const response = await fetch(`https://gamegrid-server.onrender.com/api/users/insert`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/app/toBeContinued/page.js b/src/app/toBeContinued/page.js new file mode 100644 index 0000000..28e23ab --- /dev/null +++ b/src/app/toBeContinued/page.js @@ -0,0 +1,30 @@ +'use client' +// import Header from '../components/topBar' +// import { useEffect, useState } from 'react' +export default function toBeContinued() { + // const [data, setData] = useState(null) + + // useEffect(() => { + // const fetchData = async () => { + // // const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/about`) + // const res = await fetch('https://gamegrid-server.onrender.com//api/about') + // const json = await res.json() + // setData(json) + // } + + // fetchData() + // }, []) + + // if (!data) { + // document.getElementById('data').innerHTML = 'Loading...' + // } + return ( +
+
+

Header

+

******** to be continue ********

+

Some information about us.

+
+
+ ) +}