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