chore: result file name

This commit is contained in:
Ibrahima G. Coulibaly
2025-03-26 20:24:46 +00:00
parent c3023ae4ef
commit ab587e60d0
7 changed files with 114 additions and 61 deletions

View File

@@ -49,7 +49,8 @@ export default function ToolFileResult({
const handleDownload = () => {
if (value) {
const filename = 'output-omni-tools.' + extension;
const hasExtension = value.name.includes('.');
const filename = hasExtension ? value.name : `${value.name}.${extension}`;
const blob = new Blob([value], { type: value.type });
const url = window.URL.createObjectURL(blob);

View File

@@ -1,16 +1,19 @@
import { Box, TextField } from '@mui/material';
import React, { useContext, useEffect } from 'react';
import React, { useContext } from 'react';
import { CustomSnackBarContext } from '../../contexts/CustomSnackBarContext';
import InputHeader from '../InputHeader';
import ResultFooter from './ResultFooter';
import { replaceSpecialCharacters } from '../../utils/string';
import { replaceSpecialCharacters } from '@utils/string';
import mime from 'mime';
export default function ToolTextResult({
title = 'Result',
value
value,
extension = 'txt'
}: {
title?: string;
value: string;
extension?: string;
}) {
const { showSnackBar } = useContext(CustomSnackBarContext);
const handleCopy = () => {
@@ -22,9 +25,13 @@ export default function ToolTextResult({
});
};
const handleDownload = () => {
const filename = 'output-omni-tools.txt';
const filename = `output-omni-tools.${extension}`;
const blob = new Blob([value], { type: 'text/plain' });
const mimeType = mime.getType(extension) || 'text/plain';
const blob = new Blob([value], {
type: mimeType
});
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;

View File

@@ -86,7 +86,9 @@ export default function JsonToXml({ title }: ToolComponentProps) {
inputComponent={
<ToolTextInput title="Input Json" value={input} onChange={setInput} />
}
resultComponent={<ToolTextResult title="Output XML" value={result} />}
resultComponent={
<ToolTextResult title="Output XML" value={result} extension={'xml'} />
}
getGroups={({ values, updateField }) => [
{
title: 'Output XML Indentation',