Skip to content

Commit 9bbdebb

Browse files
committed
feat(useVaultStore): add updateCollaborator function
1 parent 7b61259 commit 9bbdebb

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

resources/js/stores/vault.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,23 @@ export const useVaultStore = defineStore('vault', () => {
2525
collaborators.value.push(collaborator);
2626
}
2727

28+
function updateCollaborator(collaborator: VaultCollaborator): void {
29+
const index = collaborators.value.findIndex(c => c.id === collaborator.id);
30+
31+
if (index === -1) {
32+
addCollaborator(collaborator);
33+
34+
return;
35+
}
36+
37+
collaborators.value[index] = {
38+
...collaborators.value[index],
39+
...collaborator,
40+
};
41+
}
42+
2843
function removeCollaborator(userId: number): void {
29-
collaborators.value = collaborators.value.filter(
30-
collaborator => collaborator.id !== userId
31-
);
44+
collaborators.value = collaborators.value.filter(c => c.id !== userId);
3245
}
3346

3447
return {
@@ -39,6 +52,7 @@ export const useVaultStore = defineStore('vault', () => {
3952
setVault,
4053
updateVault,
4154
addCollaborator,
55+
updateCollaborator,
4256
removeCollaborator,
4357
};
4458
});

0 commit comments

Comments
 (0)