Skip to content

Commit

Permalink
Adjust Dashboard to remove redundant api call
Browse files Browse the repository at this point in the history
  • Loading branch information
JJtan2002 committed Jun 26, 2024
1 parent f1e2222 commit bc38cf9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions frontend/src/pages/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Dashboard = () => {
// Get the date 5 days ago
const fiveDaysAgo = new Date(today);
fiveDaysAgo.setDate(today.getDate() - 5);

// Update state with formatted dates
setDates({ today: today, fiveDaysAgo: fiveDaysAgo });
}, []);
Expand All @@ -64,7 +64,7 @@ const Dashboard = () => {
queryKey: ["api/wallet"],
queryFn: () => getWallet(),
});

const {
refetch: refetchExpenses,
data: expenses,
Expand Down Expand Up @@ -98,6 +98,7 @@ const Dashboard = () => {
/*startDate:*/ dateForDisplay.fiveDaysAgo,
/*endDate:*/ dateForDisplay.today,
),
enabled: !!dateForDisplay.fiveDaysAgo && !!dateForDisplay.today,
})

const {
Expand All @@ -113,7 +114,7 @@ const Dashboard = () => {
dateForDisplay.fiveDaysAgo,
dateForDisplay.today,
),
})
})


var barData = {
Expand Down Expand Up @@ -146,7 +147,7 @@ const Dashboard = () => {
],
};
}

var pieData = {
labels: ['Rent', 'Groceries', 'Utilities', 'Entertainment', 'Transport', 'Others'],
datasets: [
Expand Down Expand Up @@ -224,6 +225,8 @@ const Dashboard = () => {
await deleteTransaction(transactionId);
await refetchWallet();
await refetchExpenses();
await refetchBardata();
await refetchPiedata();
toast.warning("Transaction deleted!");
};

Expand Down Expand Up @@ -353,7 +356,7 @@ const Dashboard = () => {
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>

{loading ? (
<p>Loading...</p>
) : expenses && (
Expand Down

0 comments on commit bc38cf9

Please sign in to comment.