mirror of
https://github.com/acedanger/finance.git
synced 2025-12-06 07:00:13 -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 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 ---
|
||||||
|
|||||||
Reference in New Issue
Block a user