import { getDocs, collection, getFirestore } from 'firebase/firestore' export const useUsersStore = defineStore('users', () => { const ledenlijst = ref([]) const users = ref([]) const db = getFirestore() const getLedenlijst = async () => { if (ledenlijst[0]) return; try { const querySnapshot = await getDocs(collection(db, "ledenlijst")); querySnapshot.forEach((doc) => { ledenlijst.value.push(doc.data()) }); } catch (e) { console.log(e) } ledenlijst.value.sort((a, b) => a.fullName.localeCompare(b.fullName)) } const getUsers = async () => { if (users.value[0]) return try { const querySnapshot = await getDocs(collection(db, "users")); querySnapshot.forEach((doc) => { users.value.push(doc.data()) }); } catch (e) { console.log(e) } } return { ledenlijst, users, getLedenlijst, getUsers } });