Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

fix: apply collection currency changes immediately

IceeAn6422b599b163
diff --git a/frontend/composables/use-formatters.ts b/frontend/composables/use-formatters.ts
index 65f39715..04fb644c 100644
--- a/frontend/composables/use-formatters.ts
+++ b/frontend/composables/use-formatters.ts
@@ -1,23 +1,28 @@
import { format, formatDistance } from "date-fns";
+import { reactive } from "vue";
/* eslint import/namespace: ['error', { allowComputed: true }] */
import * as Locales from "date-fns/locale";
import { fmtCurrency, fmtCurrencyAsync } from "./utils";
-const cache = {
+const cache = reactive({
currency: "",
-};
+});
export function resetCurrency() {
cache.currency = "";
}
+export function setCurrency(currency: string) {
+ cache.currency = currency;
+}
+
export async function useFormatCurrency() {
if (cache.currency === "") {
const client = useUserApi();
const { data: group } = await client.group.get();
- if (group) {
+ if (group && cache.currency === "") {
cache.currency = group.currency;
}
}
diff --git a/frontend/pages/collection/index/settings.vue b/frontend/pages/collection/index/settings.vue
index ec49571a..d30e9762 100644
--- a/frontend/pages/collection/index/settings.vue
+++ b/frontend/pages/collection/index/settings.vue
@@ -8,7 +8,7 @@
import FormTextField from "~/components/Form/TextField.vue";
import type { CurrenciesCurrency, Group } from "~~/lib/api/types/data-contracts";
import { fmtCurrencyAsync } from "~/composables/utils";
- import { getLocaleCode } from "~/composables/use-formatters";
+ import { getLocaleCode, setCurrency } from "~/composables/use-formatters";
definePageMeta({
middleware: ["auth"],
@@ -114,6 +114,7 @@
}
group.value = res.data;
+ setCurrency(res.data.currency);
toast.success(t("profile.toast.group_updated"));
await reloadCollections();