Skip to content

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

feat: added link for sharing files and folders, refactoring entry properties

Ilian Sapundshievc794070d941a
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsx
index 7accdfef9..16c13c717 100644
--- a/app/components/EntryProperties.tsx
+++ b/app/components/EntryProperties.tsx
@@ -28,6 +28,7 @@ import Typography from '@material-ui/core/Typography';
import TextField from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
import InputAdornment from '@material-ui/core/InputAdornment';
+import ShareIcon from '@material-ui/icons/Link';
import LocationIcon from '@material-ui/icons/WorkOutline';
import CloudLocationIcon from '@material-ui/icons/CloudQueue';
import DOMPurify from 'dompurify';
@@ -190,6 +191,7 @@ interface Props {
const EntryProperties = (props: Props) => {
// const EntryProperties = React.memo((props: Props) => {
const fileNameRef = useRef<HTMLInputElement>(null);
+ const sharingLinkRef = useRef<HTMLInputElement>(null);
const fileDescriptionRef = useRef<HTMLInputElement>(null);
const MB_ATTR =
'<b>Leaflet</b> | Map data &copy; <b>https://openstreetmap.org/copyright</b> contributors, <b>CC-BY-SA</b>, Imagery © <b>Mapbox</b>';
@@ -202,6 +204,7 @@ const EntryProperties = (props: Props) => {
const customRenderer = new marked.Renderer();
customRenderer.link = (href, title, text) => `
<a href="#"
+ title="${href}"
onClick="event.preventDefault(); event.stopPropagation(); window.postMessage(JSON.stringify({ command: 'openLinkExternally', link: '${href}' }), '*'); return false;">
${text}
</a>`;
@@ -656,6 +659,12 @@ const EntryProperties = (props: Props) => {
}
const geoLocation: any = getGeoLocation(currentEntry.tags);
+
+ let sharingLink = window.location.href;
+ if (sharingLink.indexOf('?') > 0) {
+ sharingLink = 'ts:' + sharingLink.substr(sharingLink.indexOf('?'));
+ }
+
// @ts-ignore
return (
<div className={classes.entryProperties}>
@@ -671,49 +680,50 @@ const EntryProperties = (props: Props) => {
{i18n.t('core:editTagMasterName')}
</Typography>
</div>
- {!isReadOnlyMode &&
- !currentEntry.editMode &&
- editDescription === undefined && (
- <div
- className={classes.gridItem}
- style={{ textAlign: 'right' }}
- >
- {editName !== undefined ? (
- <div>
- <Button
- data-tid="cancelRenameEntryTID"
- color="primary"
- className={classes.button}
- onClick={deactivateEditNameField}
- >
- {i18n.t('core:cancel')}
- </Button>
- <Button
- data-tid="confirmRenameEntryTID"
- color="primary"
- className={classes.button}
- onClick={renameEntry}
- >
- {i18n.t('core:confirmSaveButton')}
- </Button>
- </div>
- ) : (
- <Button
- data-tid="startRenameEntryTID"
- color="primary"
- className={classes.button}
- onClick={activateEditNameField}
- >
- {i18n.t('core:rename')}
- </Button>
- )}
- </div>
- )}
</div>
<FormControl fullWidth={true} className={classes.formControl}>
<TextField
InputProps={{
- readOnly: editName === undefined
+ readOnly: editName === undefined,
+ endAdornment: (
+ <InputAdornment position="end">
+ {!isReadOnlyMode &&
+ !currentEntry.editMode &&
+ editDescription === undefined && (
+ <div
+ className={classes.gridItem}
+ style={{ textAlign: 'right' }}
+ >
+ {editName !== undefined ? (
+ <div>
+ <Button
+ data-tid="cancelRenameEntryTID"
+ color="primary"
+ onClick={deactivateEditNameField}
+ >
+ {i18n.t('core:cancel')}
+ </Button>
+ <Button
+ data-tid="confirmRenameEntryTID"
+ color="primary"
+ onClick={renameEntry}
+ >
+ {i18n.t('core:confirmSaveButton')}
+ </Button>
+ </div>
+ ) : (
+ <Button
+ data-tid="startRenameEntryTID"
+ color="primary"
+ onClick={activateEditNameField}
+ >
+ {i18n.t('core:rename')}
+ </Button>
+ )}
+ </div>
+ )}
+ </InputAdornment>
+ )
}}
margin="dense"
name="name"
@@ -967,6 +977,7 @@ const EntryProperties = (props: Props) => {
setColor={handleChangeColor}
onClose={toggleBackgroundColorPicker}
presetColors={[
+ 'transparent',
'#FFFFFF44',
'#00000044',
'#ac725e44',
@@ -1008,19 +1019,6 @@ const EntryProperties = (props: Props) => {
{i18n.t('core:filePath')}
</Typography>
</div>
- {currentEntry.isFile &&
- !isReadOnlyMode &&
- !currentEntry.editMode &&
- editName === undefined &&
- editDescription === undefined && (
- <Button
- color="primary"
- className={classes.button}
- onClick={toggleMoveCopyFilesDialog}
- >
- {i18n.t('core:move')}
- </Button>
- )}
</div>
<FormControl fullWidth={true} className={classes.formControl}>
<TextField
@@ -1040,6 +1038,67 @@ const EntryProperties = (props: Props) => {
<LocationIcon />
)}
</InputAdornment>
+ ),
+ endAdornment: (
+ <InputAdornment position="end">
+ {currentEntry.isFile &&
+ !isReadOnlyMode &&
+ !currentEntry.editMode &&
+ editName === undefined &&
+ editDescription === undefined && (
+ <Button
+ color="primary"
+ onClick={toggleMoveCopyFilesDialog}
+ >
+ {i18n.t('core:move')}
+ </Button>
+ )}
+ </InputAdornment>
+ )
+ }}
+ />
+ </FormControl>
+ </Grid>
+
+ <Grid item xs={12}>
+ <div className={classes.fluidGrid}>
+ <div className={classes.gridItem}>
+ <Typography
+ variant="caption"
+ className={classNames(classes.header)}
+ style={{ display: 'block' }}
+ >
+ {i18n.t('core:SharingLink')}
+ </Typography>
+ </div>
+ </div>
+ <FormControl fullWidth={true} className={classes.formControl}>
+ <TextField
+ margin="dense"
+ name="path"
+ title="Sharing Link"
+ fullWidth={true}
+ value={sharingLink}
+ inputRef={sharingLinkRef}
+ InputProps={{
+ readOnly: true,
+ startAdornment: (
+ <InputAdornment position="start">
+ <ShareIcon />
+ </InputAdornment>
+ ),
+ endAdornment: (
+ <InputAdornment position="end">
+ <Button
+ color="primary"
+ onClick={() => {
+ sharingLinkRef.current.select();
+ document.execCommand('copy');
+ }}
+ >
+ {i18n.t('core:copy')}
+ </Button>
+ </InputAdornment>
)
}}
/>
@@ -1102,6 +1161,7 @@ const EntryProperties = (props: Props) => {
<Button
color="primary"
className={classes.button}
+ style={{ whiteSpace: 'nowrap' }}
onClick={toggleThumbFilesDialog}
>
{i18n.t('core:changeThumbnail')}