TagSpaces is an offline, open source, document manager with tagging support
File Preview refreshes whenever adding a Tag (#2353)
Stanimir6465063c89b6
diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsxindex 3191cd6b6..4ef8564c2 100644--- a/src/renderer/components/EntryProperties.tsx+++ b/src/renderer/components/EntryProperties.tsx@@ -158,7 +158,7 @@ function EntryProperties(props: Props) {const { t } = useTranslation();const theme = useTheme();//const desktopMode = useSelector(isDesktopMode);- const { openedEntry, sharingLink, getOpenedDirProps } =+ const { openedEntry, sharingLink, getOpenedDirProps, fileChanged } =useOpenedEntryContext();const { openMoveCopyFilesDialog } = useMenuContext();const { isEditMode } = useFilePropertiesContext();@@ -415,6 +415,14 @@ function EntryProperties(props: Props) {};const handleChange = (name: string, value: Array<TS.Tag>, action: string) => {+ if (openedEntry && fileChanged) {+ showNotification(+ `You can't edit tags, because '${openedEntry.path}' is opened for editing`,+ 'default',+ true,+ );+ return;+ }if (action === 'remove-value') {if (!value) {// no tags left in the select elementdiff --git a/src/renderer/components/FileView.tsx b/src/renderer/components/FileView.tsxindex a264d97ab..504239459 100644--- a/src/renderer/components/FileView.tsx+++ b/src/renderer/components/FileView.tsx@@ -30,7 +30,7 @@ import {MutableRefObject,useCallback,useEffect,- useReducer,+ useMemo,useRef,} from 'react';import { useTranslation } from 'react-i18next';@@ -57,7 +57,7 @@ function FileView(props: Props) {const eventID = useRef<string>(getUuid());// const [thumb, setThumb] = useState<string | null>(null);// const [loadingThumb, setLoadingThumb] = useState(true);- const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);+ // const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);useEffect(() => {if (AppConfig.isElectron) {@@ -90,19 +90,6 @@ function FileView(props: Props) {};}, []);- /*useEffect(() => {- setLoadingThumb(true);- const loc = findLocation(openedEntry.locationID);- loc- ?.getThumbPath(openedEntry.meta.thumbPath, openedEntry.meta.lastUpdated)- .then((t) => {- setThumb(t);- })- .finally(() => {- setLoadingThumb(false);- });- }, [openedEntry]);*/-const handleFullscreenChange = useCallback((e) => {let change = '';if (fscreen.fullscreenElement !== null) {@@ -193,8 +180,7 @@ function FileView(props: Props) {console.debug('function getContent not exist for file:', e);}};*/-- function getFileOpenerURL(): string {+ const fileOpenerURL: string = useMemo(() => {if (openedEntry && openedEntry.path) {// if (fileTitle.length > maxCharactersTitleLength) {// fileTitle = fileTitle.substr(0, maxCharactersTitleLength) + '...';@@ -262,7 +248,26 @@ function FileView(props: Props) {}}return 'about:blank';- }+ }, [+ openedEntry?.lmdt,+ openedEntry?.isEncrypted,+ openedEntry?.viewingExtensionPath,+ openedEntry?.editingExtensionPath,+ isEditMode,+ theme.palette,+ searchQuery?.textQuery,+ isSearchMode,+ ]);++ /* useEffect(() => {+ const el = fileViewer.current;+ if (!el) return;+ // note: el.src may return fully qualified URL — use === comparison will work if we set it before,+ // otherwise you can compare el.getAttribute('src') to be stricter.+ if (el.getAttribute('src') !== fileOpenerURL) {+ el.setAttribute('src', fileOpenerURL);+ }+ }, [fileOpenerURL]); */return (<div@@ -303,7 +308,7 @@ function FileView(props: Props) {border: 0,}}allow="clipboard-write *"- src={getFileOpenerURL() /*fileOpenerURL.current*/}+ src={fileOpenerURL}allowFullScreensandbox="allow-same-origin allow-scripts allow-modals allow-downloads"id={'FileViewer' + eventID.current}diff --git a/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx b/src/renderer/components/dialogs/hooks/MenuContextProvider.tsxindex a613e8d02..03ac099c3 100644--- a/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx+++ b/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx@@ -29,6 +29,8 @@ import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';import { TS } from '-/tagspaces.namespace';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { Pro } from '-/pro';+import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';+import { useNotificationContext } from '-/hooks/useNotificationContext';type MenuContextData = {openMenu: (@@ -112,6 +114,8 @@ const AddRemoveTagsDialog = React.lazy(export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {const { findLocation } = useCurrentLocationContext();const { selectedEntries } = useSelectedEntriesContext();+ const { openedEntry, fileChanged } = useOpenedEntryContext();+ const { showNotification } = useNotificationContext();const [directoryContextMenuAnchorEl, setDirectoryContextMenuAnchorEl] =useState<null | HTMLElement>(null);const [fileContextMenuAnchorEl, setFileContextMenuAnchorEl] =@@ -228,6 +232,20 @@ export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {};const openAddRemoveTagsDialog = (entries?: TS.FileSystemEntry[]) => {+ const ent = entries || selectedEntries;+ if (+ openedEntry &&+ fileChanged &&+ ent &&+ ent.some((e) => e.path === openedEntry.path)+ ) {+ showNotification(+ `You can't edit tags, because '${openedEntry.path}' is opened for editing`,+ 'default',+ true,+ );+ return;+ }openAddRemoveTags.current = true;currentEntries.current = entries;forceUpdate();@@ -309,7 +327,7 @@ export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {openShareFilesDialog,closeShareFilesDialog,};- }, []);+ }, [selectedEntries, openedEntry, fileChanged]);return (<MenuContext.Provider value={context}>diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsxindex 4d043b936..e1e0870e6 100644--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx@@ -603,21 +603,17 @@ export const OpenedEntryContextProvider = ({/*** check for editMode in order to show save changes dialog (shouldReload: false)*/- if (currentEntry.current) {- //openedEntries.length > 0) {- const openFile = currentEntry.current; //openedEntries[0];- if (fileChanged.current) {- entryForOpening = {- ...openFile,- }; // false };- addToEntryContainer(entryForOpening);- showNotification(- `You can't open another file, because '${openFile.path}' is opened for editing`,- 'default',- true,- );- return Promise.resolve(false);- }+ if (fileChanged.current && currentEntry.current) {+ entryForOpening = {+ ...currentEntry.current,+ }; // false };+ addToEntryContainer(entryForOpening);+ showNotification(+ `You can't open another file, because '${currentEntry.current.path}' is opened for editing`,+ 'default',+ true,+ );+ return Promise.resolve(false);}entryForOpening = findExtensionsForEntry(fsEntry, supportedFileTypes);