#1 Update index.astro to fetch accounts from API endpoint

This commit is contained in:
GitHub Copilot
2025-04-23 21:33:53 -04:00
parent c0ac85ee7c
commit 98b29ff58b

View File

@@ -5,12 +5,12 @@ import MainContent from '../components/MainContent.astro';
import type { Account, Transaction } from '../types';
import { formatCurrency, formatDate } from '../utils';
// Initialize with empty arrays until API integration
const accounts: Account[] = [];
const allTransactions: Transaction[] = [];
// Fetch accounts from API
const accountsResponse = await fetch('http://localhost:4321/api/accounts');
const accounts: Account[] = await accountsResponse.json();
// Create an empty initial account
const initialAccount: Account = {
// Initialize with first account or empty account if none exist
const initialAccount: Account = accounts[0] || {
id: '',
name: 'No accounts available',
last4: '0000',
@@ -25,7 +25,7 @@ const initialTransactions: Transaction[] = [];
</div>
</BaseLayout>
<script define:vars={{ allAccounts: accounts, allTransactions }}>
<script define:vars={{ allAccounts: accounts, allTransactions: initialTransactions }}>
// Client-side script to handle account switching and updating the UI
// --- DOM Elements ---