Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions apps/web/src/features/texte/TexteGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const TAB_COMPONENT_NAMES: Record<TabId, string> = {
eigene: 'eigene-generators',
};

const UNIVERSAL_SUB_TYPES = ['rede', 'wahlprogramm', 'buergeranfragen', 'leichte_sprache'];

/**
* TexteGenerator - Main text generation interface with tabbed navigation.
*
Expand Down Expand Up @@ -92,12 +94,19 @@ const TexteGenerator: React.FC<TexteGeneratorProps> = ({ showHeaderFooter = true
}, [profile?.first_name, user?.display_name, user?.name]);

const hasGeneratedContent = useMemo(() => {
return Object.values(TAB_COMPONENT_NAMES).some((componentName) => {
const baseCheck = Object.values(TAB_COMPONENT_NAMES).some((componentName) => {
const content = generatedTexts[componentName];
if (!content) return false;
if (typeof content === 'string') return content.trim().length > 0;
return Object.keys(content).length > 0;
});
if (baseCheck) return true;
return UNIVERSAL_SUB_TYPES.some((subType) => {
const content = generatedTexts[`universal-text-${subType}`];
if (!content) return false;
if (typeof content === 'string') return content.trim().length > 0;
return Object.keys(content).length > 0;
});
}, [generatedTexts]);

useEffect(() => {
Expand All @@ -120,7 +129,9 @@ const TexteGenerator: React.FC<TexteGeneratorProps> = ({ showHeaderFooter = true

const wrapperClassName = useMemo(
() =>
['tabbed-layout', hasGeneratedContent && 'tabbed-layout--full-width'].filter(Boolean).join(' '),
['tabbed-layout', hasGeneratedContent && 'tabbed-layout--full-width']
.filter(Boolean)
.join(' '),
[hasGeneratedContent]
);

Expand Down
10 changes: 7 additions & 3 deletions apps/web/src/features/texte/tabs/UniversalTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ const EXTRAS_CONFIG: Partial<Record<UniversalSubType, ExtrasInputConfig>> = {
};

const UniversalTab: React.FC<UniversalTabProps> = memo(({ isActive, selectedType }) => {
const componentName = 'universal-text';
const componentName = `universal-text-${selectedType}`;

const redeFormRef = useRef<FormRef>(null);
const wahlprogrammFormRef = useRef<FormRef>(null);
const buergeranfragenFormRef = useRef<FormRef>(null);
const leichteSpracheFormRef = useRef<FormRef>(null);

const [extrasValue, setExtrasValue] = useState<string>('');
const [isLoading, setIsLoading] = useState(false);

const getCurrentFormRef = (): RefObject<FormRef | null> | null => {
switch (selectedType) {
Expand Down Expand Up @@ -129,7 +130,7 @@ const UniversalTab: React.FC<UniversalTabProps> = memo(({ isActive, selectedType

const setup = useGeneratorSetup({
instructionType: currentInstructionType,
componentName: 'universal-text',
componentName,
});

useEffect(() => {
Expand Down Expand Up @@ -202,6 +203,7 @@ const UniversalTab: React.FC<UniversalTabProps> = memo(({ isActive, selectedType

const formDataToSubmit = builder.buildSubmissionData(dataWithExtras);

setIsLoading(true);
try {
const { default: apiClient } = await import('../../../components/utils/apiClient');

Expand All @@ -221,6 +223,8 @@ const UniversalTab: React.FC<UniversalTabProps> = memo(({ isActive, selectedType
} else {
form.handleSubmitError(new Error(String(error)));
}
} finally {
setIsLoading(false);
}
}, [selectedType, form, currentFormRef, builder, extrasValue]);

Expand Down Expand Up @@ -293,11 +297,11 @@ const UniversalTab: React.FC<UniversalTabProps> = memo(({ isActive, selectedType
<>
{form.generator && (
<BaseForm
key={selectedType}
{...restBaseFormProps}
componentName={componentName}
enableEditMode={true}
onSubmit={handleSubmit}
loading={isLoading}
firstExtrasChildren={renderExtrasInput()}
>
{renderForm()}
Expand Down
Loading