Skip to content

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

add source parameter to actions model (#2095)

Stanimirdc85c4e3af0c
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsx
index 8d33afe2c..89d41ee00 100644
--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx
+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx
@@ -338,12 +338,15 @@ export const DirectoryContentContextProvider = ({
}
};
- function reflectSelection(actions) {
+ function reflectSelection(actions: TS.EditAction[]) {
let updated = false;
if (actions && actions.length > 0) {
let selected = [];
for (const action of actions) {
if (
+ action.source !== 'fsWatcher' &&
+ action.source !== 'upload' &&
+ action.source !== 'thumbgen' &&
action.entry.path.indexOf(
currentLocation?.getDirSeparator() + AppConfig.metaFolder,
) === -1
diff --git a/src/renderer/hooks/EditedEntryContextProvider.tsx b/src/renderer/hooks/EditedEntryContextProvider.tsx
index af6d9caeb..8ee51c090 100644
--- a/src/renderer/hooks/EditedEntryContextProvider.tsx
+++ b/src/renderer/hooks/EditedEntryContextProvider.tsx
@@ -20,7 +20,6 @@ import React, { createContext, useMemo, useReducer, useRef } from 'react';
import { extractTagsAsObjects } from '@tagspaces/tagspaces-common/paths';
import { TS } from '-/tagspaces.namespace';
import AppConfig from '-/AppConfig';
-import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
type EditedEntryContextData = {
actions: TS.EditAction[];
@@ -30,7 +29,11 @@ type EditedEntryContextData = {
reflectAddEntryPath: (
...entriesPromises: Promise<TS.FileSystemEntry>[]
) => Promise<boolean>;
- reflectAddEntry: (entry: TS.FileSystemEntry, open?: boolean) => void;
+ reflectAddEntry: (
+ entry: TS.FileSystemEntry,
+ open?: boolean,
+ source?: TS.ActionSource,
+ ) => void;
};
export const EditedEntryContext = createContext<EditedEntryContextData>({
@@ -103,8 +106,13 @@ export const EditedEntryContextProvider = ({
* warning: no entry.meta will be added in reflectAddEntry. To add meta use reflectAddEntryPath
* @param entry
* @param open
+ * @param actionSource
*/
- function reflectAddEntry(entry: TS.FileSystemEntry, open = true) {
+ function reflectAddEntry(
+ entry: TS.FileSystemEntry,
+ open = true,
+ actionSource: TS.ActionSource = 'local',
+ ) {
if (!entry.tags || entry.tags.length === 0) {
entry.tags = extractTagsAsObjects(entry.name, AppConfig.tagDelimiter);
}
@@ -112,6 +120,7 @@ export const EditedEntryContextProvider = ({
action: 'add',
entry: entry,
open: open,
+ ...(typeof actionSource !== 'boolean' && { source: actionSource }),
};
actions.current = [currentAction];
forceUpdate();
diff --git a/src/renderer/hooks/FSWatcherContextProvider.tsx b/src/renderer/hooks/FSWatcherContextProvider.tsx
index e898c49b9..a17aaeb8b 100644
--- a/src/renderer/hooks/FSWatcherContextProvider.tsx
+++ b/src/renderer/hooks/FSWatcherContextProvider.tsx
@@ -154,6 +154,7 @@ export const FSWatcherContextProvider = ({
actionsQueue.push({
action: 'delete',
entry: currentLocation.toFsEntry(path, false),
+ source: 'fsWatcher',
});
//reflectDeleteEntries(toFsEntry(path, false, currentLocation.uuid));
}
@@ -164,6 +165,7 @@ export const FSWatcherContextProvider = ({
action: 'add',
entry: currentLocation.toFsEntry(path, true),
open: false,
+ source: 'fsWatcher',
});
// reflectAddEntry(toFsEntry(path, true, currentLocation.uuid));
}
@@ -174,6 +176,7 @@ export const FSWatcherContextProvider = ({
action: 'add',
entry: currentLocation.toFsEntry(path, false),
open: false,
+ source: 'fsWatcher',
});
//reflectAddEntry(toFsEntry(path, false, currentLocation.uuid));
}
diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsx
index 9909372d4..133fd7d7c 100644
--- a/src/renderer/hooks/IOActionsContextProvider.tsx
+++ b/src/renderer/hooks/IOActionsContextProvider.tsx
@@ -907,6 +907,8 @@ export const IOActionsContextProvider = ({
{ path: thumbPath },
fileContent,
true,
+ undefined,
+ 'upload',
).then(() => thumbPath);
}
return undefined;
@@ -1188,6 +1190,7 @@ export const IOActionsContextProvider = ({
action: 'add',
entry: entry,
open: open,
+ source: 'upload',
}),
);
setReflectActions(...reflectActions);
diff --git a/src/renderer/hooks/PlatformFacadeContextProvider.tsx b/src/renderer/hooks/PlatformFacadeContextProvider.tsx
index ee3998422..ecd648e3f 100644
--- a/src/renderer/hooks/PlatformFacadeContextProvider.tsx
+++ b/src/renderer/hooks/PlatformFacadeContextProvider.tsx
@@ -129,7 +129,7 @@ type PlatformFacadeContextData = {
progress: any, // ManagedUpload.Progress,
response: any, // AWS.Response<AWS.S3.PutObjectOutput, AWS.AWSError>
) => void,
- reflect?,
+ reflect?: boolean | TS.ActionSource,
) => Promise<TS.FileSystemEntry>;
deleteEntriesPromise: (...paths: TS.FileSystemEntry[]) => Promise<boolean>;
setFolderThumbnailPromise: (filePath: string) => Promise<string>;
@@ -649,14 +649,18 @@ export const PlatformFacadeContextProvider = ({
progress: any, // ManagedUpload.Progress,
response: any, // AWS.Response<AWS.S3.PutObjectOutput, AWS.AWSError>
) => void,
- reflect: boolean = true,
+ reflect: boolean | TS.ActionSource = true,
): Promise<TS.FileSystemEntry> {
ignoreByWatcher(param.path);
return getLocation(param)
.saveBinaryFilePromise(param, content, overwrite, onUploadProgress)
.then((fsEntry) => {
if (reflect) {
- reflectAddEntry(fsEntry, false);
+ reflectAddEntry(
+ fsEntry,
+ false,
+ typeof reflect === 'boolean' ? 'local' : reflect,
+ );
}
deignoreByWatcher(param.path);
return fsEntry;
diff --git a/src/renderer/hooks/ThumbGenerationContextProvider.tsx b/src/renderer/hooks/ThumbGenerationContextProvider.tsx
index bcc98ba33..6d193b8c8 100644
--- a/src/renderer/hooks/ThumbGenerationContextProvider.tsx
+++ b/src/renderer/hooks/ThumbGenerationContextProvider.tsx
@@ -459,6 +459,8 @@ export const ThumbGenerationContextProvider = ({
{ path: filePath, locationID },
content, //PlatformIO.isMinio() ? content : content.buffer,
true,
+ undefined,
+ 'thumbgen',
)
.then(() => filePath)
.catch((error) => {
diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.ts
index 1675044a1..fecaf969b 100644
--- a/src/renderer/tagspaces.namespace.d.ts
+++ b/src/renderer/tagspaces.namespace.d.ts
@@ -112,12 +112,14 @@ export namespace TS {
}
type Uuid = string;
+ export type ActionSource = 'local' | 'upload' | 'thumbgen' | 'fsWatcher';
interface EditAction {
action: 'add' | 'delete' | 'update' | 'move';
entry: TS.FileSystemEntry;
oldEntryPath?: string;
open?: boolean;
+ source?: ActionSource;
}
interface EditMetaAction {