diff --git a/frontend/apps/editor3d/app/src/components/signaled/TopBar/TopBar.tsx b/frontend/apps/editor3d/app/src/components/signaled/TopBar/TopBar.tsx index d4084bf060..10907d2ebf 100644 --- a/frontend/apps/editor3d/app/src/components/signaled/TopBar/TopBar.tsx +++ b/frontend/apps/editor3d/app/src/components/signaled/TopBar/TopBar.tsx @@ -1,4 +1,4 @@ -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { faGear, faImages, @@ -18,7 +18,6 @@ import { } from "@fortawesome/pro-regular-svg-icons"; import { Button } from "@storyteller/ui-button"; import { PopoverMenu } from "@storyteller/ui-popover"; -import { AuthButtons } from "./AuthButtons"; import { SceneTitleInput } from "./SceneTitleInput"; import { Activity } from "~/pages/PageEnigma/comps/GenerateModals/Activity"; import { @@ -58,6 +57,10 @@ import { usePricingModalStore, useCreditsModalStore, } from "@storyteller/ui-pricing-modal"; +import { useCreditsBalanceChangedEvent } from "@storyteller/tauri-events"; +import { useSubscriptionPlanChangedEvent } from "@storyteller/tauri-events"; +import { useCreditsState } from "@storyteller/credits"; +import { useSubscriptionState } from "@storyteller/subscription"; interface Props { pageName: string; @@ -76,7 +79,7 @@ type SettingsSection = const SWITCHER_THROTTLE_TIME = 500; // milliseconds // NB: See `TabState` for the default tab. -const appMenuTabs: MenuIconItem[] = [ +const appMenuTabs: MenuIconItem[] = [ { id: "IMAGE", label: "Text to Image", @@ -150,6 +153,26 @@ export const TopBar = ({ pageName, loginSignUpPressed }: Props) => { const [disableSwitcher, setDisableSwitcher] = useState(false); const switcherThrottle = useRef(false); + const creditsStore = useCreditsState(); + const sumTotalCredits = creditsStore.totalCredits; + + //const subscriptionStore = useSubscriptionState(); + //const hasPaidPlan = subscriptionStore.hasPaidPlan(); + const hasPaidPlan = false; + + useEffect(() => { + creditsStore.fetchFromServer(); + //subscriptionStore.fetchFromServer(); + }, []); + + useCreditsBalanceChangedEvent(async () => { + creditsStore.fetchFromServer(); + }); + + useSubscriptionPlanChangedEvent(async () => { + //subscriptionStore.fetchFromServer(); + }); + const disableTabSwitcher = () => { return ( disableSwitcher || @@ -218,13 +241,43 @@ export const TopBar = ({ pageName, loginSignUpPressed }: Props) => { const pageTitle = getPageTitle(); - const { toggleModal } = usePricingModalStore(); + const { toggleModal: toggleSubscriptionModal } = usePricingModalStore(); const { toggleModal: toggleCreditsModal } = useCreditsModalStore(); + // Pick logo based on current theme (light uses black logo; others use white) + const [logoSrc, setLogoSrc] = useState( + "/resources/logo/artcraft-logo-color-white.svg", + ); + useEffect(() => { + const computeLogo = () => { + const root = document.documentElement; + const isLight = root.classList.contains("theme-light"); + setLogoSrc( + isLight + ? "/resources/logo/artcraft-logo-color-black.svg" + : "/resources/logo/artcraft-logo-color-white.svg", + ); + }; + computeLogo(); + const mo = new MutationObserver((muts) => { + for (const m of muts) { + if (m.type === "attributes" && m.attributeName === "class") { + computeLogo(); + break; + } + } + }); + mo.observe(document.documentElement, { + attributes: true, + attributeFilter: ["class"], + }); + return () => mo.disconnect(); + }, []); + return ( <>