Skip to content

Commit 5dd7480

Browse files
authored
Merge pull request #143 from peelar/peelar/create-pr-logo-fix
2 parents a642a46 + d5385af commit 5dd7480

4 files changed

Lines changed: 51 additions & 6 deletions

File tree

.changeset/sour-rabbits-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"dopeshot-app": patch
3+
---
4+
5+
Apply brand logos automatically for testimonial layouts when auto-apply is enabled, not only screenshot layouts. Update the brand panel copy to reflect that the setting applies across assets, and add regression coverage for testimonial auto-apply behavior.

apps/app/src/components/brand/brand-panel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ export function BrandPanel() {
423423
htmlFor="use-logo"
424424
className="cursor-pointer text-sm font-normal"
425425
>
426-
Apply to all screenshots
426+
Apply automatically to all assets
427427
</Label>
428428
<Switch
429429
id="use-logo"

apps/app/src/hooks/use-brand-logo-auto-apply.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { brandSettingsAtom, configAtom, assetsAtom } from "@/hooks/atoms";
66
import { loadedMemoryItemIdAtom } from "@/hooks/atoms/memory";
77
import { useSession } from "@/lib/auth/auth-client";
88
import type { Asset } from "@/domain/asset/types";
9+
import { getLayoutFormat } from "@/domain/layout-def/definitions";
910

1011
/**
1112
* Automatically loads and applies brand logo for NEW designs (not loaded from memory).
@@ -21,6 +22,9 @@ export function useBrandLogoAutoApply(options: { enabled: boolean } = { enabled:
2122
const loadedItemId = useAtomValue(loadedMemoryItemIdAtom);
2223
const [error, setError] = useState<string | null>(null);
2324
const hasAppliedRef = useRef(false);
25+
const currentFormat = getLayoutFormat(config.layoutId);
26+
const canAutoApplyInCurrentFormat =
27+
currentFormat === "testimonial" || Boolean(config.assets?.screenshot);
2428
const prefetchPromiseRef = useRef<Promise<{ logoUrl: string; logoPath: string } | null> | null>(
2529
null,
2630
);
@@ -92,15 +96,15 @@ export function useBrandLogoAutoApply(options: { enabled: boolean } = { enabled:
9296
// - Feature is disabled
9397
// - Already applied this session
9498
// - Toggle is off
95-
// - Screenshot not uploaded yet
99+
// - Current format is not ready (screenshot formats require an uploaded screenshot)
96100
// - Logo already exists
97101
// - User not logged in
98102
// - Design was loaded from memory (brand logo handled in useMemory)
99103
if (
100104
!options.enabled ||
101105
hasAppliedRef.current ||
102106
!brandSettings.useLogoOnScreenshots ||
103-
!config.assets?.screenshot ||
107+
!canAutoApplyInCurrentFormat ||
104108
config.assets?.logo ||
105109
!session?.user ||
106110
loadedItemId // Skip for loaded designs - handled in useMemory
@@ -131,7 +135,7 @@ export function useBrandLogoAutoApply(options: { enabled: boolean } = { enabled:
131135
(asset) => asset.kind === "logo" && asset.url === logoUrl,
132136
);
133137

134-
// Apply logo to screenshot
138+
// Apply logo to the current canvas
135139
const brandLogoAsset: Asset = existingBrandLogo ?? {
136140
id: `brand-logo-${Date.now()}`,
137141
projectId: "brand",
@@ -167,10 +171,12 @@ export function useBrandLogoAutoApply(options: { enabled: boolean } = { enabled:
167171
assets,
168172
session?.user?.id,
169173
brandSettings.useLogoOnScreenshots,
174+
canAutoApplyInCurrentFormat,
170175
config.assets?.logo,
176+
config.assets?.screenshot,
177+
config.layoutId,
171178
options.enabled,
172179
loadedItemId,
173-
setBrandSettings,
174180
setAssets,
175181
setConfig,
176182
]);

apps/app/tests/ui/brand-logo-auto-apply.test.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { act, render, screen, waitFor } from "@testing-library/react";
1+
import { act, cleanup, render, screen, waitFor } from "@testing-library/react";
22
import { Provider, createStore, useAtomValue } from "jotai";
33
import { afterEach, describe, expect, it, vi } from "vitest";
44
import { brandSettingsAtom, configAtom, assetsAtom, getEmptyCanvasConfig } from "@/hooks/atoms";
55
import { loadedMemoryItemIdAtom } from "@/hooks/atoms/memory";
66
import { useBrandLogoAutoApply } from "@/hooks/use-brand-logo-auto-apply";
7+
import { getLayoutDefinition } from "@/domain/layout-def/definitions";
78

89
vi.mock("@/lib/auth/auth-client", () => ({
910
useSession: () => ({ data: { user: { id: "user-1" } } }),
1011
}));
1112

1213
afterEach(() => {
14+
cleanup();
1315
vi.unstubAllGlobals();
1416
});
1517

@@ -27,6 +29,38 @@ function LogoProbe() {
2729
}
2830

2931
describe("useBrandLogoAutoApply", () => {
32+
it("applies brand logo automatically on testimonial layouts", async () => {
33+
const store = createStore();
34+
const testimonialLayout = getLayoutDefinition("testimonial");
35+
if (!testimonialLayout) {
36+
throw new Error("testimonial layout definition is required for this test");
37+
}
38+
const testimonialConfig = testimonialLayout.createConfig();
39+
40+
store.set(brandSettingsAtom, {
41+
logoUrl: "https://cdn.test/logo.png",
42+
logoPath: "user-1/logo.png",
43+
useLogoOnScreenshots: true,
44+
accent: "#6366F1",
45+
mode: "dark",
46+
personality: "founder",
47+
});
48+
store.set(configAtom, testimonialConfig);
49+
store.set(assetsAtom, []);
50+
store.set(loadedMemoryItemIdAtom, null);
51+
52+
render(
53+
<Provider store={store}>
54+
<LogoProbe />
55+
</Provider>,
56+
);
57+
58+
await waitFor(() => {
59+
expect(screen.getByTestId("logo-id").textContent).not.toBe("none");
60+
expect(screen.getByTestId("asset-count").textContent).toBe("1");
61+
});
62+
});
63+
3064
it("reapplies the brand logo after resetting to a new design", async () => {
3165
const store = createStore();
3266
const screenshotAsset = {

0 commit comments

Comments
 (0)