refactor: remove unnecessary onFileChange, just handle onSave stuff in onFilesChange

This commit is contained in:
Dustin Healy 2025-09-07 01:59:53 -07:00
parent 384d6c870b
commit 2c1d7a6b71
5 changed files with 5 additions and 19 deletions

View file

@ -184,7 +184,6 @@ const CreatePromptForm = ({
onFilesChange={setFiles}
handleFileChange={handleFileChange}
disabled={isSubmitting}
onFileChange={() => {}}
/>
<Description
onValueChange={(value) => methods.setValue('oneliner', value)}

View file

@ -13,7 +13,6 @@ export default function PromptFile({
fileFilter,
isRTL = false,
Wrapper,
onFileChange,
}: {
files: Map<string, ExtendedFile> | undefined;
abortUpload?: () => void;
@ -22,7 +21,6 @@ export default function PromptFile({
fileFilter?: (file: ExtendedFile) => boolean;
isRTL?: boolean;
Wrapper?: React.FC<{ children: React.ReactNode }>;
onFileChange?: (files: ExtendedFile[]) => void;
}) {
const localize = useLocalize();
const { showToast } = useToastContext();
@ -103,11 +101,6 @@ export default function PromptFile({
if (file.temp_file_id) {
updatedFiles.delete(file.temp_file_id);
}
// Call onFileChange with the updated files array
const updatedFilesArray = Array.from(updatedFiles.values());
onFileChange?.(updatedFilesArray);
return updatedFiles;
});
};

View file

@ -12,13 +12,11 @@ const PromptFiles = ({
onFilesChange,
handleFileChange,
disabled,
onFileChange,
}: {
files: ExtendedFile[];
onFilesChange?: (files: ExtendedFile[]) => void;
handleFileChange?: (event: React.ChangeEvent<HTMLInputElement>, toolResource?: string) => void;
disabled?: boolean;
onFileChange?: (files: ExtendedFile[]) => void;
}) => {
const localize = useLocalize();
@ -65,7 +63,6 @@ const PromptFiles = ({
onFilesChange?.(newFiles);
}}
setFilesLoading={() => {}}
onFileChange={onFileChange}
Wrapper={({ children }) => <div className="flex flex-wrap gap-2">{children}</div>}
/>
</div>

View file

@ -541,15 +541,15 @@ const PromptForm = () => {
<PromptVariablesAndFiles
promptText={promptText}
files={hookPromptFiles}
onFilesChange={setFiles}
handleFileChange={handleFileChange}
disabled={!canEdit}
onFileChange={(updatedFiles) => {
onFilesChange={(files) => {
setFiles(files);
if (canEdit && selectedPrompt) {
const currentPromptText = getValues('prompt');
onSave(currentPromptText, updatedFiles);
onSave(currentPromptText, files);
}
}}
handleFileChange={handleFileChange}
disabled={!canEdit}
/>
<Description
initialValue={group.oneliner ?? ''}

View file

@ -10,7 +10,6 @@ interface PromptVariablesAndFilesProps {
handleFileChange?: (event: React.ChangeEvent<HTMLInputElement>, toolResource?: string) => void;
disabled?: boolean;
showVariablesInfo?: boolean;
onFileChange?: (files: ExtendedFile[]) => void;
}
const PromptVariablesAndFiles: React.FC<PromptVariablesAndFilesProps> = ({
@ -20,7 +19,6 @@ const PromptVariablesAndFiles: React.FC<PromptVariablesAndFilesProps> = ({
handleFileChange,
disabled,
showVariablesInfo = true,
onFileChange,
}) => {
return (
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2 lg:items-stretch">
@ -36,7 +34,6 @@ const PromptVariablesAndFiles: React.FC<PromptVariablesAndFilesProps> = ({
onFilesChange={onFilesChange}
handleFileChange={handleFileChange}
disabled={disabled}
onFileChange={onFileChange}
/>
</div>
</div>