Skip to content

Commit

Permalink
Show category balances in mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Apr 13, 2024
1 parent 7322388 commit ddebeb7
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 12 deletions.
3 changes: 3 additions & 0 deletions packages/desktop-client/src/components/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export function Modals() {
onSelect: options.onSelect,
showHiddenCategories: options.showHiddenCategories,
}}
month={options.month}
onClose={options.onClose}
/>
);
Expand Down Expand Up @@ -531,6 +532,7 @@ export function Modals() {
<TransferModal
modalProps={modalProps}
title={options.title}
month={options.month}
amount={options.amount}
onSubmit={options.onSubmit}
showToBeBudgeted={options.showToBeBudgeted}
Expand All @@ -542,6 +544,7 @@ export function Modals() {
<CoverModal
modalProps={modalProps}
categoryId={options.categoryId}
month={options.month}
onSubmit={options.onSubmit}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ function CategoryItem({
}}
>
{isToBeBudgetedItem
? integerToCurrency(toBudget || 0)
? toBudget != null
? integerToCurrency(toBudget || 0)
: null
: balance != null
? integerToCurrency(balance || 0)
: null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ const ExpenseCategory = memo(function ExpenseCategory({
dispatch(
pushModal('transfer', {
title: `Transfer: ${category.name}`,
month,
amount: catBalance,
onSubmit: (amount, toCategoryId) => {
onBudgetAction(month, 'transfer-category', {
Expand All @@ -294,6 +295,7 @@ const ExpenseCategory = memo(function ExpenseCategory({
dispatch(
pushModal('cover', {
categoryId: category.id,
month,
onSubmit: fromCategoryId => {
onBudgetAction(month, 'cover', {
to: category.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,15 @@ const TransactionEditInner = memo(function TransactionEditInner({
const onClick = (transactionId, name) => {
onRequestActiveEdit?.(getFieldName(transaction.id, name), () => {
const transactionToEdit = transactions.find(t => t.id === transactionId);
const unserializedTransaction = unserializedTransactions.find(
t => t.id === transactionId,
);
switch (name) {
case 'category':
dispatch(
pushModal('category-autocomplete', {
categoryGroups,
month: monthUtils.monthFromDate(unserializedTransaction.date),
onSelect: categoryId => {
onEdit(transactionToEdit, name, categoryId);
},
Expand Down Expand Up @@ -587,7 +591,7 @@ const TransactionEditInner = memo(function TransactionEditInner({
dispatch(
pushModal('edit-field', {
name,
month: monthUtils.monthFromDate(transaction.date),
month: monthUtils.monthFromDate(unserializedTransaction.date),
onSubmit: (name, value) => {
onEdit(transactionToEdit, name, value);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import React, { type ComponentPropsWithoutRef } from 'react';

import * as monthUtils from 'loot-core/src/shared/months';

import { useResponsive } from '../../ResponsiveProvider';
import { theme } from '../../style';
import { CategoryAutocomplete } from '../autocomplete/CategoryAutocomplete';
import { ModalCloseButton, Modal, ModalTitle } from '../common/Modal';
import { View } from '../common/View';
import { SectionLabel } from '../forms';
import { type CommonModalProps } from '../Modals';
import { NamespaceContext } from '../spreadsheet/NamespaceContext';

type CategoryAutocompleteModalProps = {
modalProps: CommonModalProps;
autocompleteProps: ComponentPropsWithoutRef<typeof CategoryAutocomplete>;
onClose: () => void;
month?: string;
};

export function CategoryAutocompleteModal({
modalProps,
autocompleteProps,
month,
onClose,
}: CategoryAutocompleteModalProps) {
const _onClose = () => {
Expand Down Expand Up @@ -71,15 +76,19 @@ export function CategoryAutocompleteModal({
/>
)}
<View style={{ flex: 1 }}>
<CategoryAutocomplete
focused={true}
embedded={true}
closeOnBlur={false}
showSplitOption={false}
onClose={_onClose}
{...defaultAutocompleteProps}
{...autocompleteProps}
/>
<NamespaceContext.Provider
value={monthUtils.sheetForMonth(month || '')}
>
<CategoryAutocomplete
focused={true}
embedded={true}
closeOnBlur={false}
showSplitOption={false}
onClose={_onClose}
{...defaultAutocompleteProps}
{...autocompleteProps}
/>
</NamespaceContext.Provider>
</View>
</View>
)}
Expand Down
5 changes: 4 additions & 1 deletion packages/desktop-client/src/components/modals/CoverModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import { type CommonModalProps } from '../Modals';
type CoverModalProps = {
modalProps: CommonModalProps;
categoryId: string;
month: string;
onSubmit: (categoryId: string) => void;
};

export function CoverModal({
modalProps,
categoryId,
month,
onSubmit,
}: CoverModalProps) {
const { grouped: originalCategoryGroups, list: categories } = useCategories();
Expand All @@ -36,12 +38,13 @@ export function CoverModal({
dispatch(
pushModal('category-autocomplete', {
categoryGroups,
month,
onSelect: categoryId => {
setFromCategoryId(categoryId);
},
}),
);
}, [categoryGroups, dispatch]);
}, [categoryGroups, dispatch, month]);

const _onSubmit = (categoryId: string | null) => {
if (categoryId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function RolloverBudgetSummaryModal({
dispatch(
pushModal('transfer', {
title: 'Transfer',
month,
amount: sheetValue,
onSubmit: (amount, toCategoryId) => {
onBudgetAction?.(month, 'transfer-available', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { type CommonModalProps } from '../Modals';
type TransferModalProps = {
modalProps: CommonModalProps;
title: string;
month: string;
amount: number;
showToBeBudgeted: boolean;
onSubmit: (amount: number, toCategoryId: string) => void;
Expand All @@ -26,6 +27,7 @@ type TransferModalProps = {
export function TransferModal({
modalProps,
title,
month,
amount: initialAmount,
showToBeBudgeted,
onSubmit,
Expand All @@ -45,6 +47,7 @@ export function TransferModal({
dispatch(
pushModal('category-autocomplete', {
categoryGroups,
month,
showHiddenCategories: true,
onSelect: categoryId => {
setToCategoryId(categoryId);
Expand Down
3 changes: 3 additions & 0 deletions packages/loot-core/src/client/state-types/modals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type FinanceModals = {
'category-autocomplete': {
categoryGroups: CategoryGroupEntity[];
onSelect: (categoryId: string, categoryName: string) => void;
month?: string;
showHiddenCategories?: boolean;
onClose?: () => void;
};
Expand Down Expand Up @@ -200,12 +201,14 @@ type FinanceModals = {
};
transfer: {
title: string;
month: string;
amount: number;
onSubmit: (amount: number, toCategoryId: string) => void;
showToBeBudgeted?: boolean;
};
cover: {
categoryId: string;
month: string;
onSubmit: (fromCategoryId: string) => void;
};
'hold-buffer': {
Expand Down

0 comments on commit ddebeb7

Please sign in to comment.