612d542c06
- Create useCloudConnectionsStore with connections/loading/error refs - fetchConnections, disconnect(id), disconnectAll() actions - Append listCloudConnections, disconnectCloud, connectWebDav, updateDefaultStorage to api/client.js - Add vitest test script to package.json - 4 unit tests passing (W4 — CLAUDE.md)
40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
import * as api from '../api/client.js'
|
|
|
|
export const useCloudConnectionsStore = defineStore('cloudConnections', () => {
|
|
const connections = ref([])
|
|
const loading = ref(false)
|
|
const error = ref(null)
|
|
|
|
async function fetchConnections() {
|
|
loading.value = true
|
|
error.value = null
|
|
try {
|
|
const data = await api.listCloudConnections()
|
|
connections.value = data.items ?? []
|
|
} catch (e) {
|
|
error.value = e.message || 'Failed to load cloud connections'
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function disconnect(id) {
|
|
try {
|
|
await api.disconnectCloud(id)
|
|
connections.value = connections.value.filter(c => c.id !== id)
|
|
} catch (e) {
|
|
throw e
|
|
}
|
|
}
|
|
|
|
async function disconnectAll() {
|
|
const ids = connections.value.map(c => c.id)
|
|
for (const id of ids) await disconnect(id)
|
|
connections.value = []
|
|
}
|
|
|
|
return { connections, loading, error, fetchConnections, disconnect, disconnectAll }
|
|
})
|