Skip to content

Commit

Permalink
fix: Update calculate when notation settings change
Browse files Browse the repository at this point in the history
fix #3
  • Loading branch information
dubisdev committed Jan 14, 2024
1 parent 646e128 commit c292974
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/state/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { create } from "zustand";
import { persist, subscribeWithSelector } from "zustand/middleware";
import { share } from "shared-zustand";
import { configureRunOnStart } from "@utils/configureRunOnStart";
import { useCalculatorStore } from "./calculator";
import { getCurrent } from "@tauri-apps/api/window";

export type CalculationOptions = {
useBigNumbers: boolean;
Expand Down Expand Up @@ -65,4 +67,23 @@ if ("BroadcastChannel" in globalThis) {
}
}

// Force re-render to calculate when notation or useBigNumbers changes
if (getCurrent().label === "main") {
useSettingsStore.subscribe(
async (newState, prevState) => {
const isNewNotation = newState.notation !== prevState.notation;
const iseDifferentBigNumbers = newState.useBigNumbers !== prevState.useBigNumbers;

if (isNewNotation || iseDifferentBigNumbers) {
const currentInput = useCalculatorStore.getState().input;

useCalculatorStore.setState({ input: "" })
await new Promise((resolve) => setTimeout(resolve, 10));
useCalculatorStore.setState({ input: currentInput + "" });
}
}
)
}


export { useSettingsStore }

0 comments on commit c292974

Please sign in to comment.