mirror of
https://github.com/acedanger/finance.git
synced 2025-12-05 22:50:12 -08:00
#1 Update index.astro to fetch accounts from API endpoint
This commit is contained in:
@@ -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 ---
|
||||
|
||||
Reference in New Issue
Block a user