{"version":3,"file":"List-BuO_cirg.js","sources":["../../../app/frontend/stores/List.js"],"sourcesContent":["import { defineStore } from 'pinia';\nimport Client from \"@/utils/client\";\n\nconst sharedState = {\n lists: [],\n currentList: {\n id: null,\n name: null,\n user_owner: false,\n profiles: []\n },\n currentProfile: {\n id: null,\n name: null\n }\n};\n\nexport default defineStore('ListStore', {\n state: () => sharedState,\n actions: {\n async addProfile(id, params) {\n const response = await Client.post(`/profile/lists/${id}/add_to_list`, params);\n const index = this.lists.findIndex(o=>o.id===id);\n \n this.lists[index] = await response.json();\n },\n async removeProfile(id, params) {\n const response = await Client.post(`/profile/lists/${id}/remove_from_list`, params);\n\n if (CURRENT_PAGE == 'lists#show') {\n const index = this.currentList.profiles.findIndex(o=>o.id===id);\n this.currentList.profiles.splice(index, 1);\n } else {\n const index = this.lists.findIndex(o=>o.id===id);\n this.lists[index] = await response.json();\n }\n },\n async fetchList(id) {\n const response = await Client.get(`/profile/lists/${id}`);\n this.currentList = await response.json();\n },\n async fetchLists() {\n const response = await Client.get('/profile/lists/');\n this.lists = await response.json();\n },\n async createList(params) {\n const response = await Client.post('/profile/lists/', params);\n const list = await response.json();\n\n this.lists.push(list);\n\n if (this.currentProfile.id) {\n await this.addProfile(list.id, {\n profile_id: this.currentProfile.id\n });\n }\n },\n async renameList(id=null, params) {\n const url = `/profile/lists/${id}`\n const response = await Client.patch(url, params);\n const data = await response.json();\n\n if (CURRENT_PAGE == 'lists#index') {\n const index = this.lists.findIndex(o=>o.id==id);\n this.lists[index] = data;\n } else {\n this.currentList.name = data.name;\n }\n },\n async deleteList(id=null) {\n const url = `/profile/lists/${id}`;\n await Client.delete(url);\n\n if (CURRENT_PAGE == 'lists#index') {\n const index = this.lists.findIndex(o=>o.id===id);\n this.lists.splice(index, 1);\n }\n },\n setCurrentList(list) {\n this.currentList.id = list.id;\n this.currentList.name = list.name;\n },\n setCurrentProfile(profile) {\n this.currentProfile.id = profile.id;\n this.currentProfile.name = profile.full_name;\n }\n }\n})"],"names":["sharedState","useListStore","defineStore","id","params","response","Client","index","o","list","url","data","profile"],"mappings":"iFAGA,MAAMA,EAAc,CAChB,MAAO,CAAE,EACT,YAAa,CACT,GAAI,KACJ,KAAM,KACN,WAAY,GACZ,SAAU,CAAE,CACf,EACD,eAAgB,CACZ,GAAI,KACJ,KAAM,IACT,CACL,EAEeC,EAAAC,EAAY,YAAa,CACpC,MAAO,IAAMF,EACb,QAAS,CACL,MAAM,WAAWG,EAAIC,EAAQ,CACzB,MAAMC,EAAW,MAAMC,EAAO,KAAK,kBAAkBH,CAAE,eAAgBC,CAAM,EACvEG,EAAQ,KAAK,MAAM,UAAUC,GAAGA,EAAE,KAAKL,CAAE,EAE/C,KAAK,MAAMI,CAAK,EAAI,MAAMF,EAAS,KAAI,CAC1C,EACD,MAAM,cAAcF,EAAIC,EAAQ,CAC5B,MAAMC,EAAW,MAAMC,EAAO,KAAK,kBAAkBH,CAAE,oBAAqBC,CAAM,EAElF,GAAI,cAAgB,aAAc,CAC9B,MAAMG,EAAQ,KAAK,YAAY,SAAS,UAAUC,GAAGA,EAAE,KAAKL,CAAE,EAC9D,KAAK,YAAY,SAAS,OAAOI,EAAO,CAAC,CACzD,KAAmB,CACH,MAAMA,EAAQ,KAAK,MAAM,UAAUC,GAAGA,EAAE,KAAKL,CAAE,EAC/C,KAAK,MAAMI,CAAK,EAAI,MAAMF,EAAS,KAAI,CAC1C,CACJ,EACD,MAAM,UAAUF,EAAI,CAChB,MAAME,EAAW,MAAMC,EAAO,IAAI,kBAAkBH,CAAE,EAAE,EACxD,KAAK,YAAc,MAAME,EAAS,KAAI,CACzC,EACD,MAAM,YAAa,CACf,MAAMA,EAAW,MAAMC,EAAO,IAAI,iBAAiB,EACnD,KAAK,MAAQ,MAAMD,EAAS,KAAI,CACnC,EACD,MAAM,WAAWD,EAAQ,CAErB,MAAMK,EAAO,MADI,MAAMH,EAAO,KAAK,kBAAmBF,CAAM,GAChC,OAE5B,KAAK,MAAM,KAAKK,CAAI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