Add advanced generation options with Explicit and Smart modes
- Implemented `AdvancedGenerationOptions` component for toggling Explicit and Smart modes with confirmation dialogs. - Integrated generation options into `GhostWriter`, `DraftCompanion`, and `ShortStoryGenerator`. - Introduced `ToggleWithConfirmation` component for user interaction with alerts. - Updated `InputField` to support centered alignment for better layout flexibility. - Localized Explicit and Smart mode strings in English and French. - Enhanced content preview logic to filter placeholder text before display. - Added `autoUpdater` initialization checks and refactored updater setup for improved reliability.
This commit is contained in:
63
components/form/ToggleWithConfirmation.tsx
Normal file
63
components/form/ToggleWithConfirmation.tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
'use client'
|
||||
import React, {useState} from "react";
|
||||
import ToggleSwitch from "@/components/form/ToggleSwitch";
|
||||
import AlertBox, {AlertType} from "@/components/AlertBox";
|
||||
|
||||
interface ToggleWithConfirmationProps {
|
||||
checked: boolean;
|
||||
onChange: (checked: boolean) => void;
|
||||
alertTitle: string;
|
||||
alertMessage: string;
|
||||
alertType: AlertType;
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export default function ToggleWithConfirmation({
|
||||
checked,
|
||||
onChange,
|
||||
alertTitle,
|
||||
alertMessage,
|
||||
alertType,
|
||||
confirmText = "Activer",
|
||||
cancelText = "Annuler",
|
||||
disabled = false
|
||||
}: ToggleWithConfirmationProps) {
|
||||
const [showAlert, setShowAlert] = useState<boolean>(false);
|
||||
|
||||
function handleToggle(newChecked: boolean): void {
|
||||
if (newChecked) {
|
||||
setShowAlert(true);
|
||||
} else {
|
||||
onChange(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleConfirm(): Promise<void> {
|
||||
onChange(true);
|
||||
setShowAlert(false);
|
||||
}
|
||||
|
||||
function handleCancel(): void {
|
||||
setShowAlert(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ToggleSwitch checked={checked} onChange={handleToggle} disabled={disabled}/>
|
||||
|
||||
{showAlert && (
|
||||
<AlertBox
|
||||
title={alertTitle}
|
||||
message={alertMessage}
|
||||
type={alertType}
|
||||
confirmText={confirmText}
|
||||
cancelText={cancelText}
|
||||
onConfirm={handleConfirm}
|
||||
onCancel={handleCancel}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user