@local-civics/hub-ui 0.1.174 → 0.1.176

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -5579,30 +5579,46 @@ const PathwayCard = (props) => {
5579
5579
  const completedCount = badges.filter((b) => b.completedAt).length;
5580
5580
  const target = props.target || badges.length;
5581
5581
  const categoryTargets = (_a = props.criteria) != null ? _a : {};
5582
+ const categoryIds = Object.keys(categoryTargets);
5582
5583
  const points = (_b = props.points) != null ? _b : {};
5583
- const allCategories = Array.from(
5584
- new Set(badges.flatMap((b) => b.categories || []))
5585
- );
5586
5584
  const [filters, setFilters] = React.useState(
5587
5585
  () => {
5588
5586
  const obj = {};
5589
- allCategories.forEach((cat) => {
5590
- obj[cat] = { label: cat, isActive: false };
5587
+ categoryIds.forEach((id) => {
5588
+ obj[id] = {
5589
+ id,
5590
+ isActive: false
5591
+ };
5591
5592
  });
5592
5593
  return obj;
5593
5594
  }
5594
5595
  );
5595
- const toggleFilter = (label) => {
5596
- setFilters((prev) => __spreadProps$1(__spreadValues$2({}, prev), {
5597
- [label]: __spreadProps$1(__spreadValues$2({}, prev[label]), {
5598
- isActive: !prev[label].isActive
5599
- })
5600
- }));
5596
+ React.useEffect(() => {
5597
+ setFilters((prev) => {
5598
+ const next = {};
5599
+ categoryIds.forEach((id) => {
5600
+ var _a2, _b2;
5601
+ next[id] = {
5602
+ id,
5603
+ isActive: (_b2 = (_a2 = prev[id]) == null ? void 0 : _a2.isActive) != null ? _b2 : false
5604
+ };
5605
+ });
5606
+ return next;
5607
+ });
5608
+ }, [categoryIds]);
5609
+ const toggleFilter = (id) => {
5610
+ setFilters((prev) => {
5611
+ return __spreadProps$1(__spreadValues$2({}, prev), {
5612
+ [id]: __spreadProps$1(__spreadValues$2({}, prev[id]), {
5613
+ isActive: !prev[id].isActive
5614
+ })
5615
+ });
5616
+ });
5601
5617
  };
5602
5618
  const activeFilters = Object.values(filters).filter((f) => f.isActive);
5603
5619
  const filteredBadges = activeFilters.length === 0 ? badges : badges.filter(
5604
5620
  (b) => activeFilters.some(
5605
- (f) => (b.categories || []).includes(f.label)
5621
+ (f) => (b.categories || []).includes(f.id)
5606
5622
  )
5607
5623
  );
5608
5624
  const filterClassName = "inline-block px-4 py-2 bg-gray-600 text-white rounded-full cursor-pointer text-sm";
@@ -5620,17 +5636,18 @@ const PathwayCard = (props) => {
5620
5636
  points,
5621
5637
  height: "sm"
5622
5638
  }
5623
- ), /* @__PURE__ */ React.createElement("div", { className: "flex flex-wrap gap-2 mt-3" }, allCategories.map((cat, i) => {
5624
- var _a2;
5625
- const isActive = (_a2 = filters[cat]) == null ? void 0 : _a2.isActive;
5639
+ ), /* @__PURE__ */ React.createElement("div", { className: "flex flex-wrap gap-2 mt-3" }, categoryIds.map((id) => {
5640
+ var _a2, _b2, _c2;
5641
+ const isActive = (_a2 = filters[id]) == null ? void 0 : _a2.isActive;
5642
+ const label = (_c2 = (_b2 = props.categoryNames) == null ? void 0 : _b2[id]) != null ? _c2 : id;
5626
5643
  return /* @__PURE__ */ React.createElement(
5627
5644
  "div",
5628
5645
  {
5629
- key: i,
5630
- onClick: () => toggleFilter(cat),
5646
+ key: id,
5647
+ onClick: () => toggleFilter(id),
5631
5648
  className: isActive ? `${filterClassName} bg-gray-700` : "inline-block px-4 py-2 rounded-full hover:bg-gray-200 cursor-pointer text-sm"
5632
5649
  },
5633
- cat
5650
+ label
5634
5651
  );
5635
5652
  })), /* @__PURE__ */ React.createElement("div", { className: "mt-2 grid grid-cols-1 gap-y-2 max-h-[18rem] overflow-y-auto" }, filteredBadges.map((b) => {
5636
5653
  const buttonText = b.completedAt ? "Completed" : b.startedAt ? "Continue" : "Start";