Skip to content

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

fix: optimizing setting custom background, color and thumbnail in the entry properties

Ilian Sapundshiev6b4a97d057d9
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsx
index 0a8cbfa0d..6e981c9c1 100644
--- a/app/components/EntryProperties.tsx
+++ b/app/components/EntryProperties.tsx
@@ -160,10 +160,10 @@ interface Props {
}
const defaultBackgrounds = [
- 'linear-gradient(43deg, rgb(65, 88, 208) 0%, rgb(200, 80, 192) 46%, rgb(255, 204, 112) 100%)',
- 'linear-gradient( 102.4deg, rgba(253,189,85,1) 7.8%, rgba(249,131,255,1) 100.3% )',
- 'linear-gradient( 109.6deg, rgba(48,207,208,1) 11.2%, rgba(51,8,103,1) 92.5% )',
- 'radial-gradient( circle 321px at 8.3% 75.7%, rgba(209,247,241,1) 0%, rgba(249,213,213,1) 81% )'
+ 'linear-gradient(43deg, rgb(65, 88, 208) 0%, rgb(200, 80, 190) 45%, rgb(255, 204, 112) 100%)',
+ 'linear-gradient( 102deg, rgba(253,189,85,1) 8%, rgba(249,131,255,1) 100% )',
+ 'radial-gradient( circle 321px at 8% 75%, rgba(209,247,241,1) 0%, rgba(249,213,213,1) 80% )',
+ 'linear-gradient( 110deg, rgba(48,207,208,1) 11.2%, rgba(51,8,103,1) 90% )'
];
function EntryProperties(props: Props) {
@@ -1026,129 +1026,88 @@ function EntryProperties(props: Props) {
</Grid>
)}
- <Grid item xs={12}>
- <TextField
- margin="dense"
- name="path"
- label={i18n.t('core:backgroundColor')}
- fullWidth
- InputProps={{
- readOnly: true,
- startAdornment: (
- <InputAdornment position="start">
- {/* <Tooltip title={i18n.t('core:changeBackgroundColor')}> */}
- <TransparentBackground>
- <Button
- fullWidth
- style={{
- width: 100,
- background: currentEntry.color
- }}
- onClick={toggleBackgroundColorPicker}
- >
- &nbsp;
- </Button>
- </TransparentBackground>
- {/* </Tooltip> */}
- </InputAdornment>
- ),
- endAdornment: (
- <InputAdornment position="end">
- <Stack direction="row" spacing={1}>
- {defaultBackgrounds.map((background, cnt) => (
- <IconButton
- key={cnt}
- aria-label="fingerprint"
- onClick={() => handleChangeColor(background)}
- style={{
- backgroundImage: background
- }}
- >
- <SetBackgroundIcon />
- </IconButton>
- ))}
- {currentEntry.color && (
- <>
- <ProTooltip tooltip={i18n.t('clearFolderColor')}>
- <span>
- <IconButton
- disabled={!Pro}
- aria-label="clear"
- size="small"
- style={{ marginTop: 5 }}
- onClick={() =>
- setConfirmResetColorDialogOpened(true)
- }
- >
- <ClearBackgroundIcon />
- </IconButton>
- </span>
- </ProTooltip>
- </>
- )}
- </Stack>
- </InputAdornment>
- )
- }}
- />
- </Grid>
- <Grid container item xs={12} spacing={1}>
- <Grid item xs={6}>
- <ThumbnailTextField
+ {!currentEntry.isFile && (
+ <Grid item xs={12} style={{ marginTop: 5 }}>
+ <TextField
margin="dense"
- label={i18n.t('core:thumbnail')}
+ name="path"
+ label={
+ <>
+ {i18n.t('core:backgroundColor')}
+ <InfoIcon
+ tooltip={i18n.t(
+ 'The background color will not be visible if you have set a background image'
+ )}
+ />
+ </>
+ }
fullWidth
InputProps={{
readOnly: true,
startAdornment: (
+ <InputAdornment position="start" style={{ marginTop: 10 }}>
+ {/* <Tooltip title={i18n.t('core:changeBackgroundColor')}> */}
+ <TransparentBackground>
+ <Button
+ fullWidth
+ style={{
+ width: 100,
+ background: currentEntry.color
+ }}
+ onClick={toggleBackgroundColorPicker}
+ >
+ &nbsp;
+ </Button>
+ </TransparentBackground>
+ {/* </Tooltip> */}
+ </InputAdornment>
+ ),
+ endAdornment: (
<InputAdornment position="end">
- <Stack
- direction="row"
- spacing={1}
- style={{ alignItems: 'center' }}
- >
- <ProTooltip tooltip={i18n.t('changeThumbnail')}>
- <div
- role="button"
- tabIndex={0}
+ <Stack direction="row" spacing={1}>
+ {defaultBackgrounds.map((background, cnt) => (
+ <IconButton
+ key={cnt}
+ aria-label="fingerprint"
+ onClick={() => handleChangeColor(background)}
style={{
- backgroundSize: 'contain',
- backgroundRepeat: 'no-repeat',
- backgroundImage: thumbPathUrl,
- backgroundPosition: 'center',
- minHeight: 150,
- minWidth: 150,
- marginBottom: 5
+ backgroundImage: background
}}
- onClick={toggleThumbFilesDialog}
- />
- </ProTooltip>
- {!isReadOnlyMode &&
- !currentEntry.editMode &&
- editName === undefined &&
- editDescription === undefined && (
- <ProTooltip tooltip={i18n.t('changeThumbnail')}>
- <IconButton
- disabled={!Pro}
- color="primary"
- className={classes.button}
- style={{ whiteSpace: 'nowrap' }}
- onClick={toggleThumbFilesDialog}
- >
- <EditIcon />
- </IconButton>
+ >
+ <SetBackgroundIcon />
+ </IconButton>
+ ))}
+ {currentEntry.color && (
+ <>
+ <ProTooltip tooltip={i18n.t('clearFolderColor')}>
+ <span>
+ <IconButton
+ disabled={!Pro}
+ aria-label="clear"
+ size="small"
+ style={{ marginTop: 5 }}
+ onClick={() =>
+ setConfirmResetColorDialogOpened(true)
+ }
+ >
+ <ClearBackgroundIcon />
+ </IconButton>
+ </span>
</ProTooltip>
- )}
+ </>
+ )}
</Stack>
</InputAdornment>
)
}}
/>
</Grid>
- <Grid item xs={6}>
+ )}
+ <Grid container item xs={12} spacing={1}>
+ <Grid item xs={currentEntry.isFile ? 12 : 6}>
<ThumbnailTextField
margin="dense"
- label={i18n.t('core:backgroundImage')}
+ label={i18n.t('core:thumbnail')}
fullWidth
InputProps={{
readOnly: true,
@@ -1159,33 +1118,34 @@ function EntryProperties(props: Props) {
spacing={1}
style={{ alignItems: 'center' }}
>
- <ProTooltip tooltip={i18n.t('changeBackgroundImage')}>
+ <ProTooltip tooltip={i18n.t('changeThumbnail')}>
<div
role="button"
tabIndex={0}
style={{
- backgroundSize: 'contain',
+ backgroundSize: 'cover',
backgroundRepeat: 'no-repeat',
- backgroundImage: bgndPathUrl,
+ backgroundImage: thumbPathUrl,
backgroundPosition: 'center',
+ borderRadius: 8,
minHeight: 150,
minWidth: 150,
marginBottom: 5
}}
- onClick={toggleBgndImgDialog}
+ onClick={toggleThumbFilesDialog}
/>
</ProTooltip>
{!isReadOnlyMode &&
!currentEntry.editMode &&
editName === undefined &&
editDescription === undefined && (
- <ProTooltip tooltip={i18n.t('changeBackgroundImage')}>
+ <ProTooltip tooltip={i18n.t('changeThumbnail')}>
<IconButton
disabled={!Pro}
color="primary"
className={classes.button}
style={{ whiteSpace: 'nowrap' }}
- onClick={toggleBgndImgDialog}
+ onClick={toggleThumbFilesDialog}
>
<EditIcon />
</IconButton>
@@ -1197,7 +1157,65 @@ function EntryProperties(props: Props) {
}}
/>
</Grid>
+ {!currentEntry.isFile && (
+ <Grid item xs={6}>
+ <ThumbnailTextField
+ margin="dense"
+ label={i18n.t('core:backgroundImage')}
+ fullWidth
+ InputProps={{
+ readOnly: true,
+ startAdornment: (
+ <InputAdornment position="end">
+ <Stack
+ direction="row"
+ spacing={1}
+ style={{ alignItems: 'center' }}
+ >
+ <ProTooltip tooltip={i18n.t('changeBackgroundImage')}>
+ <div
+ role="button"
+ tabIndex={0}
+ style={{
+ backgroundSize: 'cover',
+ backgroundRepeat: 'no-repeat',
+ backgroundImage: bgndPathUrl,
+ backgroundPosition: 'center',
+ borderRadius: 8,
+ minHeight: 150,
+ minWidth: 150,
+ marginBottom: 5
+ }}
+ onClick={toggleBgndImgDialog}
+ />
+ </ProTooltip>
+ {!isReadOnlyMode &&
+ !currentEntry.editMode &&
+ editName === undefined &&
+ editDescription === undefined && (
+ <ProTooltip
+ tooltip={i18n.t('changeBackgroundImage')}
+ >
+ <IconButton
+ disabled={!Pro}
+ color="primary"
+ className={classes.button}
+ style={{ whiteSpace: 'nowrap' }}
+ onClick={toggleBgndImgDialog}
+ >
+ <EditIcon />
+ </IconButton>
+ </ProTooltip>
+ )}
+ </Stack>
+ </InputAdornment>
+ )
+ }}
+ />
+ </Grid>
+ )}
</Grid>
+ <Grid container item xs={12} style={{ height: 150 }}></Grid>
</Grid>
{isConfirmResetColorDialogOpened && (
<ConfirmDialog
diff --git a/app/components/TransparentBackground.tsx b/app/components/TransparentBackground.tsx
index d1347005a..f7d8d5fc0 100644
--- a/app/components/TransparentBackground.tsx
+++ b/app/components/TransparentBackground.tsx
@@ -25,6 +25,7 @@ function TransparentBackground(props: Props) {
return (
<span
style={{
+ borderRadius: 5,
background:
'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMUlEQVQ4T2NkYGAQYcAP3uCTZhw1gGGYhAGBZIA/nYDCgBDAm9BGDWAAJyRCgLaBCAAgXwixzAS0pgAAAABJRU5ErkJggg==")'
}}
diff --git a/app/services/thumbsgenerator.ts b/app/services/thumbsgenerator.ts
index cc8f0ea01..060218f32 100644
--- a/app/services/thumbsgenerator.ts
+++ b/app/services/thumbsgenerator.ts
@@ -30,7 +30,7 @@ import { base64ToArrayBuffer } from '-/utils/dom';
import PlatformIO from '../services/platform-facade';
import { Pro } from '../pro';
-const maxSize = AppConfig.maxThumbSize;
+let maxSize = AppConfig.maxThumbSize;
const bgColor = AppConfig.thumbBgColor;
export const supportedMisc = ['url', 'html'];
@@ -301,12 +301,19 @@ function generateDefaultThumbnail() {
return Promise.resolve('');
}
-export function generateImageThumbnail(fileURL): Promise<string> {
+export function generateImageThumbnail(
+ fileURL: string,
+ maxTmbSize?: number
+): Promise<string> {
return new Promise(resolve => {
let canvas: HTMLCanvasElement = document.createElement('canvas');
const ctx = canvas.getContext('2d');
let img: HTMLImageElement = new Image();
+ if (maxTmbSize && maxTmbSize > maxSize) {
+ maxSize = maxTmbSize;
+ }
+
const errorHandler = err => {
console.warn(
'Error while generating thumbnail for: ' +
@@ -351,6 +358,7 @@ export function generateImageThumbnail(fileURL): Promise<string> {
// default:
// // ctx.rotate(0);
// }
+ // if (img.width > maxSize || img.height > maxSize) { // uncomment to do not extend smaller images
if (img.width >= img.height) {
canvas.width = maxSize;
canvas.height = (maxSize * img.height) / img.width;
@@ -358,8 +366,11 @@ export function generateImageThumbnail(fileURL): Promise<string> {
canvas.height = maxSize;
canvas.width = (maxSize * img.width) / img.height;
}
- const { width } = canvas;
- const { height } = canvas;
+ // } else {
+ // canvas.width = img.width;
+ // canvas.height = img.height;
+ // }
+ const { width, height } = canvas;
const x = canvas.width / 2;
const y = canvas.height / 2;