Fix measure category filter not applying on initial page load
When navigating back to the measures page with a ?category query parameter, the filter wasn't applied to the initial Relay query. The component state was initialized from the URL, but the Relay fragment loaded with its default category: null. Add a mount effect that triggers a refetch with the initial category parameter. Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -193,6 +193,22 @@ export default function MeasuresPage({ queryRef }: MeasuresPageProps) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const initialUrlCategory = useRef(urlCategory);
|
||||||
|
useEffect(() => {
|
||||||
|
if (initialUrlCategory.current) {
|
||||||
|
startTransition(() => {
|
||||||
|
refetch(
|
||||||
|
{
|
||||||
|
query: null,
|
||||||
|
state: null,
|
||||||
|
category: initialUrlCategory.current,
|
||||||
|
},
|
||||||
|
{ fetchPolicy: "network-only" },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [refetch, startTransition]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (urlCategory !== categoryFilter) {
|
if (urlCategory !== categoryFilter) {
|
||||||
setCategoryFilter(urlCategory);
|
setCategoryFilter(urlCategory);
|
||||||
|
|||||||
Reference in New Issue
Block a user