Open-source personal finance manager. Self-hosted, privacy-first.
feat(dashboard): List | Calendar view for Period Transactions (#581)
Danny Feliza95366f178b6
diff --git a/frontend/src/components/transactions-page-actions.tsx b/frontend/src/components/transactions-page-actions.tsxindex f0d73066..2cb3e92e 100644--- a/frontend/src/components/transactions-page-actions.tsx+++ b/frontend/src/components/transactions-page-actions.tsx@@ -2,6 +2,7 @@ import type { ReactNode } from 'react'import { ArrowLeftRight, CalendarDays, Copy, Download, List, MoreHorizontal } from 'lucide-react'import { useTranslation } from 'react-i18next'import { MonthStepper } from '@/components/month-stepper'+import { TransactionsViewSwitcher, type TransactionsViewSwitcherProps } from '@/components/transactions-view-switcher'import { Button } from '@/components/ui/button'import {DropdownMenu,@@ -21,14 +22,7 @@ type MonthStepperConfig = {nextLabel: string}-type TransactionsViewMode = 'list' | 'calendar'--type ViewSwitcherConfig = {- value: TransactionsViewMode- onChange: (value: TransactionsViewMode) => void- listLabel: string- calendarLabel: string-}+type ViewSwitcherConfig = TransactionsViewSwitcherPropsexport type TransactionsPageActionsProps = {month: MonthStepperConfig@@ -51,38 +45,11 @@ function HeaderMonthStepper({ month }: { month: MonthStepperConfig }) {)}-function DesktopViewSwitcher({ view }: { view: ViewSwitcherConfig }) {- return (- <div className="inline-flex rounded-lg border border-border bg-card p-0.5">- <Button- variant={view.value === 'list' ? 'secondary' : 'ghost'}- size="sm"- className="h-8 gap-1.5 px-2.5"- aria-pressed={view.value === 'list'}- onClick={() => view.onChange('list')}- >- <List size={14} />- {view.listLabel}- </Button>- <Button- variant={view.value === 'calendar' ? 'secondary' : 'ghost'}- size="sm"- className="h-8 gap-1.5 px-2.5"- aria-pressed={view.value === 'calendar'}- onClick={() => view.onChange('calendar')}- >- <CalendarDays size={14} />- {view.calendarLabel}- </Button>- </div>- )-}-function DesktopSecondaryActions(props: TransactionsPageActionsProps) {const { t } = useTranslation()return (<div className="hidden sm:contents">- <DesktopViewSwitcher view={props.view} />+ <TransactionsViewSwitcher {...props.view} />{props.columnPicker}<Button variant="outline" disabled={props.exporting} onClick={props.onExport}><Download size={16} className="mr-1.5" />{props.exportLabel}diff --git a/frontend/src/components/transactions-view-switcher.tsx b/frontend/src/components/transactions-view-switcher.tsxnew file mode 100644index 00000000..d89ef5a5--- /dev/null+++ b/frontend/src/components/transactions-view-switcher.tsx@@ -0,0 +1,43 @@+import { CalendarDays, List } from 'lucide-react'+import { Button } from '@/components/ui/button'++export type TransactionsViewMode = 'list' | 'calendar'++export type TransactionsViewSwitcherProps = {+ value: TransactionsViewMode+ onChange: (value: TransactionsViewMode) => void+ listLabel: string+ calendarLabel: string+}++/**+ * Segmented List/Calendar switch, shared by the transactions page header and+ * the dashboard's transactions section so both read as the same control.+ * @example `<TransactionsViewSwitcher value={view} onChange={setView} listLabel="List" calendarLabel="Calendar" />`+ */+export function TransactionsViewSwitcher({ value, onChange, listLabel, calendarLabel }: TransactionsViewSwitcherProps) {+ return (+ <div className="inline-flex rounded-lg border border-border bg-card p-0.5">+ <Button+ variant={value === 'list' ? 'secondary' : 'ghost'}+ size="sm"+ className="h-8 gap-1.5 px-2.5"+ aria-pressed={value === 'list'}+ onClick={() => onChange('list')}+ >+ <List size={14} />+ {listLabel}+ </Button>+ <Button+ variant={value === 'calendar' ? 'secondary' : 'ghost'}+ size="sm"+ className="h-8 gap-1.5 px-2.5"+ aria-pressed={value === 'calendar'}+ onClick={() => onChange('calendar')}+ >+ <CalendarDays size={14} />+ {calendarLabel}+ </Button>+ </div>+ )+}diff --git a/frontend/src/pages/dashboard.tsx b/frontend/src/pages/dashboard.tsxindex adb79ebc..9d57bd1f 100644--- a/frontend/src/pages/dashboard.tsx+++ b/frontend/src/pages/dashboard.tsx@@ -46,6 +46,8 @@ import { AccountIcon } from '@/components/account-icon'import { TransactionDrillDown, type DrillDownFilter } from '@/components/transaction-drill-down'import { TransactionDialog, type TransactionSavePayload } from '@/components/transaction-dialog'import { extractApiError } from '@/lib/api-errors'+import { TransactionCalendarView } from '@/components/transaction-calendar-view'+import { TransactionsViewSwitcher, type TransactionsViewMode } from '@/components/transactions-view-switcher'import { RuleDialog, type RuleDialogInitialData } from '@/components/rule-dialog'import { usePrivacyMode } from '@/hooks/use-privacy-mode'import { useIsMobile } from '@/hooks/use-mobile'@@ -109,6 +111,12 @@ export default function DashboardPage() {return parseMonthFromParams(searchParams) ?? currentMonth()})const [drillDown, setDrillDown] = useState<DrillDownFilter | null>(null)+ // Transactions section view, mirroring the transactions page: the choice+ // lives in the URL so the section can be refreshed, bookmarked or shared.+ const [txViewMode, setTxViewMode] = useState<TransactionsViewMode>(() => (+ searchParams.get('view') === 'calendar' ? 'calendar' : 'list'+ ))+ const [calendarSelectedDate, setCalendarSelectedDate] = useState<string>(() => searchParams.get('day') ?? '')const prevSearchRef = useRef<string | null>(null)@@ -125,9 +133,11 @@ export default function DashboardPage() {} else if (!isInitial) {setSelectedMonth(currentMonth())}+ setTxViewMode(searchParams.get('view') === 'calendar' ? 'calendar' : 'list')+ setCalendarSelectedDate(searchParams.get('day') ?? '')}, [searchParams])- // Sync selectedMonth back to URL+ // Sync selectedMonth and the transactions view back to URLuseEffect(() => {const params = new URLSearchParams(window.location.search)if (selectedMonth) {@@ -138,8 +148,17 @@ export default function DashboardPage() {params.delete('month')}+ if (txViewMode === 'calendar') {+ params.set('view', 'calendar')+ if (calendarSelectedDate) params.set('day', calendarSelectedDate)+ else params.delete('day')+ } else {+ params.delete('view')+ params.delete('day')+ }+setSearchParams(params, { replace: true })- }, [selectedMonth, setSearchParams])+ }, [selectedMonth, txViewMode, calendarSelectedDate, setSearchParams])const [editingTx, setEditingTx] = useState<Transaction | null>(null)const [dialogOpen, setDialogOpen] = useState(false)const [createRuleOpen, setCreateRuleOpen] = useState(false)@@ -198,6 +217,18 @@ export default function DashboardPage() {enabled: !noAccounts,})+ // Same month grid the transactions page renders, scoped to the active+ // collection's accounts. Only fetched while the calendar is on screen.+ const calendarAccountIds = acctIds && acctIds.length > 0 ? acctIds : undefined+ const { data: calendarData, isLoading: calendarLoading } = useQuery({+ queryKey: ['transactions', 'calendar', selectedMonth, activeAccountIds],+ enabled: txViewMode === 'calendar' && !noAccounts,+ queryFn: () => transactions.calendar({+ month: monthStart,+ account_ids: calendarAccountIds,+ }),+ })+// Resolve group_id → name for the badge on split transactions.const { data: allGroups } = useQuery({queryKey: ['groups', 'all'],@@ -316,6 +347,18 @@ export default function DashboardPage() {setCreateRuleOpen(true)}+ // Calendar rows carry only an id, so the full transaction is fetched before+ // the edit dialog opens (same as the transactions page).+ const handleOpenCalendarTransaction = async (id: string) => {+ try {+ const tx = await transactions.get(id)+ setEditingTx(tx)+ setDialogOpen(true)+ } catch {+ toast.error(t('common.error'))+ }+ }+const cumulativeData = useMemo(() => {if (!balanceHistory) return []@@ -1080,17 +1123,45 @@ export default function DashboardPage() {{/* Period Transactions */}<div>- <div className="bg-card rounded-xl border border-border shadow-sm overflow-hidden">- <div className="px-5 py-4 border-b border-border flex items-center justify-between">- <p className="text-sm font-semibold text-foreground">{t('dashboard.periodTransactions')}</p>- <button- onClick={() => { setTxSortDesc(v => !v); setTxPage(1) }}- className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer"- >- <ArrowUpDown size={13} />- {txSortDesc ? t('dashboard.sortNewest') : t('dashboard.sortOldest')}- </button>+ {/* One control bar for both views, so the switch never moves between them. */}+ <div className="mb-3 flex flex-wrap items-center justify-between gap-2">+ <p className="text-sm font-semibold text-foreground">{t('dashboard.periodTransactions')}</p>+ <div className="flex items-center gap-3">+ <TransactionsViewSwitcher+ value={txViewMode}+ onChange={setTxViewMode}+ listLabel={t('transactions.listView')}+ calendarLabel={t('transactions.calendarView')}+ />+ {txViewMode === 'list' && (+ <button+ onClick={() => { setTxSortDesc(v => !v); setTxPage(1) }}+ className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer"+ >+ <ArrowUpDown size={13} />+ {txSortDesc ? t('dashboard.sortNewest') : t('dashboard.sortOldest')}+ </button>+ )}</div>+ </div>++ {txViewMode === 'calendar' && (+ <TransactionCalendarView+ calendar={calendarData}+ isLoading={calendarLoading}+ locale={locale}+ dateLocale={dateLocale}+ mask={mask}+ selectedDate={calendarSelectedDate}+ onSelectedDateChange={setCalendarSelectedDate}+ onOpenTransaction={handleOpenCalendarTransaction}+ accounts={accountsList}+ userCurrency={userCurrency}+ />+ )}++ {txViewMode === 'list' && (+ <div className="bg-card rounded-xl border border-border shadow-sm overflow-hidden">{txListLoading ? (<div className="p-5 space-y-3">{Array.from({ length: 5 }).map((_, i) => (@@ -1384,6 +1455,7 @@ export default function DashboardPage() {<p className="text-muted-foreground text-sm text-center py-8">{t('dashboard.noTransactions')}</p>)}</div>+ )}</div><TransactionDrillDown