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

chore(performance): ajuste de performance #31

Merged
merged 1 commit into from
Nov 6, 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
10 changes: 5 additions & 5 deletions src/components/NewTransaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export const NewTransactionModal = () => {

reset()

toast.success('Transação cadastrada', {
duration: 5000,
position: 'top-left',
})

if (fetchTransactions) {
await fetchTransactions()

toast.success('Transação cadastrada', {
duration: 5000,
position: 'top-left',
})
}
} catch (error) {
toast.error('Não foi possível cadastrar transação', {
Expand Down
1 change: 0 additions & 1 deletion src/components/NewTransaction/newTransaction.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { render, waitFor } from '@testing-library/react'

import { NewTransactionModal } from './index'
import { api } from '../../lib/api'
// import toast from 'react-hot-toast'

const mockDialogContext = {
openDialog: jest.fn(),
Expand Down
44 changes: 42 additions & 2 deletions src/components/NewTransaction/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const Overlay = styled(Dialog.Overlay)`
width: 100vw;
height: 100vh;
inset: 0;
background: #00000074;
background: #00000094;
`

export const Content = styled(Dialog.Content)`
Expand All @@ -22,6 +22,13 @@ export const Content = styled(Dialog.Content)`
left: 50%;
transform: translate(-50%, -50%);

h2 {
@media (max-width: 768px) {
font-size: 1.25rem;
line-height: 160%;
}
}

form {
margin-top: 2rem;
display: flex;
Expand All @@ -38,6 +45,12 @@ export const Content = styled(Dialog.Content)`
&::placeholder {
color: ${(props) => props.theme['gray-500']};
}

@media (max-width: 768px) {
font-size: 1rem;
font-weight: 400;
line-height: 140%;
}
}

button[type='submit'] {
Expand All @@ -60,11 +73,25 @@ export const Content = styled(Dialog.Content)`
background: ${(props) => props.theme['green-700']};
transition: background-color 0.2s;
}

@media (max-width: 768px) {
display: flex;
padding: 12px 20px;
justify-content: center;
align-items: center;
gap: 0.625rem;

font-size: 1rem;
font-weight: 700;
line-height: 160%;
}
}
}

@media (max-width: 768px) {
min-width: 22rem;
min-width: 23.5rem;
border-radius: 20px 20px 20px 20px;
box-shadow: 0px -4px 32px 0px rgba(0, 0, 0, 0.8);
}
`

Expand Down Expand Up @@ -132,4 +159,17 @@ export const TransactionTypeButton = styled(
color: ${(props) => props.theme.white};
}
}

@media (max-width: 768px) {
display: flex;
padding: 1rem 1.5rem;
justify-content: center;
align-items: center;
gap: 8px;
flex: 1 0 0;

font-size: 1rem;
font-weight: 400;
line-height: 160%;
}
`
2 changes: 1 addition & 1 deletion src/components/SearchForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const SearchForm = () => {
await fetchTransactions(query)
}

console.log(query)
return null
}

return (
Expand Down
6 changes: 0 additions & 6 deletions src/context/TransactionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ export const TransactionsProvider = ({
},
})

toast.success('Sucesso na solicitação das transações', {
duration: 5000,
position: 'top-left',
})

setTransactions(response.data)
} catch (error) {
toast.error('Erro na solicitação das transações', {
Expand All @@ -41,7 +36,6 @@ export const TransactionsProvider = ({
})

if (axios.isAxiosError(error)) {
// Erro relacionado ao Axios
const axiosError = error as AxiosError

if (axiosError.response) {
Expand Down
43 changes: 22 additions & 21 deletions src/hooks/useSummary.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import { useContext } from 'react'
import { useContext, useMemo } from 'react'
import { TransactionsContext } from '../context/TransactionContext'

export const useSummary = () => {
const { transactions } = useContext(TransactionsContext)

const summary = transactions
? transactions.reduce(
(accumulator, transaction) => {
if (transaction.expense === 'income') {
accumulator.income += transaction.price
accumulator.total += transaction.price
} else {
accumulator.outcome += transaction.price
accumulator.total -= transaction.price
}

return accumulator
},
{
income: 0,
outcome: 0,
total: 0,
},
)
: null
const summary = useMemo(() => {
return transactions
? transactions.reduce(
(accumulator, transaction) => {
if (transaction.expense === 'income') {
accumulator.income += transaction.price
accumulator.total += transaction.price
} else {
accumulator.outcome += transaction.price
accumulator.total -= transaction.price
}

return accumulator
},
{
income: 0,
outcome: 0,
total: 0,
},
)
: null
}, [transactions])
return summary
}
Loading