diff --git a/components/Panels/Settings.tsx b/components/Panels/Settings.tsx index 7a780c1..e7f0cce 100644 --- a/components/Panels/Settings.tsx +++ b/components/Panels/Settings.tsx @@ -75,8 +75,8 @@ const HelpButton = styled(Button)` align-self: center; `; -const currencyLabels = ['$', '€']; -const currencyValues: T.Currency[] = ['USD', 'EUR']; +const currencyLabels = ['$', '€', '£']; +const currencyValues: T.Currency[] = ['USD', 'EUR', 'GBP']; const Settings = ({ currentCurrency, @@ -113,6 +113,10 @@ const Settings = ({ } }; + const selectedCurrencyIndex = currencyValues.findIndex( + (_currency) => currency === _currency, + ); + return ( <> Currency { setCurrency(currencyValues[selectedSegmentIndex]); saveCurrency(currencyValues[selectedSegmentIndex]); diff --git a/components/SegmentedControl.tsx b/components/SegmentedControl.tsx index 91f79bb..d6d45ae 100644 --- a/components/SegmentedControl.tsx +++ b/components/SegmentedControl.tsx @@ -33,7 +33,7 @@ const Segment = styled.button` 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; diff --git a/lib/data-utils.ts b/lib/data-utils.ts index 921b1be..853359d 100644 --- a/lib/data-utils.ts +++ b/lib/data-utils.ts @@ -110,6 +110,11 @@ export const budgetSchema: RxJsonSchema = { required: ['name', 'month', 'value'], }; +const _hasFinishedFirstSync = { + budgets: false, + expenses: false, +}; + export const initializeDb = async (syncToken: string) => { if (!syncToken) { return null; @@ -143,6 +148,7 @@ export const initializeDb = async (syncToken: string) => { budgetsSync.complete$.subscribe((completed) => { console.log('budgetsSync.complete$', completed); + _hasFinishedFirstSync.budgets = true; }); budgetsSync.change$.subscribe((docData) => { @@ -167,6 +173,7 @@ export const initializeDb = async (syncToken: string) => { expensesSync.complete$.subscribe((completed) => { console.log('expensesSync.complete$', completed); + _hasFinishedFirstSync.expenses = true; }); expensesSync.change$.subscribe((docData) => { @@ -643,6 +650,10 @@ export const copyBudgets = async ( originalMonth: string, destinationMonth: string, ) => { + // Don't copy anything until we're done with the first sync + if (!_hasFinishedFirstSync.expenses || !_hasFinishedFirstSync.budgets) { + return; + } const originalBudgets = await fetchBudgets(db, originalMonth); const destinationBudgets = originalBudgets.map((budget) => { const newBudget: T.Budget = { ...budget }; diff --git a/lib/types.ts b/lib/types.ts index bd90982..716d8eb 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -4,7 +4,7 @@ export interface PlainObject { [key: string]: any; } -export type Currency = 'USD' | 'EUR'; +export type Currency = 'USD' | 'EUR' | 'GBP'; export interface AuthToken { syncToken: string; diff --git a/lib/utils.test.ts b/lib/utils.test.ts index 3f77a9c..624a54b 100644 --- a/lib/utils.test.ts +++ b/lib/utils.test.ts @@ -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) { diff --git a/package.json b/package.json index d8d55df..86d94be 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "budgetzen-app", "version": "1.0.0", - "build": "WxpKARxZ", + "build": "dkGscrNV", "author": "Bruno Bernardino ", "license": "UNLICENSED", "repository": {