Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge new features into main #2

Merged
merged 7 commits into from
Nov 13, 2023
Merged
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
14 changes: 4 additions & 10 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:react-hooks/recommended'],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'@typescript-eslint/no-unused-vars': 0,
},
}
};
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/svg+xml" href="favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,[email protected],300;9..40,400;9..40,500;9..40,600;9..40,700&family=Poppins:wght@400;500;600;700&display=swap"
Expand Down
20 changes: 19 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@hookform/resolvers": "^3.3.2",
"@mui/icons-material": "^5.14.16",
"@mui/material": "^5.14.16",
"@radix-ui/react-avatar": "^1.0.4",
Expand All @@ -27,7 +28,8 @@
"react-icons": "^4.11.0",
"react-router-dom": "^6.18.0",
"styled-components": "^6.1.0",
"vite-tsconfig-paths": "^4.2.1"
"vite-tsconfig-paths": "^4.2.1",
"zod": "^3.22.4"
},
"devDependencies": {
"@babel/plugin-transform-private-property-in-object": "^7.22.11",
Expand Down
Binary file added public/favicon.ico
Binary file not shown.
1 change: 0 additions & 1 deletion public/vite.svg

This file was deleted.

148 changes: 78 additions & 70 deletions src/components/CreateListModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { useContext, useEffect, useState } from 'react';
import { Backdrop, Modal } from '@mui/material';
import { FieldValues, SubmitHandler, useForm } from 'react-hook-form';
import TextField from '@mui/material/TextField';
import { Button } from '@mui/material';
import CircularProgress from '@mui/material/CircularProgress';

import { Container, Form, GameList } from './styles';
import { Container, Form, GameList, Input, Button } from './styles';
import { GameCoverImageSizes, IGame } from '../types';

import { GameCard } from './GameCard';
import apiCaller from '@/src/services/api';
import { AuthContext } from '@/src/contexts/auth';
import { NotificationSnackbar } from '../NotificationSnackbar';

interface CreateListModalProps {
isCreateListModalOpen: boolean;
Expand All @@ -27,6 +26,7 @@ export function CreateListModal({ isCreateListModalOpen, handleCreateListModal }

const [games, setGames] = useState<IGame[]>([]);
const [selectedGames, setSelectedGames] = useState<IGame[]>([]);
const [isListCreated, setIsListCreated] = useState(false);

const handleCreateCustomList: SubmitHandler<FieldValues> = async data => {
const { name } = data as FormData;
Expand All @@ -38,8 +38,7 @@ export function CreateListModal({ isCreateListModalOpen, handleCreateListModal }
const token = localStorage.getItem('@Auth:token');

if (token) {
const parsed: string = JSON.parse(token);
apiCaller.defaults.headers.common.Authorization = `Bearer ${parsed}`;
apiCaller.defaults.headers.common.Authorization = `Bearer ${token}`;
}

const payload = {
Expand All @@ -50,7 +49,10 @@ export function CreateListModal({ isCreateListModalOpen, handleCreateListModal }

apiCaller
.post('/lists', payload)
.then(response => console.log(response))
.then(_response => {
setIsListCreated(true);
setSelectedGames([]);
})
.catch(error => console.log(error));
};

Expand All @@ -68,6 +70,10 @@ export function CreateListModal({ isCreateListModalOpen, handleCreateListModal }
}
}

function handleCloseSnackbar() {
setIsListCreated(false);
}

useEffect(() => {
apiCaller
.get('/games/most-popular')
Expand All @@ -87,72 +93,74 @@ export function CreateListModal({ isCreateListModalOpen, handleCreateListModal }
}, []);

return (
<Modal
open={isCreateListModalOpen}
onClose={() => handleCreateListModal(false)}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
slots={{
backdrop: Backdrop,
}}
>
<Container>
<h1>Crie sua lista</h1>

<Form onSubmit={handleSubmit(handleCreateCustomList)}>
<TextField
{...register('name')}
id="outlined-basic"
variant="outlined"
<>
<Modal
open={isCreateListModalOpen}
onClose={() => handleCreateListModal(false)}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
slots={{
backdrop: Backdrop,
}}
>
<Container>
<h1>Crie sua lista</h1>

<Form onSubmit={handleSubmit(handleCreateCustomList)}>
<Input {...register('name')} type="text" placeholder="Nome da lista" />
<Button type="submit" disabled={selectedGames.length === 0}>
Criar
</Button>
</Form>

<Input
type="text"
placeholder="Nome da lista"
placeholder="Buscar por jogo"
disabled={games.length == 0}
style={{
width: '80%',
marginBottom: '1.5rem',
}}
/>
<Button variant="contained" type="submit" disabled={selectedGames.length === 0}>
Criar
</Button>
</Form>

<TextField
id="outlined-basic"
variant="outlined"
type="text"
color="info"
placeholder="Buscar por jogo"
sx={{
width: '80%',
}}
disabled={games.length == 0}
<GameList>
{games.length == 0 && (
<CircularProgress
color="secondary"
sx={{
alignSelf: 'center',
}}
size={'4rem'}
/>
)}

{games &&
games.map(game => {
return (
<GameCard
key={game.slug}
slug={game.slug}
title={game.name}
originInfo={game.name}
cover={game.cover}
genres={game.name}
rating={game.rating}
handleSelectGame={handleSelectGame}
isSelected={!!selectedGames.find(selectedGame => selectedGame.slug === game.slug)}
/>
);
})}
</GameList>
</Container>
</Modal>

{isListCreated && (
<NotificationSnackbar
type="success"
message="Lista criada com sucesso"
handleClose={handleCloseSnackbar}
isSnackbarOpen={isListCreated}
/>

<GameList>
{games.length == 0 && (
<CircularProgress
color="secondary"
sx={{
alignSelf: 'center',
}}
size={'4rem'}
/>
)}

{games &&
games.map(game => {
return (
<GameCard
key={game.slug}
slug={game.slug}
title={game.name}
originInfo={game.name}
cover={game.cover}
genres={game.name}
rating={game.rating}
handleSelectGame={handleSelectGame}
isSelected={!!selectedGames.find(selectedGame => selectedGame.slug === game.slug)}
/>
);
})}
</GameList>
</Container>
</Modal>
)}
</>
);
}
55 changes: 45 additions & 10 deletions src/components/CreateListModal/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ export const Container = styled.div`
background-color: #101418;
border-radius: 15px;
padding: 12px;

h1 {
margin-top: 1rem;
margin-bottom: 2rem;
font-weight: 500;
}
`;

export const Form = styled.form`
display: flex;
gap: 10px;
justify-content: center;
gap: 20px;
margin-bottom: 2rem;

label {
color: #fff;
}

input {
width: 100%;
color: #fff;
}
width: 100%;
`;

export const GameList = styled.div`
Expand All @@ -43,3 +42,39 @@ export const GameList = styled.div`
margin-bottom: 20px;
overflow: auto;
`;

export const Input = styled.input`
width: 50%;
background-color: transparent;
border: none;
outline: none;
color: #f5f5f5;
outline: 2px solid ;
border-radius: 4px;
padding: 12px;
outline: 2px solid #1F2937;

&:focus {
outline: 2px solid #1D4ED8;
}
`;

export const Button = styled.button`
background-color: #1D4ED8;
padding: 14px 20px;
color: #f5f5f5;
border: none;
outline: none;
border-radius: 4px;
cursor: pointer;
text-transform: uppercase;

&:not(:disabled):hover {
background-color: #2563EB;
}

&:disabled {
opacity: 0.4;
cursor: not-allowed;
}
`;
Loading