Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 36 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 1 addition & 1 deletion src/app/HomePage/LeaderBoard/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/HomePage/Profile/[id]/Like/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
})
Expand Down
2 changes: 1 addition & 1 deletion src/app/HomePage/Profile/[id]/Save/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
})
Expand Down
39 changes: 24 additions & 15 deletions src/app/HomePage/Profile/[id]/edit/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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' },
})
Expand Down Expand Up @@ -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' },
})
Expand All @@ -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)
Expand All @@ -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()
}
Expand All @@ -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()

Expand Down Expand Up @@ -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 = ''
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/app/HomePage/Profile/[id]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
}),
Expand Down
13 changes: 8 additions & 5 deletions src/app/HomePage/Profile/[id]/stats/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
26 changes: 16 additions & 10 deletions src/app/components/HomeNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
20 changes: 13 additions & 7 deletions src/app/components/followButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ 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) {
console.error('Error unfollowing user:', error)
}
} 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' },
Expand Down
Loading