Skip to content

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

TSN925---Folder-background-improvements925 (#1738)

Stanimir2c78ee1d65d6
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsx
index 6e981c9c1..960b6e61e 100644
--- a/app/components/EntryProperties.tsx
+++ b/app/components/EntryProperties.tsx
@@ -71,7 +71,11 @@ import {
replaceThumbnailURLPromise,
getThumbnailURLPromise
} from '-/services/thumbsgenerator';
-import { OpenedEntry } from '-/reducers/app';
+import {
+ getLastBackgroundImageChange,
+ getLastThumbnailImageChange,
+ OpenedEntry
+} from '-/reducers/app';
import { savePerspective } from '-/utils/metaoperations';
import MarkerIcon from '-/assets/icons/marker-icon.png';
import Marker2xIcon from '-/assets/icons/marker-icon-2x.png';
@@ -82,7 +86,7 @@ import NoTileServer from '-/components/NoTileServer';
import InfoIcon from '-/components/InfoIcon';
import { ProTooltip } from '-/components/HelperComponents';
import PerspectiveSelector from '-/components/PerspectiveSelector';
-import FormControlLabel from '@mui/material/FormControlLabel';
+import { connect } from 'react-redux';
const ThumbnailChooserDialog =
Pro && Pro.UI ? Pro.UI.ThumbnailChooserDialog : false;
@@ -157,6 +161,8 @@ interface Props {
tagDelimiter: string;
sharingLink: string;
tileServer: TS.MapTileServer;
+ lastBackgroundImageChange: number;
+ lastThumbnailImageChange: number;
}
const defaultBackgrounds = [
@@ -365,7 +371,10 @@ function EntryProperties(props: Props) {
.then(objUrl => {
props.updateThumbnailUrl(
currentEntry.path,
- objUrl.tmbPath + '?' + new Date().getTime()
+ objUrl.tmbPath +
+ (props.lastThumbnailImageChange
+ ? '?' + props.lastThumbnailImageChange
+ : '')
);
return true;
})
@@ -506,11 +515,27 @@ function EntryProperties(props: Props) {
let url;
let bgndUrl;
if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {
- url = PlatformIO.getURLforPath(thumbPath);
- bgndUrl = PlatformIO.getURLforPath(bgndPath);
+ if (thumbPath !== undefined) {
+ url = PlatformIO.getURLforPath(thumbPath);
+ }
+ if (bgndPath !== undefined) {
+ bgndUrl = PlatformIO.getURLforPath(bgndPath);
+ }
} else {
- url = normalizeUrl(thumbPath) + '?' + new Date().getTime();
- bgndUrl = normalizeUrl(bgndPath) + '?' + new Date().getTime();
+ if (thumbPath !== undefined) {
+ url =
+ normalizeUrl(thumbPath) +
+ (props.lastThumbnailImageChange
+ ? '?' + props.lastThumbnailImageChange
+ : '');
+ }
+ if (bgndPath !== undefined) {
+ bgndUrl =
+ normalizeUrl(bgndPath) +
+ (props.lastBackgroundImageChange
+ ? '?' + props.lastBackgroundImageChange
+ : '');
+ }
}
const thumbPathUrl = thumbPath ? 'url("' + url + '")' : '';
const bgndPathUrl = bgndPath ? 'url("' + bgndUrl + '")' : '';
@@ -1249,7 +1274,8 @@ function EntryProperties(props: Props) {
<ThumbnailChooserDialog
open={isFileThumbChooseDialogOpened}
onClose={toggleThumbFilesDialog}
- selectedFile={thumbPath}
+ selectedFile={currentEntry.path}
+ thumbPath={thumbPath}
setThumb={setThumb}
/>
)}
@@ -1307,6 +1333,14 @@ const ThumbnailTextField = withStyles((theme: Theme) =>
})
)(TextField);
+function mapStateToProps(state) {
+ return {
+ lastBackgroundImageChange: getLastBackgroundImageChange(state),
+ lastThumbnailImageChange: getLastThumbnailImageChange(state)
+ };
+}
export default withLeaflet(
- withStyles(styles, { withTheme: true })(EntryProperties)
+ connect(mapStateToProps)(
+ withStyles(styles, { withTheme: true })(EntryProperties)
+ )
);
diff --git a/app/perspectives/grid-perspective/components/CellContent.tsx b/app/perspectives/grid-perspective/components/CellContent.tsx
index 7ca220528..c3be2d0a4 100644
--- a/app/perspectives/grid-perspective/components/CellContent.tsx
+++ b/app/perspectives/grid-perspective/components/CellContent.tsx
@@ -49,6 +49,7 @@ import PlatformIO from '-/services/platform-facade';
import EntryIcon from '-/components/EntryIcon';
import { TS } from '-/tagspaces.namespace';
import TaggingActions from '-/reducers/tagging-actions';
+import { getLastThumbnailImageChange } from '-/reducers/app';
// import { getTagColor } from '-/reducers/settings';
const maxDescriptionPreviewLength = 100;
@@ -78,6 +79,7 @@ interface Props {
handleGridCellClick: (event: Object, fsEntry: TS.FileSystemEntry) => void;
editTagForEntry?: (path: string, tag: TS.Tag) => void;
reorderTags: boolean;
+ lastThumbnailImageChange: number;
}
function CellContent(props: Props) {
@@ -150,6 +152,10 @@ function CellContent(props: Props) {
tagTitles = tagTitles.substring(0, tagTitles.length - 2);
const tagPlaceholder = <TagsPreview tags={entryTags} />;
+ function urlGetDelim(url) {
+ return url.indexOf('?') > 0 ? '&' : '?';
+ }
+
function renderGridCell() {
return (
<div
@@ -170,7 +176,12 @@ function CellContent(props: Props) {
<img
alt="thumbnail"
className={classes.gridCellThumb}
- src={fsEntry.thumbPath}
+ src={
+ fsEntry.thumbPath +
+ (props.lastThumbnailImageChange
+ ? urlGetDelim(fsEntry.thumbPath) + props.lastThumbnailImageChange
+ : '')
+ }
// @ts-ignore
onError={i => (i.target.style.display = 'none')}
loading="lazy"
@@ -373,7 +384,12 @@ function CellContent(props: Props) {
<img
alt="thumbnail"
className={classes.gridCellThumb}
- src={fsEntry.thumbPath}
+ src={
+ fsEntry.thumbPath +
+ (props.lastThumbnailImageChange
+ ? urlGetDelim(fsEntry.thumbPath) + props.lastThumbnailImageChange
+ : '')
+ }
// @ts-ignore
onError={i => (i.target.style.display = 'none')}
loading="lazy"
@@ -472,7 +488,8 @@ function CellContent(props: Props) {
function mapStateToProps(state) {
return {
- reorderTags: state.settings.reorderTags
+ reorderTags: state.settings.reorderTags,
+ lastThumbnailImageChange: getLastThumbnailImageChange(state)
};
}
diff --git a/app/perspectives/grid-perspective/components/GridPagination.tsx b/app/perspectives/grid-perspective/components/GridPagination.tsx
index 413ac2003..c59505334 100644
--- a/app/perspectives/grid-perspective/components/GridPagination.tsx
+++ b/app/perspectives/grid-perspective/components/GridPagination.tsx
@@ -38,7 +38,8 @@ import {
getIsMetaLoaded,
getSearchResultCount,
getCurrentDirectoryTags,
- isLoading
+ isLoading,
+ getLastBackgroundImageChange
} from '-/reducers/app';
import EntryIcon from '-/components/EntryIcon';
import TagsPreview from '-/components/TagsPreview';
@@ -79,6 +80,7 @@ interface Props {
// eslint-disable-next-line react/no-unused-prop-types
selectedEntries; // cache only
// setMetaForCurrentDir: (metaFiles: Array<any>) => void;
+ lastBackgroundImageChange: number;
}
function GridPagination(props: Props) {
@@ -108,7 +110,7 @@ function GridPagination(props: Props) {
const containerEl = useRef(null);
// const entriesUpdated = useRef([]);
const page = useRef<number>(currentPage);
- const metaLoadedLock = useRef<boolean>(false);
+ const metaLoadedLock = useRef<boolean>(false); // TODO move this for all perspectives - not lock if you open folder with diff perspective now
// const [page, setPage] = useState(currentPage);
let pageFiles;
@@ -298,12 +300,20 @@ function GridPagination(props: Props) {
PlatformIO.getDirSeparator()
);
- const folderBgndPath = encodeURI(
- getBgndFileLocationForDirectory(
- currentDirectoryPath,
- PlatformIO.getDirSeparator()
- )
+ let folderBgndPath = getBgndFileLocationForDirectory(
+ currentDirectoryPath,
+ PlatformIO.getDirSeparator()
);
+ if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {
+ folderBgndPath = PlatformIO.getURLforPath(folderBgndPath);
+ } else {
+ folderBgndPath = encodeURI(
+ folderBgndPath +
+ (props.lastBackgroundImageChange
+ ? '?' + props.lastBackgroundImageChange
+ : '')
+ );
+ }
const dirColor = currentDirectoryColor || 'transparent';
return (
@@ -326,7 +336,7 @@ function GridPagination(props: Props) {
height: '100%',
// @ts-ignore
overflowY: AppConfig.isFirefox ? 'auto' : 'overlay',
- backgroundImage: `url(${folderBgndPath}?${new Date().getTime()})`,
+ backgroundImage: 'url(' + folderBgndPath + ')',
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat'
}}
@@ -485,7 +495,8 @@ function mapStateToProps(state) {
searchResultCount: getSearchResultCount(state),
// pageEntries: getPageEntries(state),
currentDirectoryTags: getCurrentDirectoryTags(state),
- isMetaLoaded: getIsMetaLoaded(state)
+ isMetaLoaded: getIsMetaLoaded(state),
+ lastBackgroundImageChange: getLastBackgroundImageChange(state)
};
}
@@ -502,6 +513,7 @@ function mapActionCreatorsToProps(dispatch) {
const areEqual = (prevProp: Props, nextProp: Props) =>
nextProp.theme === prevProp.theme &&
+ nextProp.lastBackgroundImageChange === prevProp.lastBackgroundImageChange &&
nextProp.currentDirectoryPath === prevProp.currentDirectoryPath &&
nextProp.isMetaLoaded === prevProp.isMetaLoaded &&
nextProp.showDirectories === prevProp.showDirectories &&
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index af48f9594..5b32b146e 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -70,6 +70,8 @@ export const types = {
DEVICE_OFFLINE: 'APP/DEVICE_OFFLINE',
PROGRESS: 'APP/PROGRESS',
RESET_PROGRESS: 'APP/RESET_PROGRESS',
+ LAST_BACKGROUND_IMAGE_CHANGE: 'APP/LAST_BACKGROUND_IMAGE_CHANGE',
+ LAST_THUMBNAIL_IMAGE_CHANGE: 'APP/LAST_THUMBNAIL_IMAGE_CHANGE',
LOGIN_SUCCESS: 'APP/LOGIN_SUCCESS',
LOGIN_FAILURE: 'APP/LOGIN_FAILURE',
LOGOUT: 'APP/LOGOUT',
@@ -238,6 +240,18 @@ export const initialState = {
// eslint-disable-next-line default-param-last
export default (state: any = initialState, action: any) => {
switch (action.type) {
+ case types.LAST_BACKGROUND_IMAGE_CHANGE: {
+ return {
+ ...state,
+ lastBackgroundImageChange: action.lastBackgroundImageChange
+ };
+ }
+ case types.LAST_THUMBNAIL_IMAGE_CHANGE: {
+ return {
+ ...state,
+ lastThumbnailImageChange: action.lastThumbnailImageChange
+ };
+ }
case types.LOGIN_SUCCESS: {
return { ...state, user: action.user };
}
@@ -792,6 +806,14 @@ function disableBackGestureMac() {
}
export const actions = {
+ setLastBackgroundImageChange: lastBackgroundImageChange => ({
+ type: types.LAST_BACKGROUND_IMAGE_CHANGE,
+ lastBackgroundImageChange
+ }),
+ setLastThumbnailImageChange: lastThumbnailImageChange => ({
+ type: types.LAST_THUMBNAIL_IMAGE_CHANGE,
+ lastThumbnailImageChange
+ }),
loggedIn: user => ({ type: types.LOGIN_SUCCESS, user }),
initApp: () => (dispatch: (action) => void, getState: () => any) => {
disableBackGestureMac();
@@ -2346,6 +2368,10 @@ export const actions = {
};
// Selectors
+export const getLastBackgroundImageChange = (state: any) =>
+ state.app.lastBackgroundImageChange;
+export const getLastThumbnailImageChange = (state: any) =>
+ state.app.lastThumbnailImageChange;
export const currentUser = (state: any) => state.app.user;
export const getIsMetaLoaded = (state: any) => state.app.isMetaLoaded;
export const getDirectoryContent = (state: any) =>
diff --git a/app/services/thumbsgenerator.ts b/app/services/thumbsgenerator.ts
index 060218f32..b6daa645d 100644
--- a/app/services/thumbsgenerator.ts
+++ b/app/services/thumbsgenerator.ts
@@ -149,7 +149,7 @@ export function getThumbnailURLPromise(
// Thumbnail exists
if (origStats.lmdt > stats.lmdt) {
// Checking if is up to date
- createThumbnailPromise(filePath, origStats.size, thumbFilePath)
+ createThumbnailPromise(filePath, origStats.size, thumbFilePath, origStats.isFile)
.then(tmbPath => resolve({ filePath, tmbPath }))
.catch(err => {
console.warn('Thumb generation failed ' + err);
@@ -161,7 +161,7 @@ export function getThumbnailURLPromise(
}
} else {
// Thumbnail does not exists
- createThumbnailPromise(filePath, origStats.size, thumbFilePath)
+ createThumbnailPromise(filePath, origStats.size, thumbFilePath, origStats.isFile)
.then(tmbPath => resolve({ filePath, tmbPath }))
.catch(err => {
console.warn('Thumb generation failed ' + err);
@@ -190,7 +190,12 @@ export function replaceThumbnailURLPromise(
return new Promise(resolve => {
PlatformIO.getPropertiesPromise(filePath)
.then(origStats => {
- createThumbnailPromise(filePath, origStats.size, thumbFilePath)
+ createThumbnailPromise(
+ filePath,
+ origStats.size,
+ thumbFilePath,
+ origStats.isFile
+ )
.then(tmbPath => resolve({ filePath, tmbPath }))
.catch(err => {
console.warn('Thumb generation failed ' + err);
@@ -208,17 +213,17 @@ export function replaceThumbnailURLPromise(
export function createThumbnailPromise(
filePath: string,
fileSize: number,
- thumbFilePath: string
+ thumbFilePath: string,
+ isFile: boolean
): Promise<any> {
return new Promise(async resolve => {
const metaDirectory = extractContainingDirectoryPath(
thumbFilePath,
PlatformIO.getDirSeparator()
);
- const fileDirectory = extractContainingDirectoryPath(
- filePath,
- PlatformIO.getDirSeparator()
- );
+ const fileDirectory = isFile
+ ? extractContainingDirectoryPath(filePath, PlatformIO.getDirSeparator())
+ : filePath;
const normalizedFileDirectory = normalizePath(fileDirectory);
if (normalizedFileDirectory.endsWith(AppConfig.metaFolder)) {
resolve(undefined); // prevent creating thumbs in meta/.ts folder
@@ -240,7 +245,7 @@ export function createThumbnailPromise(
});
return true;
}
- resolve(undefined);
+ resolve(thumbFilePath);
return true;
})
.catch(err => {