From 05d13e56205fa146e64fbd81b563431c136f38fe Mon Sep 17 00:00:00 2001 From: Methapon-Frappet Date: Sat, 13 Apr 2024 16:50:06 +0700 Subject: [PATCH] refactor: add map to contact store --- src/stores/branch-contact/index.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/stores/branch-contact/index.ts b/src/stores/branch-contact/index.ts index dbdb7fc9..b852a784 100644 --- a/src/stores/branch-contact/index.ts +++ b/src/stores/branch-contact/index.ts @@ -1,12 +1,26 @@ import axios from 'axios'; -import { ref } from 'vue'; +import { ref, watch } from 'vue'; import { defineStore } from 'pinia'; import { BranchContact, BranchContactCreate } from './types'; import { Pagination } from '../types'; import { api } from 'src/boot/axios'; +type BranchContactId = string; + const useBranchContactStore = defineStore('api-branch-contact', () => { - const data = ref>(); + const data = ref>({ + result: [], + page: 0, + pageSize: 0, + total: 0, + }); + const map = ref>({}); + + watch(data, () => { + data.value.result.forEach((v) => { + map.value[v.id] = v; + }); + }); async function fetchList( branchId: string, @@ -146,6 +160,8 @@ const useBranchContactStore = defineStore('api-branch-contact', () => { } return { + data, + map, fetchList, create, editById,