Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Creating emptry url file should not be possible

Stanimirfa11312074ae
diff --git a/src/renderer/components/dialogs/NewFileDialog.tsx b/src/renderer/components/dialogs/NewFileDialog.tsx
index 550c0bb7d..2a4d632d4 100644
--- a/src/renderer/components/dialogs/NewFileDialog.tsx
+++ b/src/renderer/components/dialogs/NewFileDialog.tsx
@@ -58,6 +58,7 @@ function NewFileDialog(props: Props) {
const { currentDirectoryPath } = useDirectoryContentContext();
const { targetDirectoryPath } = useTargetPathContext();
const haveError = useRef<boolean>(false);
+ const urlInputError = useRef<string>(undefined);
const firstRWLocation = getFirstRWLocation();
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
@@ -100,14 +101,20 @@ function NewFileDialog(props: Props) {
function createFile(fileType, targetPath) {
if (targetPath) {
- loadLocation();
- createFileAdvanced(
- targetPath,
- fileName.current,
- fileContent.current,
- fileType,
- );
- onClose();
+ if (fileType === 'url' && !fileContent.current) {
+ haveError.current = true;
+ urlInputError.current = t('core:emptyLink');
+ forceUpdate();
+ } else {
+ loadLocation();
+ createFileAdvanced(
+ targetPath,
+ fileName.current,
+ fileContent.current,
+ fileType,
+ );
+ onClose();
+ }
}
}
@@ -162,8 +169,10 @@ function NewFileDialog(props: Props) {
}
haveError={(error) => {
haveError.current = error;
+ urlInputError.current = '';
forceUpdate();
}}
+ urlInputError={urlInputError.current}
fileName={fileName.current}
/>
) : (
diff --git a/src/renderer/components/dialogs/components/CreateLink.tsx b/src/renderer/components/dialogs/components/CreateLink.tsx
index 418f67471..a5be61d6a 100644
--- a/src/renderer/components/dialogs/components/CreateLink.tsx
+++ b/src/renderer/components/dialogs/components/CreateLink.tsx
@@ -46,6 +46,7 @@ interface Props {
handleFileContentChange: (fileContent: string) => void;
createFile: (fileType: TS.FileType) => void;
haveError: (error: boolean) => void;
+ urlInputError?: string;
tidPrefix?: string;
}
@@ -57,6 +58,7 @@ function CreateLink(props: Props) {
handleFileNameChange,
handleFileContentChange,
haveError,
+ urlInputError,
} = props;
const { t } = useTranslation();
const { targetDirectoryPath } = useTargetPathContext();
@@ -146,10 +148,10 @@ function CreateLink(props: Props) {
<FormHelperText>{t('core:fileNameHelp')}</FormHelperText>
)}
</FormControl>
- <FormControl fullWidth={true} error={urlError}>
+ <FormControl fullWidth={true} error={urlError || !!urlInputError}>
<TsTextField
autoFocus
- error={urlError}
+ error={urlError || !!urlInputError}
id="fileLinkID"
label={t('core:linkURL')}
onChange={handleUrlChange}
@@ -157,6 +159,7 @@ function CreateLink(props: Props) {
{urlError && (
<FormHelperText>{t('core:urlValidationHelp')}</FormHelperText>
)}
+ {urlInputError && <FormHelperText>{urlInputError}</FormHelperText>}
</FormControl>
</StyledGrid>
);
diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.json
index 8c8c58529..bbb2809ec 100644
--- a/src/renderer/locales/en/core.json
+++ b/src/renderer/locales/en/core.json
@@ -608,6 +608,7 @@
"editSavedSearchTitle": "Edit Search Query",
"savedSearchHelp": "Save the current search parameters for a later use of this search",
"emptyTitle": "Title cannot be empty!",
+ "emptyLink": "Link cannot be empty!",
"duplicateTitle": "Search name already exist!",
"savedSearchesTitle": "Stored Search Queries",
"exportCsv": "Export current file and folder list as CSV file",