Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/common/graphql/queries/accountHierarchy.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query AccountHierarchy($userId: String!) {
accountHierarchy(userId: $userId) {
query AccountHierarchy($userId: String!, $ledgerId: String) {
accountHierarchy(userId: $userId, ledgerId: $ledgerId) {
data {
type
label
Expand Down
4 changes: 2 additions & 2 deletions src/common/graphql/queries/homeCharts.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query HomeCharts($userId: String!) {
homeCharts(userId: $userId) {
query HomeCharts($userId: String!, $ledgerId: String) {
homeCharts(userId: $userId, ledgerId: $ledgerId) {
data {
type
label
Expand Down
2 changes: 1 addition & 1 deletion src/components/ledger-guard/ledger-guard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const LedgerGuardProviderComponent = ({

LedgerGuardProviderComponent.displayName = "LedgerGuardProvider";

export const LedgerGuardProvider = memo(LedgerGuardProviderComponent);
export const LedgerGuard = memo(LedgerGuardProviderComponent);

export const useLedgerGuard = (): string => {
const context = useContext(LedgerGuardContext);
Expand Down
12 changes: 8 additions & 4 deletions src/generated-graphql/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ export type UpdateReportSubscribeResponse = {

export type AccountHierarchyQueryVariables = Exact<{
userId: Scalars['String']['input'];
ledgerId?: InputMaybe<Scalars['String']['input']>;
}>;


Expand Down Expand Up @@ -1535,6 +1536,7 @@ export type GetLedgerJournalQuery = { __typename?: 'Query', getLedgerJournal: {

export type HomeChartsQueryVariables = Exact<{
userId: Scalars['String']['input'];
ledgerId?: InputMaybe<Scalars['String']['input']>;
}>;


Expand Down Expand Up @@ -1606,8 +1608,8 @@ export type UserProfileQuery = { __typename?: 'Query', userProfile?: { __typenam


export const AccountHierarchyDocument = gql`
query AccountHierarchy($userId: String!) {
accountHierarchy(userId: $userId) {
query AccountHierarchy($userId: String!, $ledgerId: String) {
accountHierarchy(userId: $userId, ledgerId: $ledgerId) {
data {
type
label
Expand Down Expand Up @@ -1640,6 +1642,7 @@ export const AccountHierarchyDocument = gql`
* const { data, loading, error } = useAccountHierarchyQuery({
* variables: {
* userId: // value for 'userId'
* ledgerId: // value for 'ledgerId'
* },
* });
*/
Expand Down Expand Up @@ -1978,8 +1981,8 @@ export type GetLedgerJournalLazyQueryHookResult = ReturnType<typeof useGetLedger
export type GetLedgerJournalSuspenseQueryHookResult = ReturnType<typeof useGetLedgerJournalSuspenseQuery>;
export type GetLedgerJournalQueryResult = Apollo.QueryResult<GetLedgerJournalQuery, GetLedgerJournalQueryVariables>;
export const HomeChartsDocument = gql`
query HomeCharts($userId: String!) {
homeCharts(userId: $userId) {
query HomeCharts($userId: String!, $ledgerId: String) {
homeCharts(userId: $userId, ledgerId: $ledgerId) {
data {
type
label
Expand Down Expand Up @@ -2007,6 +2010,7 @@ export const HomeChartsDocument = gql`
* const { data, loading, error } = useHomeChartsQuery({
* variables: {
* userId: // value for 'userId'
* ledgerId: // value for 'ledgerId'
* },
* });
*/
Expand Down
186 changes: 96 additions & 90 deletions src/screens/home-screen/home-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { useThemeStyle, usePageView } from "@/common/hooks";
import { Button } from "@/components";
import { BarChartD3 } from "@/common/d3/bar-chart-d3";
import { LineChartD3 } from "@/common/d3/line-chart-d3";
import { LedgerGuard, useLedgerGuard } from "@/components/ledger-guard";

const getStyles = (theme: ColorTheme) =>
StyleSheet.create({
Expand All @@ -42,12 +43,13 @@ const getStyles = (theme: ColorTheme) =>
},
});

export const HomeScreen = (): JSX.Element => {
export const HomeScreenImpl = (): JSX.Element => {
const { userId } = useSession();
const { t } = useTranslations();
usePageView("home");
const styles = useThemeStyle(getStyles);
const router = useRouter();
const ledgerId = useLedgerGuard();
const { currencies, refetch: ledgerMetaRefetch } = useLedgerMeta(userId);
const currentTheme = useReactiveVar(themeVar);

Expand All @@ -60,13 +62,13 @@ export const HomeScreen = (): JSX.Element => {
loading: netWorthLoading,
refetch: netWorthRefetch,
error: netWorthError,
} = useHomeCharts(userId, currency);
} = useHomeCharts(userId, currency, ledgerId);
const {
accounts,
loading: accountsLoading,
refetch: accountsRefetch,
error: accountsError,
} = useAccountHierarchy(userId, currency);
} = useAccountHierarchy(userId, currency, ledgerId);
const [refreshing, setRefreshing] = useState(false);
const isLoading = netWorthLoading || refreshing;
const onRefresh = async () => {
Expand All @@ -83,96 +85,100 @@ export const HomeScreen = (): JSX.Element => {
};

return (
<>
<SafeAreaView edges={["top"]} style={styles.container}>
<ScrollView
showsVerticalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 16 }}
indicatorStyle={currentTheme === "dark" ? "white" : "default"}
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={onRefresh}
tintColor={currentTheme === "dark" ? "white" : "black"}
<SafeAreaView edges={["top"]} style={styles.container}>
<ScrollView
showsVerticalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 16 }}
indicatorStyle={currentTheme === "dark" ? "white" : "default"}
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={onRefresh}
tintColor={currentTheme === "dark" ? "white" : "black"}
/>
}
>
<CommonMargin />
<SmallHeaderText>{t("netAssets")}</SmallHeaderText>
<View>
{netWorthLoading || netWorthError || refreshing ? (
<LoadingTile height={40} mx={16} />
) : (
<NetAssetsStyled netAssets={`${netWorth.netAssets} ${currency}`} />
)}
</View>
<CommonMargin />

<HeaderText>{t("accounts")}</HeaderText>
<CommonMargin />
<View>
{accountsLoading || accountsError || refreshing ? (
<LoadingTile height={216} mx={16} />
) : (
<AccountsStyled
assets={`${accounts.assets} ${currency}`}
liabilities={`${accounts.liabilities} ${currency}`}
income={`${accounts.income} ${currency}`}
expenses={`${accounts.expenses} ${currency}`}
equity={`${accounts.equity} ${currency}`}
/>
}
)}
</View>
<CommonMargin />
<Button
type="primary"
onPress={async () => {
analytics.track("tap_quick_add", {});
AddTransactionCallback.setFn(onRefresh);
router.navigate({
pathname: "/add-transaction",
});
}}
>
<CommonMargin />
<SmallHeaderText>{t("netAssets")}</SmallHeaderText>
<View>
{netWorthLoading || netWorthError || refreshing ? (
<LoadingTile height={40} mx={16} />
) : (
<NetAssetsStyled
netAssets={`${netWorth.netAssets} ${currency}`}
<Text style={styles.quickAddLabel}>{t("quickAdd")}</Text>
</Button>
<CommonMargin />
<HeaderText>{t("monthlyNetIncome")}</HeaderText>
<CommonMargin />
<View>
{isLoading || netWorthError || accountsError ? (
<LoadingTile height={200} mx={16} />
) : (
<>
<BarChartD3
currencySymbol={currencySymbol}
labels={lastSixProfitData.labels}
numbers={lastSixProfitData.numbers}
/>
)}
</View>
<CommonMargin />

<HeaderText>{t("accounts")}</HeaderText>
<CommonMargin />
<View>
{accountsLoading || accountsError || refreshing ? (
<LoadingTile height={216} mx={16} />
) : (
<AccountsStyled
assets={`${accounts.assets} ${currency}`}
liabilities={`${accounts.liabilities} ${currency}`}
income={`${accounts.income} ${currency}`}
expenses={`${accounts.expenses} ${currency}`}
equity={`${accounts.equity} ${currency}`}
</>
)}
</View>
<CommonMargin />
<HeaderText>{t("monthlyNetWorth")}</HeaderText>
<CommonMargin />
<View>
{isLoading || netWorthError ? (
<LoadingTile height={200} mx={16} />
) : (
<>
<LineChartD3
currencySymbol={currencySymbol}
labels={lastSixWorthData.labels}
numbers={lastSixWorthData.numbers}
/>
)}
</View>
<CommonMargin />
<Button
type="primary"
onPress={async () => {
analytics.track("tap_quick_add", {});
AddTransactionCallback.setFn(onRefresh);
router.navigate({
pathname: "/add-transaction",
});
}}
>
<Text style={styles.quickAddLabel}>{t("quickAdd")}</Text>
</Button>
<CommonMargin />
<HeaderText>{t("monthlyNetIncome")}</HeaderText>
<CommonMargin />
<View>
{isLoading || netWorthError || accountsError ? (
<LoadingTile height={200} mx={16} />
) : (
<>
<BarChartD3
currencySymbol={currencySymbol}
labels={lastSixProfitData.labels}
numbers={lastSixProfitData.numbers}
/>
</>
)}
</View>
<CommonMargin />
<HeaderText>{t("monthlyNetWorth")}</HeaderText>
<CommonMargin />
<View>
{isLoading || netWorthError ? (
<LoadingTile height={200} mx={16} />
) : (
<>
<LineChartD3
currencySymbol={currencySymbol}
labels={lastSixWorthData.labels}
numbers={lastSixWorthData.numbers}
/>
</>
)}
</View>
<CommonMargin />
</ScrollView>
</SafeAreaView>
</>
</>
)}
</View>
<CommonMargin />
</ScrollView>
</SafeAreaView>
);
};

export const HomeScreen = () => {
return (
<LedgerGuard>
<HomeScreenImpl />
</LedgerGuard>
);
};
8 changes: 6 additions & 2 deletions src/screens/home-screen/hooks/use-account-hierarchy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { getAccountTotals } from "@/screens/home-screen/selectors/select-account-totals";
import { useAccountHierarchyQuery } from "@/generated-graphql/graphql";

export const useAccountHierarchy = (userId: string, currency: string) => {
export const useAccountHierarchy = (
userId: string,
currency: string,
ledgerId?: string,
) => {
const { loading, data, error, refetch } = useAccountHierarchyQuery({
variables: { userId },
variables: { userId, ledgerId },
fetchPolicy: "network-only",
});
const accounts = getAccountTotals(currency, data);
Expand Down
8 changes: 6 additions & 2 deletions src/screens/home-screen/hooks/use-home-charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { selectNetWorthArray } from "@/screens/home-screen/selectors/select-net-
import { selectNetProfitArray } from "@/screens/home-screen/selectors/select-net-profit-array";
import { getNetWorth } from "@/screens/home-screen/selectors/select-net-worth";

export const useHomeCharts = (userId: string, currency: string) => {
export const useHomeCharts = (
userId: string,
currency: string,
ledgerId?: string,
) => {
const { loading, data, error, refetch } = useHomeChartsQuery({
variables: { userId },
variables: { userId, ledgerId },
fetchPolicy: "network-only",
});

Expand Down
6 changes: 3 additions & 3 deletions src/screens/journal-screen/journal-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useTranslations } from "@/common/hooks/use-translations";
import { ColorTheme } from "@/types/theme-props";
import { NetworkStatus } from "@apollo/client";
import { useGetLedgerJournalQuery } from "@/generated-graphql/graphql";
import { LedgerGuardProvider, useLedgerGuard } from "@/components/ledger-guard";
import { LedgerGuard, useLedgerGuard } from "@/components/ledger-guard";
import { JournalHeader } from "./journal-header";
import { JournalEntryItem } from "./journal-entry-item";
import { JournalEmptyState } from "./journal-empty-state";
Expand Down Expand Up @@ -329,8 +329,8 @@ const JournalList = () => {

export const JournalScreen = () => {
return (
<LedgerGuardProvider>
<LedgerGuard>
<JournalList />
</LedgerGuardProvider>
</LedgerGuard>
);
};