Skip to content

Commit

Permalink
fix category reassignment
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Jul 5, 2024
1 parent f34d713 commit 80f09dd
Show file tree
Hide file tree
Showing 17 changed files with 659 additions and 274 deletions.
2 changes: 1 addition & 1 deletion apps/gnocchi/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@verdant-web/cli": "^4.4.1",
"@verdant-web/common": "2.3.4",
"@verdant-web/react": "34.0.1",
"@verdant-web/store": "3.8.1",
"@verdant-web/store": "3.8.3",
"cuid": "^2.1.8",
"stopword": "^2.0.8"
},
Expand Down
4 changes: 2 additions & 2 deletions apps/gnocchi/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"@tiptap/starter-kit": "2.4.0",
"@use-gesture/react": "^10.2.24",
"@vercel/analytics": "^0.1.6",
"@verdant-web/react-router": "^0.6.2",
"@verdant-web/store": "^3.8.1",
"@verdant-web/react-router": "^0.6.3",
"@verdant-web/store": "^3.8.3",
"@zip.js/zip.js": "^2.7.6",
"classnames": "^2.3.2",
"convert-units": "^3.0.0-beta.4",
Expand Down
19 changes: 17 additions & 2 deletions apps/gnocchi/web/src/components/groceries/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { hooks } from '@/stores/groceries/index.js';
import { Category, Item } from '@gnocchi.biscuits/verdant';
import { useEffect, useMemo } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { useSnapshot } from 'valtio';
import { groceriesState } from './state.js';
import { debounce } from '@a-type/utils';
Expand Down Expand Up @@ -34,6 +34,21 @@ export function useItemsGroupedAndSorted(
[items, purchasedStillVisibleItems, purchasedHidingItems],
);

// subscribe to the cateogryId on all visible items to re-render when the category changes
// since the items query won't rerender when this changes... not sure if there's a more
// straightforward way to approach this.
const [forcedChange, forceUpdate] = useState(0);
useEffect(() => {
const unsubs = visibleItems.map((item) =>
item.subscribeToField('categoryId', 'change', () => {
console.log('category changed', item.get('id'));
forceUpdate((prev) => prev + 1);
}),
);

return () => unsubs.forEach((unsub) => unsub());
}, [visibleItems]);

const categoryGroups = useMemo(() => {
const categoryGroups: { category: Category | null; items: Item[] }[] = [];
const sortedCategories: (Category | null)[] = categories
Expand Down Expand Up @@ -64,7 +79,7 @@ export function useItemsGroupedAndSorted(
categoryGroups[categoryIndex].items.push(item);
}
return categoryGroups;
}, [visibleItems, categories]);
}, [visibleItems, categories, forcedChange]);

return {
categoryGroups,
Expand Down
2 changes: 1 addition & 1 deletion apps/humding/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"@verdant-web/cli": "4.4.1",
"@verdant-web/common": "2.3.4",
"@verdant-web/react": "34.0.1",
"@verdant-web/store": "^3.8.1"
"@verdant-web/store": "^3.8.3"
}
}
2 changes: 1 addition & 1 deletion apps/humding/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@humding.biscuits/verdant": "workspace:*",
"@react-spring/web": "^9.7.3",
"@use-gesture/react": "^10.2.24",
"@verdant-web/react-router": "^0.6.2",
"@verdant-web/react-router": "^0.6.3",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-hot-toast": "^2.4.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/marginalia/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@verdant-web/cli": "^4.4.1",
"@verdant-web/common": "^2.3.4",
"@verdant-web/react": "^34.0.1",
"@verdant-web/store": "^3.8.1",
"@verdant-web/store": "^3.8.3",
"cuid": "^2.1.8"
}
}
2 changes: 1 addition & 1 deletion apps/marginalia/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@marginalia.biscuits/verdant": "workspace:*",
"@react-spring/web": "^9.7.3",
"@tanstack/react-query": "5.39.0",
"@verdant-web/react-router": "^0.6.2",
"@verdant-web/react-router": "^0.6.3",
"classnames": "^2.5.0",
"react": "18.3.1",
"react-dom": "18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/star-chart/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"@verdant-web/cli": "4.4.1",
"@verdant-web/common": "2.3.4",
"@verdant-web/react": "34.0.1",
"@verdant-web/store": "3.8.1"
"@verdant-web/store": "3.8.3"
}
}
2 changes: 1 addition & 1 deletion apps/star-chart/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@star-chart.biscuits/verdant": "workspace:*",
"@types/raf": "^3.4.3",
"@use-gesture/react": "^10.2.24",
"@verdant-web/react-router": "^0.6.2",
"@verdant-web/react-router": "^0.6.3",
"@xstate/react": "^4.1.1",
"raf": "^3.4.1",
"react": "18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/trip-tick/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@verdant-web/cli": "^4.4.1",
"@verdant-web/common": "2.3.4",
"@verdant-web/react": "34.0.1",
"@verdant-web/store": "3.8.1",
"@verdant-web/store": "3.8.3",
"cuid": "^2.1.8"
}
}
4 changes: 2 additions & 2 deletions apps/trip-tick/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@trip-tick.biscuits/verdant": "workspace:*",
"@unocss/transformer-variant-group": "^0.54.1",
"@verdant-web/react": "^34.0.1",
"@verdant-web/react-router": "^0.6.2",
"@verdant-web/store": "^3.8.1",
"@verdant-web/react-router": "^0.6.3",
"@verdant-web/store": "^3.8.3",
"classnames": "^2.3.2",
"date-fns": "^2.30.0",
"downshift": "^7.0.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/wish-wash/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"@verdant-web/cli": "^4.4.1",
"@verdant-web/common": "^2.3.4",
"@verdant-web/react": "^34.0.1",
"@verdant-web/store": "^3.8.1"
"@verdant-web/store": "^3.8.3"
}
}
2 changes: 1 addition & 1 deletion apps/wish-wash/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@biscuits/client": "workspace:*",
"@react-spring/web": "^9.7.3",
"@unocss/transformer-variant-group": "^0.54.1",
"@verdant-web/react-router": "^0.6.2",
"@verdant-web/react-router": "^0.6.3",
"@wish-wash.biscuits/verdant": "workspace:*",
"react": "18.3.1",
"react-dom": "18.3.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
"devDependencies": {
"@a-type/ui": "^0.8.24",
"@types/react": "18.3.3",
"@verdant-web/react-router": "0.6.2",
"@verdant-web/store": "^3.8.1",
"@unocss/transformer-variant-group": "^0.58.0",
"@verdant-web/react-router": "0.6.3",
"@verdant-web/store": "^3.8.3",
"react": "18.3.1",
"vite-plugin-pwa": "0.19.2",
"unocss": "^0.58.0",
"@unocss/transformer-variant-group": "^0.58.0"
"vite-plugin-pwa": "0.19.2"
}
}
Loading

0 comments on commit 80f09dd

Please sign in to comment.