2026-05-14 13:44:43 +03:30
|
|
|
import { ref } from 'vue'
|
|
|
|
|
import { useFundUserStore } from '@/store/fundStore'
|
|
|
|
|
|
2026-06-14 10:08:46 +03:30
|
|
|
/** 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
|
2026-05-14 13:44:43 +03:30
|
|
|
|
2026-06-14 10:08:46 +03:30
|
|
|
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
|
2026-05-14 13:44:43 +03:30
|
|
|
}
|
2026-06-14 10:08:46 +03:30
|
|
|
})()
|
2026-05-14 13:44:43 +03:30
|
|
|
|
2026-06-14 10:08:46 +03:30
|
|
|
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
|
|
|
|
|
}
|