Skip to content

Commit

Permalink
Use new useCategories hook in more places
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Löthberg <[email protected]>
  • Loading branch information
kyrias committed Aug 5, 2023
1 parent 970c554 commit d5f44d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from 'loot-core/src/shared/transactions';

import { useActions } from '../../hooks/useActions';
import { useCategories } from '../../hooks/useCategories';
import { useSetThemeColor } from '../../hooks/useSetThemeColor';
import { colors } from '../../style';
import SyncRefresh from '../SyncRefresh';
Expand Down Expand Up @@ -81,7 +82,6 @@ export default function Account(props) {
let state = useSelector(state => ({
payees: state.queries.payees,
newTransactions: state.queries.newTransactions,
categories: state.queries.categories.list,
prefs: state.prefs.local,
dateFormat: state.prefs.local.dateFormat || 'MM/dd/yyyy',
}));
Expand Down Expand Up @@ -134,9 +134,6 @@ export default function Account(props) {
}
});

if (state.categories.length === 0) {
await actionCreators.getCategories();
}
if (accounts.length === 0) {
await actionCreators.getAccounts();
}
Expand All @@ -152,6 +149,9 @@ export default function Account(props) {
return () => unlisten();
}, []);

// Load categories if necessary.
useCategories();

const updateSearchQuery = debounce(() => {
if (searchText === '' && currentQuery) {
updateQuery(currentQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useNavigate } from 'react-router-dom';
import * as queries from 'loot-core/src/client/queries';

import { useActions } from '../../hooks/useActions';
import useCategories from '../../hooks/useCategories';
import { useSetThemeColor } from '../../hooks/useSetThemeColor';
import { colors, styles } from '../../style';
import Button from '../common/Button';
Expand Down Expand Up @@ -233,27 +234,21 @@ export default function Accounts() {
let accounts = useSelector(state => state.queries.accounts);
let newTransactions = useSelector(state => state.queries.newTransactions);
let updatedAccounts = useSelector(state => state.queries.updatedAccounts);
let categories = useSelector(state => state.queries.categories.list);
let numberFormat = useSelector(
state => state.prefs.local.numberFormat || 'comma-dot',
);
let hideFraction = useSelector(
state => state.prefs.local.hideFraction || false,
);

let { getCategories, getAccounts } = useActions();
const { list: categories } = useCategories();
let { getAccounts } = useActions();

const transactions = useState({});
const navigate = useNavigate();

useEffect(() => {
(async () => {
if (categories.length === 0) {
await getCategories();
}

getAccounts();
})();
(async () => getAccounts())();
}, []);

// const sync = async () => {
Expand Down
14 changes: 3 additions & 11 deletions packages/desktop-client/src/components/reports/Overview.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useCallback, useMemo, useState, useEffect } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import { useSelector } from 'react-redux';

import { VictoryBar, VictoryGroup, VictoryVoronoiContainer } from 'victory';

import * as monthUtils from 'loot-core/src/shared/months';
import { integerToCurrency } from 'loot-core/src/shared/util';

import { useActions } from '../../hooks/useActions';
import useCategories from '../../hooks/useCategories';
import useFeatureFlag from '../../hooks/useFeatureFlag';
import { colors, styles } from '../../style';
import AnchorLink from '../common/AnchorLink';
Expand Down Expand Up @@ -256,9 +256,7 @@ function CashFlowCard() {
}

function CategorySpendingCard() {
const { getCategories } = useActions();

const [categories, setCategories] = useState({});
const categories = useCategories();

const end = monthUtils.currentDay();
const start = monthUtils.subMonths(end, 3);
Expand All @@ -276,12 +274,6 @@ function CategorySpendingCard() {

const perCategorySpending = useReport('category_spending', params);

useEffect(() => {
getCategories().then(categories => {
setCategories(categories);
});
}, []);

return (
<Card flex={1} to="/reports/category-spending">
<View>
Expand Down

0 comments on commit d5f44d0

Please sign in to comment.