Skip to content

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

fix on change location KanBan perspective switch to grid perspective (#2131)

Stanimir52348e98ec07
diff --git a/src/renderer/components/FolderContainer.tsx b/src/renderer/components/FolderContainer.tsx
index b99f91a4a..781ef37a3 100644
--- a/src/renderer/components/FolderContainer.tsx
+++ b/src/renderer/components/FolderContainer.tsx
@@ -74,7 +74,7 @@ function FolderContainer(props: Props) {
setSearchQuery,
currentDirectoryEntries,
currentDirectoryPath,
- perspective,
+ getPerspective,
setManualDirectoryPerspective,
enterSearchMode,
isSearchMode,
@@ -86,13 +86,6 @@ function FolderContainer(props: Props) {
const isDesktopMode = useSelector(getDesktopMode);
const progress = useSelector(getProgress);
- //let currentPerspective = getPerspective();
- // currentDirectoryPerspective || defaultPerspective || PerspectiveIDs.GRID;
-
- /*if (currentPerspective === PerspectiveIDs.UNSPECIFIED) {
- currentPerspective = defaultPerspective;
- }*/
-
const showWelcomePanel =
!currentDirectoryPath && currentDirectoryEntries.length < 1;
@@ -185,8 +178,6 @@ function FolderContainer(props: Props) {
const openSearchKeyBinding = ` (${adjustKeyBinding(keyBindings.openSearch)})`;
- const { FILE } = NativeTypes;
-
return (
<div
style={{
@@ -323,7 +314,7 @@ function FolderContainer(props: Props) {
</div>
{isDesktopMode && (
<ToggleButtonGroup
- value={perspective}
+ value={getPerspective()}
size="small"
data-tid="floatingPerspectiveSwitcher"
disabled={showWelcomePanel}
diff --git a/src/renderer/components/RenderPerspective.tsx b/src/renderer/components/RenderPerspective.tsx
index 8eb53300d..f99f6062c 100644
--- a/src/renderer/components/RenderPerspective.tsx
+++ b/src/renderer/components/RenderPerspective.tsx
@@ -16,7 +16,7 @@
*
*/
-import React from 'react';
+import React, { useEffect, useReducer } from 'react';
import AppConfig from '-/AppConfig';
@@ -32,6 +32,7 @@ import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import CustomDragLayer from '-/components/CustomDragLayer';
import TargetFileBox from '-/components/TargetFileBox';
import { NativeTypes } from 'react-dnd-html5-backend';
+import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
const GridPerspective = React.lazy(
() =>
@@ -155,7 +156,19 @@ interface Props {
function RenderPerspective(props: Props) {
const { openRenameEntryDialog } = props;
const { currentLocation } = useCurrentLocationContext();
- const { perspective } = useDirectoryContentContext();
+ const { getPerspective } = useDirectoryContentContext();
+ const { metaActions } = useEditedEntryMetaContext();
+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
+
+ useEffect(() => {
+ if (metaActions && metaActions.length > 0) {
+ for (const action of metaActions) {
+ if (action.action === 'perspectiveChange') {
+ forceUpdate();
+ }
+ }
+ }
+ }, [metaActions]);
const showWelcomePanel = !currentLocation;
//!currentDirectoryPath && currentDirectoryEntries.length < 1;
@@ -164,7 +177,8 @@ function RenderPerspective(props: Props) {
return AppConfig.showWelcomePanel ? <WelcomePanelAsync /> : null;
}
- function getPerspective() {
+ function getPerspectiveComponent() {
+ const perspective = getPerspective();
if (perspective === PerspectiveIDs.LIST) {
return (
<ListPerspectiveAsync openRenameEntryDialog={openRenameEntryDialog} />
@@ -193,7 +207,7 @@ function RenderPerspective(props: Props) {
return (
<TargetFileBox style={{ height: '100%' }} accepts={[FILE]}>
<CustomDragLayer />
- {getPerspective()}
+ {getPerspectiveComponent()}
</TargetFileBox>
);
}
diff --git a/src/renderer/components/dialogs/hooks/TargetPathContextProvider.tsx b/src/renderer/components/dialogs/hooks/TargetPathContextProvider.tsx
index a582c84fe..377fcdb9b 100644
--- a/src/renderer/components/dialogs/hooks/TargetPathContextProvider.tsx
+++ b/src/renderer/components/dialogs/hooks/TargetPathContextProvider.tsx
@@ -42,8 +42,7 @@ export const TargetPathContextProvider = ({
}: TargetPathContextProviderProps) => {
const { currentLocation } = useCurrentLocationContext();
const { selectedEntries } = useSelectedEntriesContext();
- const { perspective, currentDirectoryPath, getPerspective } =
- useDirectoryContentContext();
+ const { currentDirectoryPath, getPerspective } = useDirectoryContentContext();
const firstRWLocation = useSelector(getFirstRWLocation);
@@ -70,7 +69,7 @@ export const TargetPathContextProvider = ({
return {
targetDirectoryPath,
};
- }, [firstRWLocation, selectedEntries, currentDirectoryPath, perspective]);
+ }, [firstRWLocation, selectedEntries, currentDirectoryPath]);
return (
<TargetPathContext.Provider value={context}>
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsx
index c3d9a5aa5..ee2c62b80 100644
--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx
+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx
@@ -107,7 +107,7 @@ type DirectoryContentContextData = {
) => Promise<boolean>;
openCurrentDirectory: (showHiddenEntries?: boolean) => Promise<boolean>;
clearDirectoryContent: () => void;
- perspective: TS.PerspectiveType;
+ //perspective: TS.PerspectiveType;
setManualDirectoryPerspective: (perspective: string, dir?: string) => void;
setCurrentDirectoryColor: (color: string) => void;
setCurrentDirectoryDirs: (dirs: TS.OrderVisibilitySettings[]) => void;
@@ -162,7 +162,7 @@ export const DirectoryContentContext =
openDirectory: undefined,
openCurrentDirectory: undefined,
clearDirectoryContent: () => {},
- perspective: undefined,
+ //perspective: undefined,
setManualDirectoryPerspective: undefined,
setCurrentDirectoryColor: () => {},
setCurrentDirectoryDirs: () => {},
@@ -228,7 +228,6 @@ export const DirectoryContentContextProvider = ({
const currentDirectoryEntries = useRef<TS.FileSystemEntry[]>([]);
const searchQuery = useRef<TS.SearchQuery>({});
const isSearchMode = useRef<boolean>(false);
- //const currentPerspective = useRef<TS.PerspectiveType>('unspecified');
const manualPerspective = useRef<TS.PerspectiveType>('unspecified');
const directoryMeta = useRef<TS.FileSystemEntryMeta>(getDefaultDirMeta());
const open = useRef<boolean>(false);
@@ -288,13 +287,13 @@ export const DirectoryContentContextProvider = ({
isLoading.current = true;
openDirectory(locationPath)
.then((success) => {
+ manualPerspective.current = 'unspecified';
isLoading.current = false;
return success;
})
.catch((ex) => console.log(ex));
}
});
- manualPerspective.current = 'unspecified';
} else {
currentLocationPath.current = '';
clearDirectoryContent();
@@ -310,11 +309,13 @@ export const DirectoryContentContextProvider = ({
cleanTrailingDirSeparator(action.entry.path)
) {
if (action.action === 'perspectiveChange') {
- manualPerspective.current =
- action.entry.meta.perspective === PerspectiveIDs.UNSPECIFIED
- ? defaultPerspective
- : action.entry.meta.perspective;
- forceUpdate();
+ if (action.entry.meta.perspective !== undefined) {
+ manualPerspective.current =
+ action.entry.meta.perspective === PerspectiveIDs.UNSPECIFIED
+ ? defaultPerspective
+ : action.entry.meta.perspective;
+ forceUpdate();
+ }
//setManualDirectoryPerspective(action.entry.meta.perspective);
} else if (
action.action === 'bgdColorChange' ||
@@ -966,10 +967,10 @@ export const DirectoryContentContextProvider = ({
return directoryContent;
}
- const perspective = useMemo(
+ /*const perspective = useMemo(
() => getPerspective(),
[directoryMeta.current?.perspective, manualPerspective.current],
- );
+ );*/
function getPerspective(): TS.PerspectiveType {
if (manualPerspective.current === 'unspecified') {
@@ -1006,30 +1007,6 @@ export const DirectoryContentContextProvider = ({
.catch((error) => {
console.log('Error getting properties for entry: ' + directory, error);
});
-
- /*return new Promise((resolve) => {
- if (isManual) {
- //&& currentPerspective.current === 'unspecified') {
- manualPerspective.current = perspective;
- resolve(null);
- } else {
- if (
- directory === undefined ||
- directory === currentDirectoryPath.current
- ) {
- currentPerspective.current = perspective;
- manualPerspective.current = isManual ? perspective : 'unspecified';
- }
- savePerspective(
- directory ? directory : currentDirectoryPath.current,
- perspective,
- ).then((entryMeta: TS.FileSystemEntryMeta) => resolve(entryMeta));
- }
- setSelectedEntries([]);
- if (reload) {
- forceUpdate();
- }
- });*/
}
function setCurrentDirectoryDirs(dirs: TS.OrderVisibilitySettings[]) {
@@ -1452,7 +1429,6 @@ export const DirectoryContentContextProvider = ({
openCurrentDirectory,
clearDirectoryContent,
setManualDirectoryPerspective,
- perspective,
setCurrentDirectoryColor,
setCurrentDirectoryDirs,
setCurrentDirectoryFiles,
@@ -1479,8 +1455,6 @@ export const DirectoryContentContextProvider = ({
currentDirectoryEntries.current,
currentDirectoryPath.current,
directoryMeta.current,
- //currentPerspective.current,
- perspective,
currentDirectoryFiles.current,
currentDirectoryDirs.current,
isSearchMode.current,
diff --git a/src/renderer/hooks/FSWatcherContextProvider.tsx b/src/renderer/hooks/FSWatcherContextProvider.tsx
index a17aaeb8b..90cf64c47 100644
--- a/src/renderer/hooks/FSWatcherContextProvider.tsx
+++ b/src/renderer/hooks/FSWatcherContextProvider.tsx
@@ -65,7 +65,7 @@ export const FSWatcherContextProvider = ({
currentDirectoryEntries,
loadDirectoryContent,
currentDirectoryPath,
- perspective,
+ getPerspective,
} = useDirectoryContentContext();
const { setReflectActions, reflectUpdateMeta } = useEditedEntryContext();
const ignored = useRef<string[]>([]);
@@ -80,7 +80,7 @@ export const FSWatcherContextProvider = ({
currentLocation.type !== locationType.TYPE_CLOUD
) {
if (currentDirectoryPath && currentDirectoryPath.length > 0) {
- const depth = perspective === PerspectiveIDs.KANBAN ? 3 : 1;
+ const depth = getPerspective() === PerspectiveIDs.KANBAN ? 3 : 1;
watchFolder(currentDirectoryPath, depth);
}
diff --git a/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
index 6df381ce4..df2b4f8e2 100644
--- a/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
+++ b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
@@ -29,6 +29,7 @@ import { Pro } from '-/pro';
import { useIOActionsContext } from '-/hooks/useIOActionsContext';
import { mergeFsEntryMeta } from '-/services/utils-io';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
+import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
type PerspectiveSettingsContextData = {
settings: TS.FolderSettings;
@@ -87,12 +88,12 @@ export const PerspectiveSettingsContextProvider = ({
const { currentLocation } = useCurrentLocationContext();
const {
currentDirectoryPath,
- perspective,
directoryMeta,
setDirectoryMeta,
getDefaultPerspectiveSettings,
getPerspective,
} = useDirectoryContentContext();
+ const { metaActions } = useEditedEntryMetaContext();
const { removeFolderCustomSettings, saveCurrentLocationMetaData } =
useIOActionsContext();
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
@@ -100,10 +101,21 @@ export const PerspectiveSettingsContextProvider = ({
getSettings(getPerspective(), directoryMeta),
);
- useEffect(() => {
+ /*useEffect(() => {
settings.current = getSettings(getPerspective(), directoryMeta);
forceUpdate();
- }, [perspective, directoryMeta]);
+ }, [perspective, directoryMeta]);*/
+
+ useEffect(() => {
+ if (metaActions && metaActions.length > 0) {
+ for (const action of metaActions) {
+ if (action.action === 'perspectiveChange') {
+ settings.current = getSettings(getPerspective(), directoryMeta);
+ forceUpdate();
+ }
+ }
+ }
+ }, [metaActions]);
function getSettings(
persp: string,