Skip to content

Commit 68be838

Browse files
committed
make save content and style together at text content
1 parent 61cc4d5 commit 68be838

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

frontend/src/components/chat/code-engine/component-inspector/components/TypographyControls.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ export const TypographyControls: React.FC<TypographyControlsProps> = ({
1818
<span className="w-2 h-2 bg-blue-500 rounded-full mr-2"></span>
1919
Typography
2020
</div>
21-
<div className="text-xs text-muted-foreground">
22-
<span>Saved with style changes</span>
23-
</div>
2421
</h4>
2522
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 mb-3">
2623
<div>

frontend/src/components/chat/code-engine/component-inspector/tabs/ContentTab.tsx

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { Button } from '@/components/ui/button';
33
import { Textarea } from '@/components/ui/textarea';
44
import { ScrollArea } from '@/components/ui/scroll-area';
@@ -15,12 +15,15 @@ export const ContentTab: React.FC<ContentTabProps> = ({
1515
customStyles,
1616
computedStyles,
1717
isContentEdited,
18+
isStyleEdited,
1819
applyingChanges,
1920
editableContent,
2021
originalContent,
2122
setEditableContent,
2223
setIsContentEdited,
24+
setIsStyleEdited,
2325
applyContentChanges,
26+
applyStyleChanges,
2427
handleStyleChange
2528
}) => {
2629
// Check if content has changed from original
@@ -45,15 +48,20 @@ export const ContentTab: React.FC<ContentTabProps> = ({
4548
console.error('No component selected for content save');
4649
return;
4750
}
48-
49-
console.log('Saving content for component:', {
50-
id: selectedComponent.id,
51-
selector: selectedComponent.selector,
52-
tagName: selectedComponent.tagName,
53-
content: editableContent.substring(0, 50) + (editableContent.length > 50 ? '...' : '')
54-
});
5551

56-
applyContentChanges(editableContent);
52+
// Save content changes if needed
53+
if (hasContentChanged) {
54+
applyContentChanges(editableContent);
55+
}
56+
57+
// Always save typography style changes when we have custom styles
58+
if (Object.keys(customStyles).length > 0) {
59+
console.log("Applying style changes as we have custom styles");
60+
applyStyleChanges();
61+
} else if (isStyleEdited) {
62+
console.log("Applying style changes based on isStyleEdited flag");
63+
applyStyleChanges();
64+
}
5765
};
5866

5967
// Handle content changes with real-time preview updates
@@ -68,6 +76,17 @@ export const ContentTab: React.FC<ContentTabProps> = ({
6876
}
6977
};
7078

79+
// Wrapper for handleStyleChange that also sets isStyleEdited flag
80+
const handleTypographyStyleChange = (property: string, value: string) => {
81+
console.log("Typography style change:", property, value);
82+
83+
// Call the original style change handler
84+
handleStyleChange(property, value);
85+
86+
// Force isStyleEdited to true
87+
setIsStyleEdited(true);
88+
};
89+
7190
if (!selectedComponent) {
7291
return (
7392
<div className="p-3 sm:p-5 m-0 flex flex-col items-center justify-center h-full text-center">
@@ -103,11 +122,14 @@ export const ContentTab: React.FC<ContentTabProps> = ({
103122
variant="default"
104123
size="sm"
105124
className="text-xs h-8"
106-
onClick={handleContentSave}
107-
disabled={!hasContentChanged || applyingChanges}
125+
onClick={() => {
126+
console.log("Save button clicked, isStyleEdited:", isStyleEdited, "hasContentChanged:", hasContentChanged);
127+
handleContentSave();
128+
}}
129+
disabled={(!hasContentChanged && !isStyleEdited && Object.keys(customStyles).length === 0) || applyingChanges}
108130
>
109131
<Save className="w-3.5 h-3.5 mr-1.5" />
110-
Save Content
132+
Save Changes
111133
</Button>
112134
</div>
113135
</div>
@@ -134,7 +156,9 @@ export const ContentTab: React.FC<ContentTabProps> = ({
134156
<TypographyControls
135157
customStyles={customStyles}
136158
computedStyles={computedStyles}
137-
onChange={handleStyleChange}
159+
onChange={(property, value) => {
160+
handleTypographyStyleChange(property, value);
161+
}}
138162
/>
139163
</div>
140164
</ScrollArea>

frontend/src/components/chat/code-engine/component-inspector/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export interface ContentTabProps extends InspectorProps {
7777
originalContent: string;
7878
setEditableContent: (content: string) => void;
7979
handleStyleChange: (property: string, value: string) => void;
80+
setIsStyleEdited: (edited: boolean) => void;
8081
}
8182

8283
export interface ClassesTabProps extends InspectorProps {

0 commit comments

Comments
 (0)