Skip to content

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

Broken thumbnails for folders on linux (#1679)

Stanimir3316b058cb4a
diff --git a/app/perspectives/grid-perspective/components/GridPagination.tsx b/app/perspectives/grid-perspective/components/GridPagination.tsx
index f5aab7f04..c6a5e8774 100644
--- a/app/perspectives/grid-perspective/components/GridPagination.tsx
+++ b/app/perspectives/grid-perspective/components/GridPagination.tsx
@@ -27,7 +27,6 @@ import {
actions as AppActions,
getCurrentDirectoryColor,
getIsMetaLoaded,
- getPageEntries,
getSearchResultCount,
isLoading
} from '-/reducers/app';
@@ -38,6 +37,7 @@ import { getMetaForEntry } from '-/services/utils-io';
import {
getMetaFileLocationForDir,
getMetaFileLocationForFile,
+ getThumbFileLocationForDirectory,
getThumbFileLocationForFile
} from '-/utils/paths';
import PlatformIO from '-/services/platform-facade';
@@ -52,7 +52,7 @@ interface Props {
directories: Array<TS.FileSystemEntry>;
showDirectories: boolean;
files: Array<TS.FileSystemEntry>;
- pageEntries: Array<TS.FileSystemEntry>;
+ // pageEntries: Array<TS.FileSystemEntry>;
renderCell: (entry: TS.FileSystemEntry, isLast?: boolean) => void;
currentDirectoryColor: string;
isAppLoading: boolean;
@@ -63,10 +63,7 @@ interface Props {
searchResultCount: number;
onContextMenu: (event: React.MouseEvent<HTMLDivElement>) => void;
onClick: (event: React.MouseEvent<HTMLDivElement>) => void;
- updateCurrentDirEntries: (
- dirEntries: TS.FileSystemEntry[],
- pageEntries: any
- ) => void;
+ updateCurrentDirEntries: (dirEntries: TS.FileSystemEntry[]) => void;
// eslint-disable-next-line react/no-unused-prop-types
settings; // cache only
// eslint-disable-next-line react/no-unused-prop-types
@@ -85,8 +82,7 @@ function GridPagination(props: Props) {
currentDirectoryColor,
gridPageLimit,
currentPage,
- files,
- pageEntries
+ files
} = props;
const allFilesCount = files.length;
const showPagination = gridPageLimit && files.length > gridPageLimit;
@@ -97,6 +93,7 @@ function GridPagination(props: Props) {
const containerEl = useRef(null);
// const entriesUpdated = useRef([]);
const page = useRef<number>(currentPage);
+ const metaLoadedLock = useRef<boolean>(false);
// const [page, setPage] = useState(currentPage);
let pageFiles;
@@ -109,9 +106,11 @@ function GridPagination(props: Props) {
// const [, forceUpdate] = useReducer(x => x + 1, 0);
useEffect(() => {
- if (!props.isMetaLoaded) {
+ if (!props.isMetaLoaded && !metaLoadedLock.current) {
+ metaLoadedLock.current = true;
PlatformIO.listMetaDirectoryPromise(props.currentDirectoryPath)
.then(meta => {
+ metaLoadedLock.current = false;
props.setIsMetaLoaded(true);
const dirEntriesPromises = getDirEntriesPromises();
const fileEntriesPromises = getFileEntriesPromises(meta);
@@ -125,7 +124,7 @@ function GridPagination(props: Props) {
})
.catch(ex => console.error(ex));
}
- }, [page.current, files, props.isMetaLoaded]);
+ }, [page.current, props.isMetaLoaded, files]);
useEffect(() => {
page.current = currentPage;
@@ -173,21 +172,36 @@ function GridPagination(props: Props) {
);
const getDirEntriesPromises = (): Promise<any>[] =>
- directories.map(entry => {
+ directories.map(async entry => {
+ if (entry.name === AppConfig.metaFolder) {
+ return Promise.resolve({ [entry.path]: undefined });
+ }
+ const meta = await PlatformIO.listMetaDirectoryPromise(entry.path);
const metaFilePath = getMetaFileLocationForDir(
entry.path,
PlatformIO.getDirSeparator()
);
+ const thumbDirPath = getThumbFileLocationForDirectory(
+ entry.path,
+ PlatformIO.getDirSeparator()
+ );
+ let enhancedEntry;
+ if (meta.some(metaFile => thumbDirPath.endsWith(metaFile.path))) {
+ const thumbPath = PlatformIO.haveObjectStoreSupport()
+ ? PlatformIO.getURLforPath(thumbDirPath)
+ : thumbDirPath;
+ enhancedEntry = { ...entry, thumbPath };
+ }
if (
- // meta.some(metaFile => metaFilePath.endsWith(metaFile)) &&
- !checkEntryExist(entry.path) &&
+ meta.some(metaFile => metaFilePath.endsWith(metaFile.path)) &&
+ // !checkEntryExist(entry.path) &&
entry.path.indexOf(
AppConfig.metaFolder + PlatformIO.getDirSeparator()
) === -1
) {
- return getMetaForEntry(entry, metaFilePath);
+ return getMetaForEntry(enhancedEntry || entry, metaFilePath);
}
- return Promise.resolve({ [entry.path]: undefined });
+ return Promise.resolve({ [entry.path]: enhancedEntry });
});
const getFileEntriesPromises = (meta: Array<any>): Promise<any>[] =>
@@ -199,7 +213,7 @@ function GridPagination(props: Props) {
if (
// check if metaFilePath exist in listMetaDirectory content
meta.some(metaFile => metaFilePath.endsWith(metaFile.path)) &&
- !checkEntryExist(entry.path) &&
+ // !checkEntryExist(entry.path) &&
entry.path.indexOf(
AppConfig.metaFolder + PlatformIO.getDirSeparator()
) === -1
@@ -213,7 +227,7 @@ function GridPagination(props: Props) {
const catchHandler = error => undefined;
Promise.all(metaPromises.map(promise => promise.catch(catchHandler)))
.then(entries => {
- updateCurrentDirEntries(entries.filter(entry => entry !== undefined));
+ updateCurrentDirEntries(entries); // .filter(entry => entry !== undefined));
// entriesUpdated.current = entries;
return true;
})
@@ -233,16 +247,16 @@ function GridPagination(props: Props) {
}
});
if (entriesEnhanced.length > 0) {
- props.updateCurrentDirEntries(entriesEnhanced, entries);
+ props.updateCurrentDirEntries(entriesEnhanced);
}
};
- const checkEntryExist = path => {
+ /* const checkEntryExist = path => {
const index = pageEntries.findIndex(
objUpdated => Object.keys(objUpdated).indexOf(path) > -1
);
return index > -1;
- };
+ }; */
const handleChange = (event, value) => {
// setPage(value);
@@ -361,7 +375,7 @@ function mapStateToProps(state) {
isAppLoading: isLoading(state),
currentDirectoryColor: getCurrentDirectoryColor(state),
searchResultCount: getSearchResultCount(state),
- pageEntries: getPageEntries(state),
+ // pageEntries: getPageEntries(state),
isMetaLoaded: getIsMetaLoaded(state)
};
}
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 9aabf9970..571cc4bf5 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -273,7 +273,7 @@ export default (state: any = initialState, action: any) => {
return {
...state,
currentDirectoryEntries: action.directoryContent,
- pageEntries: [],
+ // pageEntries: [],
currentDirectoryColor: action.directoryMeta
? action.directoryMeta.color || ''
: '',
@@ -310,21 +310,6 @@ export default (state: any = initialState, action: any) => {
currentDirectoryPath: ''
};
}
- /* case types.LOAD_PAGE_CONTENT: {
- const newPageEntries = [...state.pageEntries];
- for (let i = 0; i < action.pageEntries.length; i += 1) {
- const index = newPageEntries.findIndex(
- entry => entry.path === action.pageEntries[i].path
- );
- if (index === -1) {
- newPageEntries.push(action.pageEntries[i]);
- }
- }
- return {
- ...state,
- pageEntries: newPageEntries
- };
- } */
case types.SET_CURRENLOCATIONID: {
return {
...state,
@@ -659,20 +644,9 @@ export default (state: any = initialState, action: any) => {
}
}
- /* const newPageEntries = [...state.pageEntries];
- for (const [path, value] of Object.entries(newPageEntries)) {
- const pageEntry = action.pageEntries.findIndex(
- entry => entry.path === newPageEntries[i].path
- );
- if (pageEntry) {
- newPageEntries[i] = pageEntry;
- }
- } */
-
return {
...state,
- currentDirectoryEntries: newDirEntries,
- pageEntries: action.pageEntries
+ currentDirectoryEntries: newDirEntries
};
}
case types.UPDATE_CURRENTDIR_ENTRY: {
@@ -1034,7 +1008,6 @@ export const actions = {
dispatch(
actions.setCurrentDirectoryPerspective(PerspectiveIDs.UNSPECIFIED)
);
- dispatch(actions.setIsMetaLoaded(false));
prepareDirectoryContent(
results,
directoryPath,
@@ -1135,6 +1108,7 @@ export const actions = {
directoryMeta
)
);
+ dispatch(actions.setIsMetaLoaded(false));
},
loadDirectorySuccessInt: (
directoryPath: string,
@@ -1907,13 +1881,9 @@ export const actions = {
path,
entry
}),
- updateCurrentDirEntries: (
- dirEntries: TS.FileSystemEntry[],
- pageEntries: any
- ) => ({
+ updateCurrentDirEntries: (dirEntries: TS.FileSystemEntry[]) => ({
type: types.UPDATE_CURRENTDIR_ENTRIES,
- dirEntries,
- pageEntries
+ dirEntries
}),
/**
* @param path
@@ -2264,7 +2234,7 @@ export const currentUser = (state: any) => state.app.user;
export const getIsMetaLoaded = (state: any) => state.app.isMetaLoaded;
export const getDirectoryContent = (state: any) =>
state.app.currentDirectoryEntries;
-export const getPageEntries = (state: any) => state.app.pageEntries;
+// export const getPageEntries = (state: any) => state.app.pageEntries;
export const getCurrentDirectoryFiles = (state: any) =>
state.app.currentDirectoryFiles;
export const getCurrentDirectoryDirs = (state: any) =>
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index b2c9107c9..e96a68f02 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -140,7 +140,7 @@ export function enhanceDirectoryContent(
export async function getMetaForEntry(
entry: TS.FileSystemEntry,
- metaFilePath: string
+ metaFilePath: string,
): Promise<any> {
const meta: TS.FileSystemEntryMeta = await loadJSONFile(metaFilePath);
if (meta) {