From 11c0df1293832d15b0172dd2dd018e930f402027 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Mon, 8 Dec 2025 09:21:19 +0100 Subject: [PATCH] refactor: clean up code formatting and improve query invalidation logic in RulesPage and useIsMobile hook for better readability and maintainability --- app/rules/page.tsx | 30 ++++++++++++++++-------------- hooks/use-mobile.ts | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/rules/page.tsx b/app/rules/page.tsx index 9976670..2efd410 100644 --- a/app/rules/page.tsx +++ b/app/rules/page.tsx @@ -42,19 +42,21 @@ export default function RulesPage() { offset: 0, includeUncategorized: true, }, - !!metadata, + !!metadata ); const refresh = useCallback(() => { invalidateTransactions(); queryClient.invalidateQueries({ queryKey: ["banking-metadata"] }); + queryClient.invalidateQueries({ queryKey: ["category-stats"] }); + queryClient.invalidateQueries({ queryKey: ["accounts-with-stats"] }); }, [invalidateTransactions, queryClient]); const [searchQuery, setSearchQuery] = useState(""); const [sortBy, setSortBy] = useState<"count" | "amount" | "name">("count"); const [filterMinCount, setFilterMinCount] = useState(2); const [expandedGroups, setExpandedGroups] = useState>(new Set()); const [selectedGroup, setSelectedGroup] = useState( - null, + null ); const [isDialogOpen, setIsDialogOpen] = useState(false); const [isAutoCategorizing, setIsAutoCategorizing] = useState(false); @@ -85,7 +87,7 @@ export default function RulesPage() { totalAmount: transactions.reduce((sum, t) => sum + t.amount, 0), suggestedKeyword: suggestKeyword(descriptions), }; - }, + } ); // Filter by search query @@ -96,7 +98,7 @@ export default function RulesPage() { (g) => g.displayName.toLowerCase().includes(query) || g.key.includes(query) || - g.suggestedKeyword.toLowerCase().includes(query), + g.suggestedKeyword.toLowerCase().includes(query) ); } @@ -165,7 +167,7 @@ export default function RulesPage() { // 1. Add keyword to category const category = metadata.categories.find( - (c: { id: string }) => c.id === ruleData.categoryId, + (c: { id: string }) => c.id === ruleData.categoryId ); if (!category) { throw new Error("Category not found"); @@ -173,7 +175,7 @@ export default function RulesPage() { // Check if keyword already exists const keywordExists = category.keywords.some( - (k: string) => k.toLowerCase() === ruleData.keyword.toLowerCase(), + (k: string) => k.toLowerCase() === ruleData.keyword.toLowerCase() ); if (!keywordExists) { @@ -191,14 +193,14 @@ export default function RulesPage() { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id, categoryId: ruleData.categoryId }), - }), - ), + }) + ) ); } refresh(); }, - [metadata, refresh], + [metadata, refresh] ); const handleAutoCategorize = useCallback(async () => { @@ -212,7 +214,7 @@ export default function RulesPage() { for (const transaction of uncategorized) { const categoryId = autoCategorize( transaction.description + " " + (transaction.memo || ""), - metadata.categories, + metadata.categories ); if (categoryId) { await fetch("/api/banking/transactions", { @@ -226,7 +228,7 @@ export default function RulesPage() { refresh(); alert( - `${categorizedCount} transaction(s) catégorisée(s) automatiquement`, + `${categorizedCount} transaction(s) catégorisée(s) automatiquement` ); } catch (error) { console.error("Error auto-categorizing:", error); @@ -245,8 +247,8 @@ export default function RulesPage() { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ...t, categoryId }), - }), - ), + }) + ) ); refresh(); } catch (error) { @@ -254,7 +256,7 @@ export default function RulesPage() { alert("Erreur lors de la catégorisation"); } }, - [refresh], + [refresh] ); if ( diff --git a/hooks/use-mobile.ts b/hooks/use-mobile.ts index a11de0c..5ba6260 100644 --- a/hooks/use-mobile.ts +++ b/hooks/use-mobile.ts @@ -4,7 +4,7 @@ const MOBILE_BREAKPOINT = 768; export function useIsMobile() { const [isMobile, setIsMobile] = React.useState( - undefined, + undefined ); React.useEffect(() => {