Skip to content

Commit

Permalink
refactor: aggregate state into separate folder
Browse files Browse the repository at this point in the history
  • Loading branch information
grantwforsythe committed Apr 15, 2024
1 parent 5c66c69 commit 75f0e69
Show file tree
Hide file tree
Showing 27 changed files with 67 additions and 73 deletions.
10 changes: 5 additions & 5 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { provideStoreDevtools } from '@ngrx/store-devtools';

import { environment as env } from '../environments/environment';
import { routes } from './app.routes';
import { ReportEffects } from './reports/data-access/report.effects';
import { reportReducer } from './reports/data-access/report.reducers';
import { BudgetEffects } from './reports/feature/budget-cards/budget-cards.effects';
import { budgetsReducers } from './reports/feature/budget-cards/budget-cards.reducers';
import { formReducer } from './reports/feature/dashboard/reports-form/dashboard-form.reducers';
import { authInterceptor } from './shared/services/auth/auth.interceptor';
import { BudgetEffects } from './state/effects/budget-cards.effects';
import { ReportEffects } from './state/effects/report.effects';
import { budgetsReducers } from './state/reducers/budget-cards.reducers';
import { formReducer } from './state/reducers/dashboard-form.reducers';
import { reportReducer } from './state/reducers/report.reducers';

export const appConfig: ApplicationConfig = {
providers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { RouterModule } from '@angular/router';

import { Store } from '@ngrx/store';

import { budgetActions } from './budget-cards.actions';
import { selectBudgets } from './budget-cards.selectors';
import { budgetActions } from '../../../state/actions/budget-cards.actions';
import { selectBudgets } from '../../../state/selectors/budget-cards.selectors';

@Component({
selector: 'app-budgets',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NgxChartsModule } from '@swimlane/ngx-charts';
import { Account } from '../../../../shared/services/ynab/interfaces/accounts/account';
import { CategoryGroup } from '../../../../shared/services/ynab/interfaces/categories/categoryGroup';
import { Transaction } from '../../../../shared/services/ynab/interfaces/transactions/transaction';
import { selectSortedResults } from '../../../data-access/report.selectors';
import { selectSortedResults } from '../../../../state/selectors/report.selectors';
import { ChartsBarHorizontalComponent } from './bar-horizontal.component';

describe('ChartsBarHorizontalComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Store } from '@ngrx/store';
import { BarChartModule } from '@swimlane/ngx-charts';
import { Observable } from 'rxjs';

import { selectSortedResults } from '../../../data-access/report.selectors';
import { selectSortedResults } from '../../../../state/selectors/report.selectors';

@Component({
selector: 'app-charts-bar-horizontal',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NgxChartsModule } from '@swimlane/ngx-charts';
import { Account } from '../../../../shared/services/ynab/interfaces/accounts/account';
import { CategoryGroup } from '../../../../shared/services/ynab/interfaces/categories/categoryGroup';
import { Transaction } from '../../../../shared/services/ynab/interfaces/transactions/transaction';
import { selectSortedResults } from '../../../data-access/report.selectors';
import { selectSortedResults } from '../../../../state/selectors/report.selectors';
import { ChartsBarVerticalComponent } from './bar-vertical.component';

describe('ChartsBarVerticalComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Store } from '@ngrx/store';
import { BarChartModule } from '@swimlane/ngx-charts';
import { Observable } from 'rxjs';

import { selectSortedResults } from '../../../data-access/report.selectors';
import { selectSortedResults } from '../../../../state/selectors/report.selectors';

@Component({
selector: 'app-charts-bar-vertical',
Expand Down
4 changes: 2 additions & 2 deletions src/app/reports/feature/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Store } from '@ngrx/store';

import { Observable } from 'rxjs';

import { reportActions } from '../../data-access/report.actions';
import { selectChartType } from '../../data-access/report.selectors';
import { reportActions } from '../../../state/actions/report.actions';
import { selectChartType } from '../../../state/selectors/report.selectors';
import { ChartsBarHorizontalComponent } from './bar-chart/bar-horizontal.component';
import { ChartsBarVerticalComponent } from './bar-chart/bar-vertical.component';
import { ChartsPieChartComponent } from './pie-chart/pie-chart.component';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Store } from '@ngrx/store';
import { PieChartModule } from '@swimlane/ngx-charts';
import { Observable } from 'rxjs';

import { selectSortedResults } from '../../../data-access/report.selectors';
import { selectSortedResults } from '../../../../state/selectors/report.selectors';

@Component({
selector: 'app-charts-pie-chart',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { Observable, Subject, combineLatest, startWith, takeUntil } from 'rxjs';

import { Account } from '../../../../shared/services/ynab/interfaces/accounts/account';
import { Category } from '../../../../shared/services/ynab/interfaces/categories/category';
import { formActions } from '../../../../state/actions/dashboard-form.actions';
import { FormState } from '../../../../state/app.state';
import {
selectEarliestTransactionDate,
selectReportAccounts,
selectReportCategories,
} from '../../../data-access/report.selectors';
import { formActions } from './dashboard-form.actions';
import { FormState } from './dashboard-form.interface';
} from '../../../../state/selectors/report.selectors';

@Component({
selector: 'app-reports-dashboard-form',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createActionGroup, emptyProps, props } from '@ngrx/store';

import { BudgetSummary } from '../../../shared/services/ynab/interfaces/budgets/summary/budgetSummary';
import { BudgetSummary } from '../../shared/services/ynab/interfaces/budgets/summary/budgetSummary';

export const budgetActions = createActionGroup({
source: 'Budget Page',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createActionGroup, props } from '@ngrx/store';

import { FormState } from './dashboard-form.interface';
import { FormState } from '../app.state';

export const formActions = createActionGroup({
source: 'Form Page',
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions src/app/state/app.state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Account } from '../shared/services/ynab/interfaces/accounts/account';
import { BudgetSummary } from '../shared/services/ynab/interfaces/budgets/summary/budgetSummary';
import { CategoryGroup } from '../shared/services/ynab/interfaces/categories/categoryGroup';
import { Transaction } from '../shared/services/ynab/interfaces/transactions/transaction';

export interface BudgetState {
budgets: BudgetSummary[];
}

export interface FormState {
start: string | null;
end: string | null;
sort?: 'asc' | 'desc' | null;
account: string[] | null;
category: string[] | null;
chartType: string | null;
}

export interface ReportState {
categoryGroups: CategoryGroup[];
accounts: Account[];
transactions: Transaction[];
}

export interface AppState {
form: FormState;
report: ReportState;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { provideMockStore } from '@ngrx/store/testing';

import { Observable, of } from 'rxjs';

import { YnabService } from '../../../shared/services/ynab/ynab.service';
import { mockBudgets } from '../../../shared/utils/mocks';
import { budgetActions } from './budget-cards.actions';
import { YnabService } from '../../shared/services/ynab/ynab.service';
import { mockBudgets } from '../../shared/utils/mocks';
import { budgetActions } from '../actions/budget-cards.actions';
import { BudgetEffects } from './budget-cards.effects';

describe('BudgetEffects', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Store } from '@ngrx/store';

import { of, switchMap } from 'rxjs';

import { YnabService } from '../../../shared/services/ynab/ynab.service';
import { budgetActions } from './budget-cards.actions';
import { YnabService } from '../../shared/services/ynab/ynab.service';
import { budgetActions } from '../actions/budget-cards.actions';

export class BudgetEffects {
actions$ = inject(Actions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
mockId,
mockTransactions,
} from '../../shared/utils/mocks';
import { reportActions } from './report.actions';
import { reportActions } from '../actions/report.actions';
import { ReportEffects } from './report.effects';

describe('ReportEffects', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { forkJoin, mergeMap, of, switchMap } from 'rxjs';

import { selectRouteNestedParam } from '../../router.selectors';
import { YnabService } from '../../shared/services/ynab/ynab.service';
import { reportActions } from './report.actions';
import { reportActions } from '../actions/report.actions';

export class ReportEffects {
actions$ = inject(Actions);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { budgetActions } from './budget-cards.actions';
import { budgetActions } from '../actions/budget-cards.actions';
import * as fromReducer from './budget-cards.reducers';

describe('Budget Cards Reducers', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { createReducer, on } from '@ngrx/store';

import { BudgetSummary } from '../../../shared/services/ynab/interfaces/budgets/summary/budgetSummary';
import { budgetActions } from './budget-cards.actions';

export interface BudgetState {
budgets: BudgetSummary[];
}
import { budgetActions } from '../actions/budget-cards.actions';
import { BudgetState } from '../app.state';

export const initialState: BudgetState = {
budgets: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createReducer, on } from '@ngrx/store';

import { formActions } from './dashboard-form.actions';
import { FormState } from './dashboard-form.interface';
import { formActions } from '../actions/dashboard-form.actions';
import { FormState } from '../app.state';

const initialState: FormState = {
start: null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mockAccounts, mockCategoryGroups, mockTransactions } from '../../shared/utils/mocks';
import { reportActions } from './report.actions';
import { reportActions } from '../actions/report.actions';
import * as fromReducer from './report.reducers';

describe('Report Reducer', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { createReducer, on } from '@ngrx/store';

import { Account } from '../../shared/services/ynab/interfaces/accounts/account';
import { CategoryGroup } from '../../shared/services/ynab/interfaces/categories/categoryGroup';
import { Transaction } from '../../shared/services/ynab/interfaces/transactions/transaction';
import { reportActions } from './report.actions';

interface ReportState {
categoryGroups: CategoryGroup[];
accounts: Account[];
transactions: Transaction[];
}
import { reportActions } from '../actions/report.actions';
import { ReportState } from '../app.state';

export const initialState: ReportState = {
categoryGroups: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BudgetState } from './budget-cards.reducers';
import { BudgetState } from '../app.state';
import { selectBudgets } from './budget-cards.selectors';

describe('Budget Cards Selectors', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createFeatureSelector, createSelector } from '@ngrx/store';

import { BudgetState } from './budget-cards.reducers';
import { BudgetState } from '../app.state';

export const selectBudgetState = createFeatureSelector<BudgetState>('budget');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { mockAccounts, mockCategoryGroups, mockTransactions } from '../../shared/utils/mocks';
import { AppState } from '../app.state';
import * as fromSelectors from './report.selectors';

const initialState: fromSelectors.AppState = {
const initialState: AppState = {
report: {
categoryGroups: [],
accounts: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import { createFeatureSelector, createSelector } from '@ngrx/store';

import { Account } from '../../shared/services/ynab/interfaces/accounts/account';
import { CategoryGroup } from '../../shared/services/ynab/interfaces/categories/categoryGroup';
import { Transaction } from '../../shared/services/ynab/interfaces/transactions/transaction';
import { FormState } from '../feature/dashboard/reports-form/dashboard-form.interface';

export interface ReportState {
categoryGroups: CategoryGroup[];
accounts: Account[];
transactions: Transaction[];
}

export interface AppState {
form: FormState;
report: ReportState;
}
import { FormState, ReportState } from '../app.state';

export const selectFormState = createFeatureSelector<FormState>('form');

Expand Down

0 comments on commit 75f0e69

Please sign in to comment.