Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Adds Sterling Pound option and doesn't allow copying budgets until sy…
Browse files Browse the repository at this point in the history
…nc is done.

Also tweaks the data reload timer so it's less intrusive.
  • Loading branch information
BrunoBernardino committed Apr 17, 2021
1 parent 82fac3f commit 8535343
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "budgetzen-desktop",
"productName": "Budget Zen",
"version": "1.2.1",
"buildHash": "rfydHa5p",
"version": "1.3.0",
"buildHash": "Hx7BNMQB",
"description": "Desktop app for Budget Zen",
"main": ".webpack/main",
"scripts": {
Expand Down Expand Up @@ -38,7 +38,7 @@
"appBundleId": "com.emotionloop.BudgetsCalm-macOS",
"appCategoryType": "public.app-category.finance",
"appCopyright": "Bruno Bernardino",
"buildVersion": 12
"buildVersion": 13
},
"makers": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/components/SegmentedControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const Segment = styled.button<SegmentProps>`
selected ? colors().primaryButtonBackground : 'transparent'};
padding: 10px;
border-radius: 5px;
min-width: 50%;
min-width: 33%;
color: ${({ selected }) =>
selected ? colors().primaryButtonText : 'inherit'};
font-size: ${fontSizes.button}px;
Expand Down
2 changes: 1 addition & 1 deletion src/hocs/withLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface LayoutState {
}

const notificationTimeoutInMS = 10 * 1000;
const reloadTimeoutInMS = 60 * 1000;
const reloadTimeoutInMS = 15 * 60 * 1000;

const withLayout: any = (WrappedComponent: any, sharedOptions: any) => {
class LayoutComponent extends Component<LayoutProps, LayoutState> {
Expand Down
25 changes: 25 additions & 0 deletions src/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { sortByDate, sortByName, splitArrayInChunks } from './utils';
import * as T from './types';

interface DB {
_hasFinishedFirstSync: {
budgets: boolean;
expenses: boolean;
};
updateSyncDate: (alive: boolean) => Promise<void>;
connect: () => Promise<RxDatabase>;
fetchBudgets: (db: RxDatabase, month: string) => Promise<T.Budget[]>;
Expand Down Expand Up @@ -103,6 +107,10 @@ const localDbName = 'localdb_budgetscalm_v0';
const store = new Store();

const DB: DB = {
_hasFinishedFirstSync: {
budgets: false,
expenses: false,
},
updateSyncDate: async (alive = true) => {
const lastSyncDate = moment().format('YYYY-MM-DD HH:mm:ss');
if (alive) {
Expand Down Expand Up @@ -150,6 +158,15 @@ const DB: DB = {
expensesSync.change$.subscribe((change) =>
DB.updateSyncDate(change.ok),
);
budgetsSync.complete$.subscribe(() => {
DB._hasFinishedFirstSync.budgets = true;
});
expensesSync.complete$.subscribe(() => {
DB._hasFinishedFirstSync.expenses = true;
});
} else {
DB._hasFinishedFirstSync.budgets = true;
DB._hasFinishedFirstSync.expenses = true;
}

return db;
Expand Down Expand Up @@ -383,6 +400,14 @@ const DB: DB = {
await existingExpense.remove();
},
copyBudgets: async (db, originalMonth, destinationMonth) => {
// Don't copy anything until we're done with the first sync
if (
!DB._hasFinishedFirstSync.expenses ||
!DB._hasFinishedFirstSync.budgets
) {
return;
}

const originalBudgets = await DB.fetchBudgets(db, originalMonth);
const destinationBudgets = originalBudgets.map((budget) => {
const newBudget: T.Budget = { ...budget };
Expand Down
3 changes: 3 additions & 0 deletions src/lib/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ describe('lib/utils', () => {
{ currency: 'EUR', number: 900.999, expected: '€901' },
{ currency: 'EUR', number: 900.991, expected: '€900.99' },
{ currency: 'USD', number: 50.11, expected: '$50.11' },
{ currency: 'GBP', number: 900.999, expected: '£901' },
{ currency: 'GBP', number: 900.991, expected: '£900.99' },
{ currency: 'GBP', number: 50.11, expected: '£50.11' },
];

for (const test of tests) {
Expand Down
12 changes: 9 additions & 3 deletions src/windows/main/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ const Code = styled.code`
line-height: 1em;
`;

const currencyLabels = ['$', '€'];
const currencyValues = ['USD', 'EUR'];
const currencyLabels = ['$', '€', '£'];
const currencyValues = ['USD', 'EUR', 'GBP'];

class Settings extends Component<SettingsProps, SettingsState> {
constructor(props: SettingsProps) {
Expand Down Expand Up @@ -197,6 +197,10 @@ class Settings extends Component<SettingsProps, SettingsState> {
currency,
} = this.state;

const selectedCurrencyIndex = currencyValues.findIndex(
(_currency) => currency === _currency,
);

return (
<>
<SettingsButton
Expand Down Expand Up @@ -229,7 +233,9 @@ class Settings extends Component<SettingsProps, SettingsState> {
<Label>Currency</Label>
<StyledSegmentedControl
values={currencyLabels}
selectedIndex={currency === '' || currency === 'USD' ? 0 : 1}
selectedIndex={
selectedCurrencyIndex === -1 ? 0 : selectedCurrencyIndex
}
onChange={(selectedSegmentIndex: number) => {
this.setState(
{
Expand Down

0 comments on commit 8535343

Please sign in to comment.