TagSpaces is an offline, open source, document manager with tagging support
refactoring locations (#2221)
Stanimir6af21426675a
diff --git a/src/renderer/components/EntryContainerTabs.tsx b/src/renderer/components/EntryContainerTabs.tsxindex 6ae95d98e..6de742708 100644--- a/src/renderer/components/EntryContainerTabs.tsx+++ b/src/renderer/components/EntryContainerTabs.tsx@@ -21,7 +21,6 @@ import Tooltip from '-/components/Tooltip';import TsTabPanel from '-/components/TsTabPanel';import { TabItem, TabNames } from '-/hooks/EntryPropsTabsContextProvider';import { useChatContext } from '-/hooks/useChatContext';-import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useEntryPropsTabsContext } from '-/hooks/useEntryPropsTabsContext';import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';import { AppDispatch } from '-/reducers/app';@@ -29,7 +28,6 @@ import {actions as SettingsActions,getEntryContainerTab,getMapTileServer,- isDevMode,} from '-/reducers/settings';import { Box, Tab, Tabs, useMediaQuery } from '@mui/material';import { styled, useTheme } from '@mui/material/styles';diff --git a/src/renderer/hooks/CurrentLocationContextProvider.tsx b/src/renderer/hooks/CurrentLocationContextProvider.tsxindex 30e4a6199..9a7d3f250 100644--- a/src/renderer/hooks/CurrentLocationContextProvider.tsx+++ b/src/renderer/hooks/CurrentLocationContextProvider.tsx@@ -46,6 +46,7 @@ import { TS } from '-/tagspaces.namespace';type CurrentLocationContextData = {locations: CommonLocation[];currentLocation: CommonLocation;+ currentLocationId: string;readOnlyMode: boolean;skipInitialDirList: boolean;persistTagsInSidecarFile: boolean;@@ -87,6 +88,7 @@ export const CurrentLocationContext = createContext<CurrentLocationContextData>({locations: undefined,currentLocation: undefined,+ currentLocationId: undefined,readOnlyMode: false,skipInitialDirList: false,persistTagsInSidecarFile: true,@@ -126,13 +128,15 @@ export const CurrentLocationContextProvider = ({const { t } = useTranslation();const { showNotification } = useNotificationContext();- const locations: CommonLocation[] = useSelector(getLocations);+ const locations: TS.Location[] = useSelector(getLocations);const defaultLocationId = useSelector(getDefaultLocationId);const settingsPersistTagsInSidecarFile: boolean = useSelector(getPersistTagsInSidecarFile,);-- const allLocations = useRef<CommonLocation[]>(locations);+ // needs to convert TS.Location from redux into CommonLocation+ const allLocations = useRef<CommonLocation[]>(+ locations.map((l) => new CommonLocation(l)),+ );const currentLocation = useRef<string>(undefined); //defaultLocationId);const selectedLocation = useRef<CommonLocation>(undefined);const skipInitialDirList = useRef<boolean>(false);@@ -190,7 +194,6 @@ export const CurrentLocationContextProvider = ({}, []);useEffect(() => {- allLocations.current = locations;if (locations.length < 1) {// init locationssetDefaultLocations();@@ -205,10 +208,19 @@ export const CurrentLocationContextProvider = ({//closeLocation(currentLocation.current.uuid);}}+ // if(!areLocationsEqual(allLocations.current,locations)){+ allLocations.current = locations.map((l) => new CommonLocation(l));+ forceUpdate();+ // }}- forceUpdate();}, [locations]); //allLocations.current]);+ /*function areLocationsEqual(arr1: CommonLocation[], arr2: CommonLocation[]) {+ if (arr1.length !== arr2.length) return false;++ return arr1.every((obj, index) => obj.equal(arr2[index]));+ }*/+function getLocationPath(location: CommonLocation): Promise<string> {let locationPath = '';if (location) {@@ -453,7 +465,7 @@ export const CurrentLocationContextProvider = ({}function editLocationInt(location: CommonLocation, openAfterEdit = false) {- allLocations.current = locations.map((l) =>+ allLocations.current = allLocations.current.map((l) =>l.uuid === location.uuid ? location : l,);dispatch(LocationActions.changeLocation(location));@@ -585,6 +597,7 @@ export const CurrentLocationContextProvider = ({return {locations: allLocations.current,currentLocation: location,+ currentLocationId: currentLocation.current,readOnlyMode,skipInitialDirList: skipInitialDirList.current,persistTagsInSidecarFile,diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsxindex ac273ee53..4d92b2ed5 100644--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx@@ -203,7 +203,7 @@ export const DirectoryContentContextProvider = ({const { t } = useTranslation();const {closeAllLocations,- currentLocation,+ currentLocationId,findLocation,skipInitialDirList,getLocationPath,@@ -239,6 +239,8 @@ export const DirectoryContentContextProvider = ({const firstRender = useFirstRender();const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);+ const currentLocation = findLocation(currentLocationId);+useEffect(() => {if (AppConfig.isElectron) {window.electronIO.ipcRenderer.on('cmd', (arg) => {@@ -297,7 +299,7 @@ export const DirectoryContentContextProvider = ({clearDirectoryContent();exitSearchMode();}- }, [currentLocation]);+ }, [currentLocationId]);useEffect(() => {if (!firstRender && metaActions && metaActions.length > 0) {diff --git a/src/renderer/reducers/locations.ts b/src/renderer/reducers/locations.tsindex 076a3b996..0dd9f99d1 100644--- a/src/renderer/reducers/locations.ts+++ b/src/renderer/reducers/locations.ts@@ -172,8 +172,7 @@ export const actions = {};// Selectors-export const getLocations = (state: any): CommonLocation[] =>- state.locations.map((l) => new CommonLocation(l));+export const getLocations = (state: any): TS.Location[] => state.locations;export const getDefaultLocationId = (state: any): string | undefined => {let foundLocation = state.locations.find((location) => location.isDefault);return foundLocation ? foundLocation.uuid : undefined;diff --git a/src/renderer/utils/CommonLocation.ts b/src/renderer/utils/CommonLocation.tsindex 653518505..a15c29fc5 100644--- a/src/renderer/utils/CommonLocation.ts+++ b/src/renderer/utils/CommonLocation.ts@@ -99,6 +99,46 @@ export class CommonLocation implements TS.Location {}}+ equal = (location: CommonLocation): boolean => {+ let isEqual =+ this.uuid === location.uuid &&+ this.name === location.name &&+ this.type === location.type && // 0 - local && 1 - S3 && 2 - amplify && 3 - webdav+ this.authType === location.authType && // none,password,digest,token+ this.username === location.username &&+ this.password === location.password &&+ this.path === location.path &&+ this.perspective === location.perspective &&+ this.creationDate === location.creationDate &&+ // this.lastEditedDate === location.lastEditedDate &&+ this.isDefault === location.isDefault &&+ this.isReadOnly === location.isReadOnly &&+ this.isNotEditable === location.isNotEditable &&+ this.watchForChanges === location.watchForChanges &&+ this.disableIndexing === location.disableIndexing &&+ this.disableThumbnailGeneration === location.disableThumbnailGeneration &&+ this.fullTextIndex === location.fullTextIndex &&+ this.maxIndexAge === location.maxIndexAge &&+ this.maxLoops === location.maxLoops &&+ this.persistTagsInSidecarFile === location.persistTagsInSidecarFile &&+ this.ignorePatternPaths === location.ignorePatternPaths &&+ this.autoOpenedFilename === location.autoOpenedFilename;+ if (!isEqual) {+ return false;+ }+ if (location.type === locationType.TYPE_CLOUD) {+ isEqual =+ this.accessKeyId === (location as TS.S3Location).accessKeyId &&+ this.secretAccessKey === (location as TS.S3Location).secretAccessKey &&+ this.sessionToken === (location as TS.S3Location).sessionToken &&+ this.bucketName === (location as TS.S3Location).bucketName &&+ this.encryptionKey === (location as TS.S3Location).encryptionKey &&+ this.region === (location as TS.S3Location).region &&+ this.endpointURL === (location as TS.S3Location).endpointURL;+ }+ return isEqual;+ };+getPath = (param) => {if (typeof param === 'object' && param !== null) {return param.path;