diff --git a/src/components/Dashboard/TableHead/index.tsx b/src/components/Dashboard/TableHead/index.tsx
index dcf0678..c2acfb1 100644
--- a/src/components/Dashboard/TableHead/index.tsx
+++ b/src/components/Dashboard/TableHead/index.tsx
@@ -1,16 +1,20 @@
import * as Table from '../../Table'
+import { useResponsiveness } from '../../../hook/useResponsiveness'
type TableHeadProps = {
- isMobile: boolean
transactionsTotal: number
}
-export function TableHead({ isMobile, transactionsTotal }: TableHeadProps) {
+export function TableHead({ transactionsTotal }: TableHeadProps) {
+ const { isMobile } = useResponsiveness()
+
if (isMobile) {
return (
<>
Transações
- {transactionsTotal} items
+
+ {transactionsTotal} items
+
>
)
}
diff --git a/src/components/Dashboard/TableRows/index.tsx b/src/components/Dashboard/TableRows/index.tsx
index fca7528..e54e0ad 100644
--- a/src/components/Dashboard/TableRows/index.tsx
+++ b/src/components/Dashboard/TableRows/index.tsx
@@ -2,15 +2,19 @@ import { FiTrash } from 'react-icons/fi'
import * as Table from '../../Table'
import { Button } from '../../Button'
+import { Loading } from '../../Loading'
import { useTransactions } from '../../../hook/useTransactions'
+import { useResponsiveness } from '../../../hook/useResponsiveness'
import { dateFormatter, priceFormatter } from '../../../utils/formatter'
-type TableRows = {
- isMobile: boolean
-}
+export function TableRows() {
+ const { isMobile } = useResponsiveness()
-export function TableRows({ isMobile }: TableRows) {
- const { transactions, handleRemoveTransactionById } = useTransactions()
+ const {
+ transactions,
+ handleRemoveTransactionById,
+ isDeleteTransactionLoading,
+ } = useTransactions()
return transactions.map((transaction) => {
const dataFormatted = dateFormatter.format(new Date(transaction.date))
@@ -18,6 +22,19 @@ export function TableRows({ isMobile }: TableRows) {
const priceFormattedWithSignalOrNot =
transaction.type === 'outcome' ? `- ${priceFormatted}` : priceFormatted
+ const isLoadingIcon =
+ isDeleteTransactionLoading.id === transaction.id &&
+ isDeleteTransactionLoading.value
+
+ const buttonIcon = isLoadingIcon ? (
+
+ ) : (
+
+ )
+
return (
{isMobile ? (
@@ -29,10 +46,11 @@ export function TableRows({ isMobile }: TableRows) {
@@ -59,10 +77,11 @@ export function TableRows({ isMobile }: TableRows) {
>
diff --git a/src/components/Dashboard/index.tsx b/src/components/Dashboard/index.tsx
index 12e1029..85178cb 100644
--- a/src/components/Dashboard/index.tsx
+++ b/src/components/Dashboard/index.tsx
@@ -1,4 +1,3 @@
-import { useEffect, useState } from 'react'
import { useAutoAnimate } from '@formkit/auto-animate/react'
import * as Table from '../Table'
@@ -10,9 +9,6 @@ import { useTransactions } from '../../hook/useTransactions'
export function Dashboard() {
const [parent] = useAutoAnimate()
- const [currentBrowserWidth, setCurrentBrowserWidth] = useState(0)
- const isMobile = currentBrowserWidth < 640
-
const {
transactions,
balance,
@@ -25,24 +21,12 @@ export function Dashboard() {
const transactionsTotal = transactions.length
- function onUpdateCurrentBrowserWidth() {
- setCurrentBrowserWidth(window.innerWidth)
- }
-
- useEffect(() => {
- window.addEventListener('resize', onUpdateCurrentBrowserWidth)
- return () => {
- window.removeEventListener('resize', onUpdateCurrentBrowserWidth)
- }
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [])
-
return (