git-proxy / src /stores /accountStorage.ts
github-actions[bot]
Update from GitHub Actions
15ff6c7
raw
history blame
738 Bytes
import { defineStore } from 'pinia'
import { accountApi, type Account } from '../services/accountApi'
export const useAccountStore = defineStore('server', {
state: () => ({
accounts: [] as Account[],
initialized: false
}),
actions: {
async fetchAccounts(force = false) {
if (!force && this.initialized) return;
try {
const data = await accountApi.get();
this.accounts = Array.isArray(data) ? data : [];
this.initialized = true;
} catch (error) {
console.error('Failed to fetch accounts:', error);
this.accounts = [];
}
},
updateAccounts(newAccounts: Account[]) {
this.accounts = Array.isArray(newAccounts) ? newAccounts : [];
}
}
})