From e33b2cb34e3a7faf39ea54793bdbf335892bdb27 Mon Sep 17 00:00:00 2001 From: rare-magma Date: Sat, 5 Oct 2024 22:48:11 +0200 Subject: [PATCH] refactor: use static fields instead of exports Signed-off-by: rare-magma --- src/guitos/domain/userOptions.ts | 5 ++--- .../localForageOptionsRepository.ts | 16 ++++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/guitos/domain/userOptions.ts b/src/guitos/domain/userOptions.ts index 96209c5..0cbd453 100644 --- a/src/guitos/domain/userOptions.ts +++ b/src/guitos/domain/userOptions.ts @@ -1,12 +1,11 @@ import type { IntlConfig } from "react-currency-input-field/dist/components/CurrencyInputProps"; import { currenciesList } from "../../lists/currenciesList"; -export const CURRENCY_CODE = "currencyCode"; -export const LOCALE = "locale"; - export class UserOptions { currencyCode: string; locale: string; + static CURRENCY_CODE = "currencyCode"; + static LOCALE = "locale"; constructor(currencyCode: string, locale: string) { this.currencyCode = currencyCode; diff --git a/src/guitos/infrastructure/localForageOptionsRepository.ts b/src/guitos/infrastructure/localForageOptionsRepository.ts index 8329077..1141026 100644 --- a/src/guitos/infrastructure/localForageOptionsRepository.ts +++ b/src/guitos/infrastructure/localForageOptionsRepository.ts @@ -1,7 +1,6 @@ import localforage from "localforage"; import { currenciesMap } from "../../lists/currenciesMap"; -import { CURRENCY_CODE, LOCALE } from "../domain/userOptions"; -import type { UserOptions } from "../domain/userOptions"; +import { UserOptions } from "../domain/userOptions"; import type { UserOptionsRepository } from "../domain/userOptionsRepository"; export class localForageOptionsRepository implements UserOptionsRepository { @@ -16,7 +15,9 @@ export class localForageOptionsRepository implements UserOptionsRepository { async getCurrencyCode(): Promise { try { - const code = await this.optionsDB.getItem(CURRENCY_CODE); + const code = await this.optionsDB.getItem( + UserOptions.CURRENCY_CODE, + ); if (!code) { return this.getDefaultCurrencyCode(); } @@ -28,7 +29,10 @@ export class localForageOptionsRepository implements UserOptionsRepository { async saveCurrencyCode(options: UserOptions): Promise { try { - await this.optionsDB.setItem(CURRENCY_CODE, options.currencyCode); + await this.optionsDB.setItem( + UserOptions.CURRENCY_CODE, + options.currencyCode, + ); return true; } catch { return false; @@ -37,7 +41,7 @@ export class localForageOptionsRepository implements UserOptionsRepository { async getLocale(): Promise { try { - const locale = await this.optionsDB.getItem(LOCALE); + const locale = await this.optionsDB.getItem(UserOptions.LOCALE); if (!locale) throw new Error(); return locale; } catch (e) { @@ -47,7 +51,7 @@ export class localForageOptionsRepository implements UserOptionsRepository { async saveLocale(options: UserOptions): Promise { try { - await this.optionsDB.setItem(LOCALE, options.locale); + await this.optionsDB.setItem(UserOptions.LOCALE, options.locale); return true; } catch { return false;