Files
boursecu_user/src/views/base/home/composables/useUserFunds.ts
T
safavimohadeseh78andCursor a5e458ed25 Split desktop and mobile layouts with shared page data so APIs fetch once per context.
Add layout shells, desktop views, module-level page caches, and UI fixes for auth, home, wallet, transactions, address, and related pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-14 10:08:46 +03:30

55 lines
1.1 KiB
TypeScript

import { ref } from 'vue'
import { useFundUserStore } from '@/store/fundStore'
/** Module-level fund list — shared across home layout variants. */
const funds = ref<unknown[]>([])
const fundsLoading = ref(false)
let fundsPromise: Promise<void> | null = null
let fundsLoaded = false
async function fetchFunds(force = false) {
if (!force && fundsLoaded) {
return
}
if (!force && fundsPromise) {
return fundsPromise
}
const fundStore = useFundUserStore()
fundsPromise = (async () => {
try {
fundsLoading.value = true
const result = await fundStore.getMyFund()
funds.value = result?.rows || []
fundsLoaded = true
} catch (error) {
console.error('Error loading funds:', error)
} finally {
fundsLoading.value = false
fundsPromise = null
}
})()
return fundsPromise
}
export function useUserFunds() {
return {
funds,
loading: fundsLoading,
loadFunds: fetchFunds,
}
}
export function loadHomeFunds(force = false) {
return fetchFunds(force)
}
export function resetHomeFunds() {
funds.value = []
fundsLoaded = false
fundsPromise = null
}