Added libs
This commit is contained in:
57
noSys/vue/stores/noSysStore.js
Normal file
57
noSys/vue/stores/noSysStore.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useNoSysStore = defineStore('noSysStore', {
|
||||
state: () => ({
|
||||
users: [], // [{ publicKey }]
|
||||
connections: [], // [{ publicKey, connectedAt, network }]
|
||||
networks: [],
|
||||
}),
|
||||
|
||||
getters: {
|
||||
getUserByKey: (state) => (key) => {
|
||||
return state.users.find(u => u.publicKey === key)
|
||||
},
|
||||
getConnectionsByNetwork: (state) => (network) => {
|
||||
return state.connections.filter(c => c.network === network)
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
addUser(user) {
|
||||
if (!this.users.find(u => u.publicKey === user.publicKey)) {
|
||||
this.users.push(user)
|
||||
}
|
||||
},
|
||||
|
||||
removeUser(publicKey) {
|
||||
this.users = this.users.filter(u => u.publicKey !== publicKey)
|
||||
},
|
||||
|
||||
updateUser(updated) {
|
||||
const index = this.users.findIndex(u => u.publicKey === updated.publicKey)
|
||||
if (index !== -1) this.users[index] = { ...this.users[index], ...updated }
|
||||
},
|
||||
|
||||
addConnection(conn) {
|
||||
const exists = this.connections.find(
|
||||
c => c.publicKey === conn.publicKey && c.network === conn.network
|
||||
)
|
||||
if (!exists) {
|
||||
this.connections.push({
|
||||
...conn,
|
||||
connectedAt: conn.connectedAt || new Date().toISOString(),
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
removeConnection(publicKey, network = null) {
|
||||
this.connections = this.connections.filter(
|
||||
c => c.publicKey !== publicKey || (network && c.network !== network)
|
||||
)
|
||||
},
|
||||
|
||||
clearConnections() {
|
||||
this.connections = []
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user