{"version":3,"file":"filters_controller-DqYWlHCT.js","sources":["../../../app/javascript/controllers/conversations/filters_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\"\nimport { get } from \"@rails/request.js\"\n\nimport { Current } from \"../models/current\";\n\nexport default class extends Controller {\n static values = {\n url: String,\n stateFilter: String,\n memberFilter: Array,\n labelFilter: {\n type: Array,\n default: [],\n },\n }\n\n changeStateFilter(e) {\n this.stateFilterValue = e.target.dataset.filter\n\n this.displayStateFilterSkeletons()\n this.getFilteredResults()\n }\n\n applyLabelFilter(e) {\n this.labelFilterValue = [...this.labelFilterValue, e.currentTarget.dataset.id]\n this.displayStateFilterSkeletons()\n\n this.getFilteredResults()\n }\n\n applyMemberFilter(e) {\n this.memberFilterValue = Array.from(\n new Set([...this.memberFilterValue, e.currentTarget.dataset.id])\n )\n\n this.displayStateFilterSkeletons()\n this.getFilteredResults()\n }\n\n async removeMemberFilter({ currentTarget }) {\n this.memberFilterValue = this.memberFilterValue.filter(\n (memberId) => memberId !== currentTarget.dataset.id\n )\n\n this.displayStateFilterSkeletons()\n await this.getFilteredResults()\n }\n\n async removeLabelFilter({ currentTarget }) {\n this.labelFilterValue = this.labelFilterValue.filter(\n (labelId) => labelId !== currentTarget.dataset.id\n )\n\n this.displayStateFilterSkeletons()\n await this.getFilteredResults()\n }\n\n async getFilteredResults() {\n const url = new URL(this.urlValue)\n\n url.searchParams.set(\"filter\", this.stateFilterValue)\n\n if (this.appliedMemberFiltersWithoutSiteAdmin.length === 0) {\n url.searchParams.append(\"team\", \"1\")\n } else if(this.appliedMemberFiltersWithoutSiteAdmin.length > 0) {\n url.searchParams.append(\"member\", this.appliedMemberFiltersWithoutSiteAdmin.join(\",\"))\n }\n\n url.searchParams.append(\"label\", this.labelFilterValue.join(\",\"))\n\n this.changeBrowserUrl()\n\n await get(url.toString(), {\n responseKind: \"turbo-stream\",\n })\n }\n\n filter(e) {\n const url = new URL(this.urlValue)\n url.searchParams.set(this.queryValue, e.target.dataset.filter)\n\n get(url.toString(), {\n responseKind: \"turbo-stream\",\n })\n\n this.changeBrowserUrl()\n }\n\n changeBrowserUrl() {\n const url = new URL(window.location.href.split(\"?\")[0])\n url.searchParams.set(\"filter\", this.stateFilterValue)\n\n if(this.labelFilterValue.length > 0) {\n url.searchParams.append(\"label\", this.labelFilterValue.join(\",\"))\n }\n\n if (this.appliedMemberFiltersWithoutSiteAdmin.length === 0) {\n url.searchParams.append(\"team\", \"1\")\n } else if(this.appliedMemberFiltersWithoutSiteAdmin.length > 0) {\n url.searchParams.append(\"member\", this.appliedMemberFiltersWithoutSiteAdmin.join(\",\"))\n }\n\n history.pushState({}, null, url.toString().replaceAll(\"%2C\", \",\"))\n Turbo.navigator.history.replace(url.toString().replaceAll(\"%2C\", \",\"))\n\n this.dispatch(\"reset-pages\", { prefix: false, detail: { page: 2 } })\n }\n\n stateFilterValueChanged() {\n this.dispatch(\"stateChanged\", {\n target: document.getElementById(\"conversations-list\"),\n detail: {\n state: this.stateFilterValue,\n }\n })\n }\n\n // private\n\n displayStateFilterSkeletons() {\n this.element.querySelectorAll(\"[data-state-filter]\").forEach((element) => {\n element.querySelector(\"x-count\").classList.add(\"hidden\")\n element.querySelector(\"x-count-skeleton\").classList.remove(\"hidden\")\n })\n }\n\n get appliedMemberFiltersWithoutSiteAdmin() {\n if(Current.user.teamMember) {\n return this.memberFilterValue\n } else {\n return this.memberFilterValue.filter((memberId) => memberId !== Current.user.id)\n }\n }\n}\n"],"names":["filters_controller","Controller","currentTarget","memberId","labelId","url","get","element","Current","__publicField"],"mappings":"uSAKe,MAAKA,UAASC,CAAW,CAWtC,kBAAkB,EAAG,CACnB,KAAK,iBAAmB,EAAE,OAAO,QAAQ,OAEzC,KAAK,4BAA2B,EAChC,KAAK,mBAAkB,CAC3B,CAEE,iBAAiB,EAAG,CAClB,KAAK,iBAAmB,CAAC,GAAG,KAAK,iBAAkB,EAAE,cAAc,QAAQ,EAAE,EAC7E,KAAK,4BAA2B,EAEhC,KAAK,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