TagSpaces is an offline, open source, document manager with tagging support
refactoring perspective settings (#2029)
Stanimirf8e1a9b15801
diff --git a/.prettierignore b/.prettierignoreindex a85f099a2..eca67bd5a 100755--- a/.prettierignore+++ b/.prettierignore@@ -9,7 +9,6 @@ release/app/node_modulesrelease/app/distsrc/node_modulessrc/renderer/version.json-src/renderer/tagspaces.namespace.d.tsflow-typedextensions/extensions/*extensions/tagspacespro/libs/*diff --git a/src/main/main.ts b/src/main/main.tsindex 6bb04fa19..b4e6de6eb 100644--- a/src/main/main.ts+++ b/src/main/main.ts@@ -109,7 +109,6 @@ const browserWindowOptions: BrowserWindowConstructorOptions = {center: true,autoHideMenuBar: true,titleBarStyle: isMacLike ? 'hidden' : 'default',- trafficLightPosition: { x: 3, y: 3 },webPreferences: {spellcheck: true,preload:diff --git a/src/renderer/components/EntryContainer.tsx b/src/renderer/components/EntryContainer.tsxindex 0270e2f4d..dc59546b9 100644--- a/src/renderer/components/EntryContainer.tsx+++ b/src/renderer/components/EntryContainer.tsx@@ -89,6 +89,7 @@ function EntryContainer() {updateOpenedFile,reloadOpenedFile,toggleEntryFullWidth,+ isEntryInFullWidth,} = useOpenedEntryContext();const { saveDescription } = useDescriptionContext();const { readOnlyMode, switchLocationTypeByID, switchCurrentLocationType } =@@ -890,6 +891,8 @@ function EntryContainer() {reloadDocument={reloadDocument}toggleFullScreen={toggleFullScreen}startClosingEntry={startClosingEntry}+ isEntryInFullWidth={isEntryInFullWidth}+ desktopMode={desktopMode}/><EntryContainerNavisFile={openedFile.isFile}diff --git a/src/renderer/components/EntryContainerTitle.tsx b/src/renderer/components/EntryContainerTitle.tsxindex 1088f8326..cfe93c70b 100644--- a/src/renderer/components/EntryContainerTitle.tsx+++ b/src/renderer/components/EntryContainerTitle.tsx@@ -58,11 +58,19 @@ interface Props {toggleFullScreen: () => void;reloadDocument: () => void;startClosingEntry: (event) => void;+ isEntryInFullWidth: boolean;+ desktopMode: boolean;}function EntryContainerTitle(props: Props) {- const { isFileChanged, reloadDocument, toggleFullScreen, startClosingEntry } =- props;+ const {+ isFileChanged,+ reloadDocument,+ toggleFullScreen,+ startClosingEntry,+ isEntryInFullWidth,+ desktopMode,+ } = props;const { t } = useTranslation();const theme = useTheme();const { openedEntries, sharingLink, sharingParentFolderLink } =@@ -122,7 +130,7 @@ function EntryContainerTitle(props: Props) {}return (- <Box+ <divstyle={{paddingLeft: 5,display: 'flex',@@ -132,6 +140,10 @@ function EntryContainerTitle(props: Props) {flex: '1 1',overflowX: 'auto',overflowY: 'hidden',+ marginLeft:+ AppConfig.isMacLike && desktopMode && isEntryInFullWidth ? 60 : 0,+ // @ts-ignore+ WebkitAppRegion: 'drag',}}>{openedFile.isFile ? (@@ -166,6 +178,8 @@ function EntryContainerTitle(props: Props) {alignItems: 'center',textTransform: 'uppercase',paddingLeft: 10,+ // @ts-ignore+ WebkitAppRegion: 'no-drag',}}>{@@ -194,6 +208,8 @@ function EntryContainerTitle(props: Props) {display: 'flex',alignItems: 'center',paddingLeft: 10,+ // @ts-ignore+ WebkitAppRegion: 'no-drag',}}><FolderIcon style={{ fontSize: 20 }} />@@ -222,6 +238,10 @@ function EntryContainerTitle(props: Props) {aria-label="bookmark"size="small"onClick={bookmarkClick}+ style={{+ // @ts-ignore+ WebkitAppRegion: 'no-drag',+ }}>{haveBookmark ? (<BookmarkIcon@@ -247,7 +267,7 @@ function EntryContainerTitle(props: Props) {reloadDocument={reloadDocument}toggleFullScreen={toggleFullScreen}/>- </Box>+ </div>);}diff --git a/src/renderer/components/FolderContainer.tsx b/src/renderer/components/FolderContainer.tsxindex e33d1c112..5b79d2506 100644--- a/src/renderer/components/FolderContainer.tsx+++ b/src/renderer/components/FolderContainer.tsx@@ -43,7 +43,6 @@ import {} from './CommonIcons';import { Pro } from '../pro';import RenameEntryDialog from '-/components/dialogs/RenameEntryDialog';-import { TS } from '-/tagspaces.namespace';import PathBreadcrumbs from './PathBreadcrumbs';import { PerspectiveIDs, AvailablePerspectives } from '-/perspectives';// import LoadingAnimation from '-/components/LoadingAnimation';@@ -76,6 +75,9 @@ function FolderContainer(props: Props) {defaultPerspective,goBack,goForward,+ drawerOpened,+ progress,+ toggleUploadDialog,} = props;const { t } = useTranslation();@@ -91,26 +93,6 @@ function FolderContainer(props: Props) {isSearchMode,} = useDirectoryContentContext();- /**- * reflect update openedFile from perspective- */- /*useEffect(() => {- const { editedEntryPaths, openedFiles, openEntry } = props;-- if (!firstRender && editedEntryPaths && editedEntryPaths.length > 0) {- editedEntryPaths.forEach(editedEntryPath => {- const { action, path } = editedEntryPath;- // update opened file after delete sidecar tags- if (path && action.startsWith('edit')) {- const openedFile = openedFiles[0];- if (openedFile.path === path) {- openEntry(path);- }- }- });- }- }, [props.editedEntryPaths]);*/-const [isRenameEntryDialogOpened, setRenameEntryDialogOpened] =useState<boolean>(false);@@ -123,7 +105,6 @@ function FolderContainer(props: Props) {const showWelcomePanel =!currentDirectoryPath && currentDirectoryEntries.length < 1;- // && !(isSearchMode && props.lastSearchTimestamp);const openRenameEntryDialog = useCallback(() => setRenameEntryDialogOpened(true),@@ -157,7 +138,7 @@ function FolderContainer(props: Props) {}const getProgressValue = () => {- const objProgress = props.progress.find(+ const objProgress = progress.find((fileProgress) =>fileProgress.progress < 100 && fileProgress.progress > -1,);@@ -242,6 +223,8 @@ function FolderContainer(props: Props) {minHeight: 50,// @ts-ignoreWebkitAppRegion: 'drag',+ marginLeft:+ AppConfig.isMacLike && isDesktopMode && !drawerOpened ? 60 : 0,}}><IconButton@@ -311,12 +294,12 @@ function FolderContainer(props: Props) {<SearchIcon /></IconButton></Tooltip>- {props.progress && props.progress.length > 0 && (+ {progress?.length > 0 && (<IconButtonid="progressButton"title={t('core:progress')}data-tid="uploadProgress"- onClick={() => props.toggleUploadDialog()}+ onClick={() => toggleUploadDialog()}style={{position: 'relative',padding: '8px 12px 6px 8px',@@ -351,7 +334,7 @@ function FolderContainer(props: Props) {/>)}</div>- {props.isDesktopMode && (+ {isDesktopMode && (<ToggleButtonGroupvalue={currentPerspective}size="small"diff --git a/src/renderer/components/RenderPerspective.tsx b/src/renderer/components/RenderPerspective.tsxindex 39e634c94..e495f9ef4 100644--- a/src/renderer/components/RenderPerspective.tsx+++ b/src/renderer/components/RenderPerspective.tsx@@ -29,6 +29,7 @@ import LoadingLazy from '-/components/LoadingLazy';import { SortedDirContextProvider } from '-/perspectives/grid-perspective/hooks/SortedDirContextProvider';import { PaginationContextProvider } from '-/hooks/PaginationContextProvider';import { ThumbGenerationContextProvider } from '-/hooks/ThumbGenerationContextProvider';+import { PerspectiveSettingsContextProvider } from '-/hooks/PerspectiveSettingsContextProvider';const GridPerspective = React.lazy(() =>@@ -42,7 +43,9 @@ function GridPerspectiveAsync(props) {<SortedDirContextProvider><PaginationContextProvider><ThumbGenerationContextProvider>- <GridPerspective {...props} />+ <PerspectiveSettingsContextProvider>+ <GridPerspective {...props} />+ </PerspectiveSettingsContextProvider></ThumbGenerationContextProvider></PaginationContextProvider></SortedDirContextProvider>@@ -60,7 +63,9 @@ function ListPerspectiveAsync(props) {<SortedDirContextProvider><PaginationContextProvider><ThumbGenerationContextProvider>- <ListPerspective {...props} />+ <PerspectiveSettingsContextProvider>+ <ListPerspective {...props} />+ </PerspectiveSettingsContextProvider></ThumbGenerationContextProvider></PaginationContextProvider></SortedDirContextProvider>@@ -107,7 +112,9 @@ function KanBanPerspectiveAsync(props) {return (<React.Suspense fallback={<LoadingLazy />}><ThumbGenerationContextProvider>- <KanBanPerspective {...props} />+ <PerspectiveSettingsContextProvider>+ <KanBanPerspective {...props} />+ </PerspectiveSettingsContextProvider></ThumbGenerationContextProvider></React.Suspense>);diff --git a/src/renderer/components/TagsPreview.tsx b/src/renderer/components/TagsPreview.tsxindex ef59b8fc1..286bdc167 100644--- a/src/renderer/components/TagsPreview.tsx+++ b/src/renderer/components/TagsPreview.tsx@@ -90,6 +90,8 @@ function TagsPreview(props: Props) {lineHeight: '16px',color: firstTagTextColor || defaultTextColor, //tag1Colors.textcolor ,textAlign: 'center',+ // @ts-ignore+ WebkitAppRegion: 'no-drag',}}>{moreThanOne ? tags.length : '1'}diff --git a/src/renderer/components/ZoomComponent.tsx b/src/renderer/components/ZoomComponent.tsxindex 7ab4bae9e..79f1fef24 100644--- a/src/renderer/components/ZoomComponent.tsx+++ b/src/renderer/components/ZoomComponent.tsx@@ -23,64 +23,68 @@ import ZoomOutIcon from '@mui/icons-material/RemoveCircleOutline';import ZoomInIcon from '@mui/icons-material/ControlPoint';import Typography from '@mui/material/Typography';import IconButton from '@mui/material/IconButton';+import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';+import { useReducer } from 'react';interface Props {- entrySize: EntrySizes;- changeEntrySize: (entrySize: EntrySizes) => void;+ preview: boolean;}-export enum EntrySizes {- huge = 'huge',- big = 'big',- normal = 'normal',- small = 'small',- tiny = 'tiny',-}+export default function ZoomComponent(props: Props) {+ const { preview } = props;+ const { entrySize, setSettings, saveSettings } =+ usePerspectiveSettingsContext();+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);+ const theme = useTheme();+ const entrySizePercent = mapEntrySizeToPercent();-function mapEntrySizeToPercent(entrySize: EntrySizes) {- if (entrySize === EntrySizes.huge) {- return '120%';- } else if (entrySize === EntrySizes.big) {- return '110%';- } else if (entrySize === EntrySizes.normal) {- return '100%';- } else if (entrySize === EntrySizes.small) {- return '90%';- } else if (entrySize === EntrySizes.tiny) {- return '80%';+ function mapEntrySizeToPercent() {+ if (entrySize === 'huge') {+ return '120%';+ } else if (entrySize === 'big') {+ return '110%';+ } else if (entrySize === 'normal') {+ return '100%';+ } else if (entrySize === 'small') {+ return '90%';+ } else if (entrySize === 'tiny') {+ return '80%';+ }}-}-export default function ZoomComponent(props: Props) {- const { changeEntrySize, entrySize } = props;- const theme = useTheme();- const entrySizePercent = mapEntrySizeToPercent(entrySize);+ function changeEntrySize(size) {+ setSettings({ entrySize: size });+ if (!preview) {+ saveSettings(); //isDefaultSetting);+ }+ forceUpdate();+ }function zoomIn() {- if (entrySize === EntrySizes.huge) {- // changeEntrySize(EntrySizes.tiny);- } else if (entrySize === EntrySizes.big) {- changeEntrySize(EntrySizes.huge);- } else if (entrySize === EntrySizes.normal) {- changeEntrySize(EntrySizes.big);- } else if (entrySize === EntrySizes.small) {- changeEntrySize(EntrySizes.normal);- } else if (entrySize === EntrySizes.tiny) {- changeEntrySize(EntrySizes.small);+ if (entrySize === 'huge') {+ // changeEntrySize(TS.EntrySizes.tiny);+ } else if (entrySize === 'big') {+ changeEntrySize('huge');+ } else if (entrySize === 'normal') {+ changeEntrySize('big');+ } else if (entrySize === 'small') {+ changeEntrySize('normal');+ } else if (entrySize === 'tiny') {+ changeEntrySize('small');}}function zoomOut() {- if (entrySize === EntrySizes.huge) {- changeEntrySize(EntrySizes.big);- } else if (entrySize === EntrySizes.big) {- changeEntrySize(EntrySizes.normal);- } else if (entrySize === EntrySizes.normal) {- changeEntrySize(EntrySizes.small);- } else if (entrySize === EntrySizes.small) {- changeEntrySize(EntrySizes.tiny);- } else if (entrySize === EntrySizes.tiny) {- // changeEntrySize(EntrySizes.small);+ if (entrySize === 'huge') {+ changeEntrySize('big');+ } else if (entrySize === 'big') {+ changeEntrySize('normal');+ } else if (entrySize === 'normal') {+ changeEntrySize('small');+ } else if (entrySize === 'small') {+ changeEntrySize('tiny');+ } else if (entrySize === 'tiny') {+ // changeEntrySize(TS.EntrySizes.small);}}diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsxindex 579d633f0..1e0535959 100644--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx@@ -65,6 +65,8 @@ import { getSearches } from '-/reducers/searches';import { getTagColors } from '-/services/taglibrary-utils';import { defaultTitle } from '-/services/search';import { Pro } from '-/pro';+import { defaultSettings as defaultGridSettings } from '-/perspectives/grid-perspective';+import { defaultSettings as defaultListSettings } from '-/perspectives/list';type DirectoryContentContextData = {currentLocationPath: string;@@ -121,6 +123,7 @@ type DirectoryContentContextData = {enterSearchMode: () => void;exitSearchMode: () => void;findFromSavedSearch: (uuid: string) => void;+ getDefaultPerspectiveSettings: (perspective: string) => TS.FolderSettings;};export const DirectoryContentContext =@@ -159,6 +162,7 @@ export const DirectoryContentContext =enterSearchMode: () => {},exitSearchMode: () => {},findFromSavedSearch: () => {},+ getDefaultPerspectiveSettings: undefined,});export type DirectoryContentContextProviderProps = {@@ -197,11 +201,8 @@ export const DirectoryContentContextProvider = ({const currentDirectoryEntries = useRef<TS.FileSystemEntry[]>([]);const searchQuery = useRef<TS.SearchQuery>({});const isSearchMode = useRef<boolean>(false);- /**- * if search is performed = timestamp otherwise undefined- */- // const lastSearchTimestamp = useRef<number>(undefined);- const directoryMeta = useRef<TS.FileSystemEntryMeta>({ id: getUuid() });+ const currentPerspective = useRef<TS.PerspectiveType>('unspecified');+ const directoryMeta = useRef<TS.FileSystemEntryMeta>(getDefaultDirMeta());/*** isMetaLoaded boolean if thumbs and description from meta are loaded* is using why directoryMeta can be loaded but empty@@ -210,7 +211,6 @@ export const DirectoryContentContextProvider = ({const isMetaLoaded = useRef<boolean>(undefined);//const isMetaFolderExist = useRef<boolean>(undefined);const currentDirectoryPath = useRef<string>(undefined);- const currentPerspective = useRef<string>(PerspectiveIDs.UNSPECIFIED);const currentDirectoryFiles = useRef<TS.OrderVisibilitySettings[]>([]);const currentDirectoryDirs = useRef<TS.OrderVisibilitySettings[]>([]);// const firstRender = useFirstRender();@@ -282,6 +282,34 @@ export const DirectoryContentContextProvider = ({}}, [editedEntryPaths]);*/+ function getPerspective(): TS.PerspectiveType {+ return currentPerspective.current === 'unspecified'+ ? 'grid'+ : currentPerspective.current;+ }++ function getDefaultDirMeta(): TS.FileSystemEntryMeta {+ const perspective = getPerspective();+ const settings: TS.PerspectiveSettings = {+ [getPerspective()]: getDefaultPerspectiveSettings(perspective),+ };+ return {+ id: getUuid(),+ perspectiveSettings: settings,+ };+ }++ function getDefaultPerspectiveSettings(perspective: string) {+ if (perspective === PerspectiveIDs.GRID) {+ return defaultGridSettings;+ } else if (perspective === PerspectiveIDs.LIST) {+ return defaultListSettings;+ } else if (perspective === PerspectiveIDs.KANBAN && Pro) {+ return Pro.Perspectives.KanBanPerspectiveSettings;+ }+ return defaultGridSettings;+ }+function setCurrentDirectoryEntries(dirEntries, reflect = true) {currentDirectoryEntries.current = dirEntries;if (reflect) {@@ -289,56 +317,52 @@ export const DirectoryContentContextProvider = ({}}- const reflectRenameEntries = useMemo(() => {- return (paths: Array<string[]>): Promise<boolean> => {- const metaChanged = [];- const newEntries = paths- .map((path) => {- const entry = currentDirectoryEntries.current.find(- (e) => e.path === path[0],+ function reflectRenameEntries(paths: Array<string[]>): Promise<boolean> {+ const metaChanged = [];+ const newEntries = paths+ .map((path) => {+ const entry = currentDirectoryEntries.current.find(+ (e) => e.path === path[0],+ );+ if (path[0] === path[1]) {+ metaChanged.push(entry);+ return undefined;+ }+ return getNewEntry(entry, path[1]);+ })+ .filter((item) => item !== undefined);+ if (newEntries.length > 0) {+ const newDirectoryEntries = currentDirectoryEntries.current.map(+ (entry) => {+ const newEntry = newEntries.find(+ (nEntry) => nEntry && nEntry.uuid === entry.uuid,);- if (path[0] === path[1]) {- metaChanged.push(entry);- return undefined;+ if (newEntry) {+ return newEntry;}- return getNewEntry(entry, path[1]);- })- .filter((item) => item !== undefined);- if (newEntries.length > 0) {- const newDirectoryEntries = currentDirectoryEntries.current.map(- (entry) => {- const newEntry = newEntries.find(- (nEntry) => nEntry && nEntry.uuid === entry.uuid,- );- if (newEntry) {- return newEntry;- }- return entry;- },- );- setCurrentDirectoryEntries(newDirectoryEntries);- setSelectedEntries(newEntries);- }+ return entry;+ },+ );+ setCurrentDirectoryEntries(newDirectoryEntries);+ setSelectedEntries(newEntries);+ }- if (metaChanged.length > 0) {- const enhancedEntriesPromises = metaChanged.map((entry) =>- getMetaForEntry(entry),- );- Promise.allSettled(enhancedEntriesPromises).then((results) => {- const entries = results- .filter(({ status }) => status === 'fulfilled')- .map(- (p) => (p as PromiseFulfilledResult<TS.FileSystemEntry>).value,- );- updateCurrentDirEntries(entries);- });- /* Promise.all(enhancedEntriesPromises).then((entries) => {+ if (metaChanged.length > 0) {+ const enhancedEntriesPromises = metaChanged.map((entry) =>+ getMetaForEntry(entry),+ );+ Promise.allSettled(enhancedEntriesPromises).then((results) => {+ const entries = results+ .filter(({ status }) => status === 'fulfilled')+ .map((p) => (p as PromiseFulfilledResult<TS.FileSystemEntry>).value);+ updateCurrentDirEntries(entries);+ });+ /* Promise.all(enhancedEntriesPromises).then((entries) => {updateCurrentDirEntries(entries);});*/- }- return Promise.resolve(true);- };- }, [currentDirectoryEntries.current]);+ }+ return Promise.resolve(true);+ }function getNewEntry(entry: TS.FileSystemEntry, newPath): TS.FileSystemEntry {if (entry) {@@ -423,26 +447,18 @@ export const DirectoryContentContextProvider = ({}}- const updateCurrentDirEntry = useMemo(() => {- return (path: string, entry: any) => {- if (path === currentDirectoryPath.current) {- directoryMeta.current = directoryMeta.current- ? { ...directoryMeta.current, ...entry }- : entry;- }- const entryUpdated = { ...entry, ...(!entry.path && { path: path }) };- /*if (searchMode.current) {- const results = updateFsEntries(- GlobalSearch.getInstance().getResults(),- [entryUpdated]- );- GlobalSearch.getInstance().setResults(results);- } else {*/- setCurrentDirectoryEntries(- updateFsEntries(currentDirectoryEntries.current, [entryUpdated]),- );- };- }, [currentDirectoryEntries.current]);+ function updateCurrentDirEntry(path: string, entry: any) {+ if (path === currentDirectoryPath.current) {+ directoryMeta.current = directoryMeta.current+ ? { ...directoryMeta.current, ...entry }+ : entry;+ }+ const entryUpdated = { ...entry, ...(!entry.path && { path: path }) };++ setCurrentDirectoryEntries(+ updateFsEntries(currentDirectoryEntries.current, [entryUpdated]),+ );+ }const getMergedEntries = (entries1, entries2) => {if (entries1 && entries1.length > 0) {@@ -522,46 +538,30 @@ export const DirectoryContentContextProvider = ({);return loadJSONFile(metaFilePath).then((fsEntryMeta) => {+ directoryMeta.current = fsEntryMeta;isMetaLoaded.current = true;- return loadDirectoryContentInt(- directoryPath,- fsEntryMeta,- showHiddenEntries,- );+ return loadDirectoryContentInt(directoryPath, showHiddenEntries);}).catch((err) => {- console.debug(- 'Error loading meta of:' + directoryPath + ' ' + err,- );+ console.log('Error loading meta of:' + directoryPath, err);isMetaLoaded.current = true;- return loadDirectoryContentInt(- directoryPath,- undefined,- showHiddenEntries,- );+ directoryMeta.current = getDefaultDirMeta();+ return loadDirectoryContentInt(directoryPath, showHiddenEntries);});} else {- //isMetaFolderExist.current = false;- return loadDirectoryContentInt(- directoryPath,- undefined,- showHiddenEntries,- );+ directoryMeta.current = getDefaultDirMeta();+ return loadDirectoryContentInt(directoryPath, showHiddenEntries);}});} else {isMetaLoaded.current = false;- return loadDirectoryContentInt(- directoryPath,- undefined,- showHiddenEntries,- );+ directoryMeta.current = getDefaultDirMeta();+ return loadDirectoryContentInt(directoryPath, showHiddenEntries);}}function loadDirectoryContentInt(directoryPath: string,- fsEntryMeta?: TS.FileSystemEntryMeta,showHiddenEntries = undefined,): Promise<TS.FileSystemEntry[]> {showNotification(t('core:loading'), 'info', false);@@ -594,7 +594,6 @@ export const DirectoryContentContextProvider = ({return loadDirectorySuccess(directoryPath,results,- fsEntryMeta,showHiddenEntries,);}@@ -653,29 +652,29 @@ export const DirectoryContentContextProvider = ({function loadDirectorySuccess(directoryPath: string,dirEntries: TS.FileSystemEntry[],- dirMeta?: TS.FileSystemEntryMeta,showHiddenEntries = undefined,): TS.FileSystemEntry[] {hideNotifications(['error']);- if (dirMeta) {- directoryMeta.current = dirMeta;- if (dirMeta.perspective) {- currentPerspective.current = dirMeta.perspective;+ if (directoryMeta.current) {+ if (directoryMeta.current.perspective) {+ currentPerspective.current = directoryMeta.current+ .perspective as TS.PerspectiveType;} else {- currentPerspective.current = PerspectiveIDs.UNSPECIFIED;+ currentPerspective.current = 'unspecified';}- if (dirMeta.customOrder) {- if (dirMeta.customOrder.files) {- currentDirectoryFiles.current = dirMeta.customOrder.files;+ if (directoryMeta.current.customOrder) {+ if (directoryMeta.current.customOrder.files) {+ currentDirectoryFiles.current =+ directoryMeta.current.customOrder.files;}- if (dirMeta.customOrder.folders) {- currentDirectoryDirs.current = dirMeta.customOrder.folders;+ if (directoryMeta.current.customOrder.folders) {+ currentDirectoryDirs.current =+ directoryMeta.current.customOrder.folders;}}} else {- directoryMeta.current = undefined;- currentPerspective.current = PerspectiveIDs.UNSPECIFIED;+ currentPerspective.current = 'unspecified';}const directoryContent = enhanceDirectoryContent(dirEntries,@@ -765,7 +764,7 @@ export const DirectoryContentContextProvider = ({}, [showUnixHiddenEntries]);function setCurrentDirectoryPerspective(- perspective: string,+ perspective: TS.PerspectiveType,reload: boolean = true,) {currentPerspective.current = perspective;@@ -794,40 +793,36 @@ export const DirectoryContentContextProvider = ({currentDirectoryFiles.current = files;}- const addDirectoryEntries = useMemo(() => {- return (entries: TS.FileSystemEntry[]) => {- setCurrentDirectoryEntries([- ...currentDirectoryEntries.current,- ...entries,- ]);- };- }, [currentDirectoryEntries.current]);-- const removeDirectoryEntries = useMemo(() => {- return (entryPaths: string[]) => {- if (entryPaths.some((ePath) => ePath === currentDirectoryPath.current)) {- //handle currentDirectoryPath deleted- return openDirectory(- extractContainingDirectoryPath(- currentDirectoryPath.current,- PlatformIO.getDirSeparator(),- ),- );- } else {- const index = currentDirectoryEntries.current.findIndex((entry) =>- entryPaths.includes(entry.path),- );- if (index > -1) {- // delete in place (for fs watcher events unlink/add in 20ms)- currentDirectoryEntries.current.splice(index, 1);- /*const entries = currentDirectoryEntries.filter(+ function addDirectoryEntries(entries: TS.FileSystemEntry[]) {+ setCurrentDirectoryEntries([+ ...currentDirectoryEntries.current,+ ...entries,+ ]);+ }++ function removeDirectoryEntries(entryPaths: string[]) {+ if (entryPaths.some((ePath) => ePath === currentDirectoryPath.current)) {+ //handle currentDirectoryPath deleted+ return openDirectory(+ extractContainingDirectoryPath(+ currentDirectoryPath.current,+ PlatformIO.getDirSeparator(),+ ),+ );+ } else {+ const index = currentDirectoryEntries.current.findIndex((entry) =>+ entryPaths.includes(entry.path),+ );+ if (index > -1) {+ // delete in place (for fs watcher events unlink/add in 20ms)+ currentDirectoryEntries.current.splice(index, 1);+ /*const entries = currentDirectoryEntries.filter((entry) => !entryPaths.includes(entry.path),);*/- setCurrentDirectoryEntries([...currentDirectoryEntries.current]); //entries);- }+ setCurrentDirectoryEntries([...currentDirectoryEntries.current]); //entries);}- };- }, [currentDirectoryEntries.current]);+ }+ }function setDirectoryMeta(meta: TS.FileSystemEntryMeta) {directoryMeta.current = meta;@@ -938,15 +933,15 @@ export const DirectoryContentContextProvider = ({enterSearchMode,exitSearchMode,findFromSavedSearch,+ getDefaultPerspectiveSettings,};}, [- currentLocation,+ // currentLocation,currentLocationPath.current,currentDirectoryEntries.current,currentDirectoryPath.current,directoryMeta.current,currentPerspective.current,- //isMetaFolderExist.current,currentDirectoryFiles.current,currentDirectoryDirs.current,isSearchMode.current,diff --git a/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsxnew file mode 100644index 000000000..f3ba2d8ff--- /dev/null+++ b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx@@ -0,0 +1,214 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2023-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import React, {+ createContext,+ useEffect,+ useMemo,+ useReducer,+ useRef,+} from 'react';+import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';+import { TS } from '-/tagspaces.namespace';+import { PerspectiveIDs } from '-/perspectives';+import { Pro } from '-/pro';+import { removeFolderCustomSettings } from '-/utils/metaoperations';++type PerspectiveSettingsContextData = {+ orderBy: boolean;+ sortBy: string;+ singleClickAction: string;+ entrySize: TS.EntrySizes;+ thumbnailMode: TS.ThumbnailMode;+ showDirectories: boolean;+ showDetails: boolean;+ showDescription: boolean;+ showEntriesDescription: boolean;+ showTags: boolean;+ gridPageLimit: number;+ showFolderContent: boolean; //KanBan+ layoutType: string; //KanBan+ showSubFolderDetails: boolean; // KanBan+ filesLimit: number; // KanBan+ haveLocalSetting: () => boolean;+ resetLocalSetting: () => void;+ setSettings: (set: any) => void;+ saveSettings: (isDefaultSetting?: boolean) => void;+};++export const PerspectiveSettingsContext =+ createContext<PerspectiveSettingsContextData>({+ orderBy: true,+ sortBy: 'byName',+ singleClickAction: 'openInternal', // openInternal openExternal+ entrySize: 'small',+ thumbnailMode: 'contain', // cover contain+ showDirectories: true,+ showDetails: true,+ showDescription: false,+ showEntriesDescription: true,+ showTags: true,+ gridPageLimit: 100,+ showFolderContent: false,+ layoutType: 'grid',+ showSubFolderDetails: false,+ filesLimit: 15,+ haveLocalSetting: undefined,+ resetLocalSetting: undefined,+ setSettings: undefined,+ saveSettings: undefined,+ });++export type PerspectiveSettingsContextProviderProps = {+ children: React.ReactNode;+};++export const PerspectiveSettingsContextProvider = ({+ children,+}: PerspectiveSettingsContextProviderProps) => {+ const {+ currentDirectoryPath,+ currentDirectoryPerspective,+ directoryMeta,+ setDirectoryMeta,+ getDefaultPerspectiveSettings,+ } = useDirectoryContentContext();+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);+ const settings = useRef<TS.FolderSettings>(+ getSettings(getPerspective(), directoryMeta),+ );++ useEffect(() => {+ settings.current = getSettings(getPerspective(), directoryMeta);+ forceUpdate();+ }, [currentDirectoryPerspective, directoryMeta]);++ function getSettings(+ perspective: string,+ directoryMeta: TS.FileSystemEntryMeta,+ ): TS.FolderSettings {+ const defaultSettings = getDefaultPerspectiveSettings(perspective);+ let s: TS.FolderSettings = defaultSettings;+ if (+ Pro &&+ directoryMeta &&+ directoryMeta.perspectiveSettings &&+ directoryMeta.perspectiveSettings[perspective]+ ) {+ const proSettings: TS.FolderSettings =+ directoryMeta.perspectiveSettings[perspective];+ if (proSettings) {+ s = { ...s, ...proSettings };+ }+ } else if (defaultSettings.settingsKey) {+ // loading settings for not Pro+ const localStorageSettings: TS.FolderSettings = JSON.parse(+ localStorage.getItem(defaultSettings.settingsKey),+ );+ if (localStorageSettings) {+ s = { ...s, ...localStorageSettings };+ }+ }++ return s;+ }++ function setSettings(newSettings) {+ settings.current = { ...settings.current, ...newSettings };+ forceUpdate();+ }++ function haveLocalSetting() {+ return (+ directoryMeta &&+ directoryMeta.perspectiveSettings &&+ directoryMeta.perspectiveSettings[getPerspective()]+ );+ }++ /**+ * remove custom folder settings+ */+ function resetLocalSetting() {+ removeFolderCustomSettings(currentDirectoryPath, getPerspective()).then(+ (fsEntryMeta: TS.FileSystemEntryMeta) => {+ setDirectoryMeta(fsEntryMeta);+ },+ );+ }++ function getPerspective() {+ return currentDirectoryPerspective === PerspectiveIDs.UNSPECIFIED+ ? PerspectiveIDs.GRID+ : currentDirectoryPerspective;+ }++ /**+ * @param isDefaultSetting true: save in default settings; false: save per folder settings;+ */+ function saveSettings(isDefaultSetting = undefined) {+ if (isDefaultSetting === undefined) {+ isDefaultSetting = !haveLocalSetting();+ }+ if (Pro && !isDefaultSetting) {+ Pro.MetaOperations.savePerspectiveSettings(+ currentDirectoryPath,+ getPerspective(),+ settings.current,+ ).then((fsEntryMeta: TS.FileSystemEntryMeta) => {+ setDirectoryMeta(fsEntryMeta);+ });+ } else {+ const defaultSettings = getDefaultPerspectiveSettings(getPerspective());+ localStorage.setItem(+ defaultSettings.settingsKey,+ JSON.stringify(settings.current),+ );+ }+ }++ const context = useMemo(() => {+ return {+ showDirectories: settings.current.showDirectories,+ showDescription: settings.current.showDescription,+ showEntriesDescription: settings.current.showEntriesDescription,+ showDetails: settings.current.showDetails,+ showTags: settings.current.showTags,+ orderBy: settings.current.orderBy,+ sortBy: settings.current.sortBy,+ singleClickAction: settings.current.singleClickAction,+ entrySize: settings.current.entrySize,+ thumbnailMode: settings.current.thumbnailMode,+ gridPageLimit: settings.current.gridPageLimit,+ showFolderContent: settings.current.showFolderContent,+ layoutType: settings.current.layoutType,+ showSubFolderDetails: settings.current.showSubFolderDetails,+ filesLimit: settings.current.filesLimit,+ resetLocalSetting: resetLocalSetting,+ haveLocalSetting: haveLocalSetting,+ setSettings: setSettings,+ saveSettings: saveSettings,+ };+ }, [settings.current]);++ return (+ <PerspectiveSettingsContext.Provider value={context}>+ {children}+ </PerspectiveSettingsContext.Provider>+ );+};diff --git a/src/renderer/hooks/usePerspectiveSettingsContext.tsx b/src/renderer/hooks/usePerspectiveSettingsContext.tsxnew file mode 100644index 000000000..2fb62794a--- /dev/null+++ b/src/renderer/hooks/usePerspectiveSettingsContext.tsx@@ -0,0 +1,24 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2023-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import { useContext } from 'react';++import { PerspectiveSettingsContext } from './PerspectiveSettingsContextProvider';++export const usePerspectiveSettingsContext = () =>+ useContext(PerspectiveSettingsContext);diff --git a/src/renderer/perspectives/grid-perspective/components/GridCell.tsx b/src/renderer/perspectives/grid-perspective/components/GridCell.tsxindex 30557a25e..f619a7d3b 100644--- a/src/renderer/perspectives/grid-perspective/components/GridCell.tsx+++ b/src/renderer/perspectives/grid-perspective/components/GridCell.tsx@@ -20,15 +20,12 @@ import React, { useMemo } from 'react';import { useSelector, useDispatch } from 'react-redux';import { useTheme, styled } from '@mui/material/styles';import { useTranslation } from 'react-i18next';-import classNames from 'classnames';import Typography from '@mui/material/Typography';-import Paper from '@mui/material/Paper';import Box from '@mui/material/Box';import Card from '@mui/material/Card';import CardHeader from '@mui/material/CardHeader';import CardMedia from '@mui/material/CardMedia';import CardContent from '@mui/material/CardContent';-import CardActions from '@mui/material/CardActions';import Tooltip from '-/components/Tooltip';import { FolderOutlineIcon } from '-/components/CommonIcons';import IconButton from '@mui/material/IconButton';@@ -72,39 +69,39 @@ import { defaultSettings } from '../index';import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';-import { EntrySizes } from '-/components/ZoomComponent';+import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';export function urlGetDelim(url) {return url.indexOf('?') > 0 ? '&' : '?';}-export function calculateEntryWitdth(entrySize: EntrySizes) {+export function calculateEntryWidth(entrySize: TS.EntrySizes) {let entryWidth = 200;- if (entrySize === EntrySizes.tiny) {+ if (entrySize === 'tiny') {entryWidth = 100;- } else if (entrySize === EntrySizes.small) {+ } else if (entrySize === 'small') {entryWidth = 150;- } else if (entrySize === EntrySizes.normal) {+ } else if (entrySize === 'normal') {entryWidth = 200;- } else if (entrySize === EntrySizes.big) {+ } else if (entrySize === 'big') {entryWidth = 250;- } else if (entrySize === EntrySizes.huge) {+ } else if (entrySize === 'huge') {entryWidth = 300;}return entryWidth;}-export function calculateEntryHeight(entrySize: EntrySizes) {+export function calculateEntryHeight(entrySize: TS.EntrySizes) {let entryHeight = 200;- if (entrySize === EntrySizes.tiny) {+ if (entrySize === 'tiny') {entryHeight = 100;- } else if (entrySize === EntrySizes.small) {+ } else if (entrySize === 'small') {entryHeight = 150;- } else if (entrySize === EntrySizes.normal) {+ } else if (entrySize === 'normal') {entryHeight = 200;- } else if (entrySize === EntrySizes.big) {+ } else if (entrySize === 'big') {entryHeight = 250;- } else if (entrySize === EntrySizes.huge) {+ } else if (entrySize === 'huge') {entryHeight = 300;}return entryHeight;@@ -114,32 +111,24 @@ interface Props {selected: boolean;isLast?: boolean;fsEntry: TS.FileSystemEntry;- entrySize: EntrySizes;style?: any;- thumbnailMode: any;selectEntry: (fsEntry: TS.FileSystemEntry) => void;deselectEntry: (fsEntry: TS.FileSystemEntry) => void;selectionMode: boolean;- showTags: boolean;handleTagMenu: (event: Object, tag: TS.Tag, entryPath: string) => void;handleGridContextMenu: (event: Object, fsEntry: TS.FileSystemEntry) => void;handleGridCellDblClick: (event: Object, fsEntry: TS.FileSystemEntry) => void;handleGridCellClick: (event: Object, fsEntry: TS.FileSystemEntry) => void;- showEntriesDescription?: boolean;}function GridCell(props: Props) {const {selected,fsEntry,- entrySize,- thumbnailMode,handleTagMenu,handleGridContextMenu,handleGridCellDblClick,handleGridCellClick,- showEntriesDescription,- showTags,selectEntry,deselectEntry,selectionMode,@@ -148,13 +137,15 @@ function GridCell(props: Props) {const { t } = useTranslation();const theme = useTheme();+ const { entrySize, showEntriesDescription, showTags } =+ usePerspectiveSettingsContext();const { selectedEntries } = useSelectedEntriesContext();const { addTags, editTagForEntry } = useTaggingActionsContext();const { readOnlyMode } = useCurrentLocationContext();const supportedFileTypes = useSelector(getSupportedFileTypes);const reorderTags: boolean = useSelector(isReorderTags);const lastThumbnailImageChange = useSelector(getLastThumbnailImageChange);- const desktopMode = useSelector(isDesktopMode);+ // const desktopMode = useSelector(isDesktopMode);const dispatch: AppDispatch = useDispatch();const handleEditTag = (path: string, tag: TS.Tag, newTagTitle?: string) => {@@ -220,8 +211,7 @@ function GridCell(props: Props) {];const entryPath = fSystemEntry.path;- const isSmall =- entrySize === EntrySizes.tiny || entrySize === EntrySizes.small;+ const isSmall = entrySize === 'tiny' || entrySize === 'small';const renderTags = useMemo(() => {let sideCarLength = 0;diff --git a/src/renderer/perspectives/grid-perspective/components/GridCellsContainer.tsx b/src/renderer/perspectives/grid-perspective/components/GridCellsContainer.tsxnew file mode 100644index 000000000..9f2f84b77--- /dev/null+++ b/src/renderer/perspectives/grid-perspective/components/GridCellsContainer.tsx@@ -0,0 +1,36 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import React from 'react';+import { useGridCellsStyleContext } from '../hooks/useGridCellsStyleContext';++export type GridCellsContainerProps = {+ children: React.ReactNode;+};++export const GridCellsContainer = ({ children }: GridCellsContainerProps) => {+ const { cellsStyle } = useGridCellsStyleContext();++ return (+ <div style={cellsStyle} data-tid="perspectiveGridFileTable">+ {children}+ </div>+ );+};++export default GridCellsContainer;diff --git a/src/renderer/perspectives/grid-perspective/components/GridOptionsMenu.tsx b/src/renderer/perspectives/grid-perspective/components/GridOptionsMenu.tsxindex 125e481f1..a587eb82c 100644--- a/src/renderer/perspectives/grid-perspective/components/GridOptionsMenu.tsx+++ b/src/renderer/perspectives/grid-perspective/components/GridOptionsMenu.tsx@@ -31,45 +31,29 @@ import RadioUncheckedIcon from '@mui/icons-material/RadioButtonUnchecked';import SettingsIcon from '@mui/icons-material/Settings';import HelpIcon from '@mui/icons-material/Help';import { useTranslation } from 'react-i18next';+import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';interface Props {open: boolean;onClose: () => void;anchorEl: Element;- toggleShowDirectories: () => void;- toggleShowTags: () => void;- showDirectories: boolean;- showTags: boolean;- toggleThumbnailsMode: () => string;- thumbnailMode: string;- singleClickAction: string;- entrySize: string;- changeEntrySize: (entrySize: string) => void;- changeSingleClickAction: (actionType: string) => void;openHelpWebPage: () => void;openSettings: () => void;}function GridOptionsMenu(props: Props) {+ const { open, onClose, anchorEl, openHelpWebPage, openSettings } = props;++ const { t } = useTranslation();const {- open,- onClose,- anchorEl,- changeEntrySize,- toggleShowDirectories,showDirectories,- toggleShowTags,showTags,- toggleThumbnailsMode,thumbnailMode,- changeSingleClickAction,entrySize,singleClickAction,- openHelpWebPage,- openSettings,- } = props;-- const { t } = useTranslation();+ setSettings,+ saveSettings,+ } = usePerspectiveSettingsContext();return (<Menu anchorEl={anchorEl} open={open} onClose={onClose}>@@ -77,7 +61,10 @@ function GridOptionsMenu(props: Props) {data-tid="gridPerspectiveToggleShowDirectories"title={t('core:showHideDirectories')}aria-label={t('core:showHideDirectories')}- onClick={toggleShowDirectories}+ onClick={() => {+ setSettings({ showDirectories: !showDirectories });+ saveSettings(false);+ }}><ListItemIcon>{showDirectories ? <CheckBoxIcon /> : <CheckBoxEmptyIcon />}@@ -88,7 +75,10 @@ function GridOptionsMenu(props: Props) {data-tid="gridPerspectiveToggleShowTags"title={t('core:showTags')}aria-label={t('core:showTags')}- onClick={toggleShowTags}+ onClick={() => {+ setSettings({ showTags: !showTags });+ saveSettings(false);+ }}><ListItemIcon>{showTags ? <CheckBoxIcon /> : <CheckBoxEmptyIcon />}@@ -100,7 +90,10 @@ function GridOptionsMenu(props: Props) {data-tid="gridPerspectiveToggleThumbnailsMode"title={t('core:toggleThumbnailModeTitle')}aria-label={t('core:toggleThumbnailMode')}- onClick={toggleThumbnailsMode}+ onClick={() => {+ setSettings({ thumbnailMode: 'cover' ? 'contain' : 'cover' });+ saveSettings(false);+ }}><ListItemIcon>{thumbnailMode === 'cover' ? (@@ -116,7 +109,10 @@ function GridOptionsMenu(props: Props) {data-tid="gridPerspectiveEntrySizeSmall"title={t('core:entrySizeSmall')}aria-label={t('core:entrySizeSmall')}- onClick={() => changeEntrySize('small')}+ onClick={() => {+ setSettings({ entrySize: 'small' });+ saveSettings(false);+ }}><ListItemIcon>{entrySize === 'small' ? (@@ -131,7 +127,10 @@ function GridOptionsMenu(props: Props) {data-tid="gridPerspectiveEntrySizeNormal"title={t('core:entrySizeNormal')}aria-label={t('core:entrySizeNormal')}- onClick={() => changeEntrySize('normal')}+ onClick={() => {+ setSettings({ entrySize: 'normal' });+ saveSettings(false);+ }}><ListItemIcon>{entrySize === 'normal' ? (@@ -146,7 +145,10 @@ function GridOptionsMenu(props: Props) {data-tid="gridPerspectiveEntrySizeBig"title={t('core:entrySizeBig')}aria-label={t('core:entrySizeBig')}- onClick={() => changeEntrySize('big')}+ onClick={() => {+ setSettings({ entrySize: 'big' });+ saveSettings(false);+ }}><ListItemIcon>{entrySize === 'big' ? <RadioCheckedIcon /> : <RadioUncheckedIcon />}@@ -158,7 +160,10 @@ function GridOptionsMenu(props: Props) {data-tid="gridPerspectiveSingleClickOpenInternally"title={t('core:singleClickOpenInternally')}aria-label={t('core:singleClickOpenInternally')}- onClick={() => changeSingleClickAction('openInternal')}+ onClick={() => {+ setSettings({ singleClickAction: 'openInternal' });+ saveSettings(false);+ }}><ListItemIcon>{singleClickAction === 'openInternal' ? (@@ -173,7 +178,10 @@ function GridOptionsMenu(props: Props) {data-tid="gridPerspectiveSingleClickOpenExternally"title={t('core:singleClickOpenExternally')}aria-label={t('core:singleClickOpenExternally')}- onClick={() => changeSingleClickAction('openExternal')}+ onClick={() => {+ setSettings({ singleClickAction: 'openExternal' });+ saveSettings(false);+ }}><ListItemIcon>{singleClickAction === 'openExternal' ? (@@ -188,7 +196,10 @@ function GridOptionsMenu(props: Props) {data-tid="gridPerspectiveSingleClickSelects"title={t('core:singleClickSelects')}aria-label={t('core:singleClickSelects')}- onClick={() => changeSingleClickAction('selects')}+ onClick={() => {+ setSettings({ singleClickAction: 'selects' });+ saveSettings(false);+ }}><ListItemIcon>{singleClickAction === 'selects' ? (diff --git a/src/renderer/perspectives/grid-perspective/components/GridPagination.tsx b/src/renderer/perspectives/grid-perspective/components/GridPagination.tsxindex 04a3a78da..7e7d2b28b 100644--- a/src/renderer/perspectives/grid-perspective/components/GridPagination.tsx+++ b/src/renderer/perspectives/grid-perspective/components/GridPagination.tsx@@ -52,20 +52,13 @@ import { useIOActionsContext } from '-/hooks/useIOActionsContext';import { useNotificationContext } from '-/hooks/useNotificationContext';import { useFsActionsContext } from '-/hooks/useFsActionsContext';import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';+import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';+import GridCellsContainer from './GridCellsContainer';interface Props {- style?: any;- // gridRef: Object;directories: Array<TS.FileSystemEntry>;- showDirectories: boolean;- showDetails: boolean;- showDescription: boolean;- showTags: boolean;desktopMode: boolean;- thumbnailMode: string;- entrySize: string;files: Array<TS.FileSystemEntry>;- // pageEntries: Array<TS.FileSystemEntry>;getCellContent: (fsEntry: TS.FileSystemEntry,selectedEntries: Array<TS.FileSystemEntry>,@@ -75,20 +68,15 @@ interface Props {handleGridCellDblClick,isLast?: boolean,) => void;- gridPageLimit: number;currentDirectoryPath: string;onContextMenu: (event: React.MouseEvent<HTMLDivElement>) => void;openRenameEntryDialog: () => void;onClick: (event: React.MouseEvent<HTMLDivElement>) => void;// eslint-disable-next-line react/no-unused-prop-types- settings; // cache only- // eslint-disable-next-line react/no-unused-prop-typesselectedEntries; // cache only- // setMetaForCurrentDir: (metaFiles: Array<any>) => void;lastBackgroundImageChange: any;lastThumbnailImageChange: any;setSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => void;- singleClickAction: string;setFileContextMenuAnchorEl: (HTMLElement) => void;setDirContextMenuAnchorEl: (HTMLElement) => void;clearSelection: () => void;@@ -98,12 +86,6 @@ function GridPagination(props: Props) {let { directories } = props;const { t } = useTranslation();const {- style,- showDirectories,- showDetails,- showDescription,- showTags,- singleClickAction,getCellContent,desktopMode,currentDirectoryPath,@@ -112,12 +94,19 @@ function GridPagination(props: Props) {lastBackgroundImageChange,setFileContextMenuAnchorEl,setDirContextMenuAnchorEl,- gridPageLimit,selectedEntries,setSelectedEntries,clearSelection,files,} = props;+ const {+ showDetails,+ showDescription,+ showDirectories,+ showTags,+ gridPageLimit,+ singleClickAction,+ } = usePerspectiveSettingsContext();const { lastSelectedEntryPath } = useSelectedEntriesContext();const { openEntry } = useOpenedEntryContext();const { moveFiles } = useIOActionsContext();@@ -352,7 +341,7 @@ function GridPagination(props: Props) {</Grid>)}</Grid>- <div style={style} data-tid="perspectiveGridFileTable">+ <GridCellsContainer>{page === 1 &&directories.map((entry, index) =>renderCell(@@ -447,7 +436,7 @@ function GridPagination(props: Props) {)}</div>)}- </div>+ </GridCellsContainer>{showPagination && (<Tooltip title={folderSummary}><Pagination@@ -500,17 +489,15 @@ const areEqual = (prevProp: Props, nextProp: Props) =>JSON.stringify(nextProp.lastThumbnailImageChange) ===JSON.stringify(prevProp.lastThumbnailImageChange) &&nextProp.currentDirectoryPath === prevProp.currentDirectoryPath &&- nextProp.showDirectories === prevProp.showDirectories &&- nextProp.showDetails === prevProp.showDetails &&- nextProp.showDescription === prevProp.showDescription &&- nextProp.showTags === prevProp.showTags &&- nextProp.thumbnailMode === prevProp.thumbnailMode &&- nextProp.entrySize === prevProp.entrySize &&- nextProp.gridPageLimit === prevProp.gridPageLimit &&+ //nextProp.showDirectories === prevProp.showDirectories &&+ //nextProp.showDetails === prevProp.showDetails &&+ //nextProp.showDescription === prevProp.showDescription &&+ //nextProp.showTags === prevProp.showTags &&+ //nextProp.gridPageLimit === prevProp.gridPageLimit &&JSON.stringify(nextProp.files) === JSON.stringify(prevProp.files) &&JSON.stringify(nextProp.directories) ===JSON.stringify(prevProp.directories) &&- JSON.stringify(nextProp.settings) === JSON.stringify(prevProp.settings) &&+ // JSON.stringify(nextProp.settings) === JSON.stringify(prevProp.settings) &&JSON.stringify(nextProp.selectedEntries) ===JSON.stringify(prevProp.selectedEntries);diff --git a/src/renderer/perspectives/grid-perspective/components/GridSettingsDialog.tsx b/src/renderer/perspectives/grid-perspective/components/GridSettingsDialog.tsxindex 28e6087a8..23e8a8c70 100644--- a/src/renderer/perspectives/grid-perspective/components/GridSettingsDialog.tsx+++ b/src/renderer/perspectives/grid-perspective/components/GridSettingsDialog.tsx@@ -47,65 +47,37 @@ import { Pro } from '-/pro';import { useTheme } from '@mui/material/styles';import { useTranslation } from 'react-i18next';import { useSortedDirContext } from '-/perspectives/grid-perspective/hooks/useSortedDirContext';-import ZoomComponent, { EntrySizes } from '-/components/ZoomComponent';+import ZoomComponent from '-/components/ZoomComponent';+import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';interface Props {open: boolean;- gridPageLimit: number;- onClose: (isDefault?: boolean) => void;- setGridPageLimit: (number) => void;- toggleShowDescription?: () => void;- toggleShowEntriesDescription?: () => void;- toggleShowDetails: () => void;- showDetails: boolean;- showDescription: boolean;- showEntriesDescription?: boolean;- toggleShowDirectories: () => void;- toggleShowTags: () => void;- showDirectories: boolean;- showTags: boolean;- toggleThumbnailsMode: () => string;- thumbnailMode: string;- changeEntrySize: (entrySize: string) => void;- entrySize: EntrySizes;- changeSingleClickAction: (actionType: string) => void;- singleClickAction: string;+ onClose: () => void;openHelpWebPage: () => void;handleSortingMenu: (event) => void;- isLocal: boolean;- resetLocalSettings: () => void;}function GridSettingsDialog(props: Props) {const { t } = useTranslation();- const { sortBy, orderBy } = useSortedDirContext();- const [ignored, forceUpdate] = useReducer((x: number) => x + 1, 0, undefined);- const thumbnailMode = useRef<string>(props.thumbnailMode);- const entrySize = useRef<EntrySizes>(props.entrySize);- const singleClickAction = useRef<string>(props.singleClickAction);-- const theme = useTheme();const {- open,- onClose,- gridPageLimit,+ showDirectories,+ showTags,showDetails,- toggleShowDetails,showDescription,showEntriesDescription,- toggleShowEntriesDescription,- toggleShowDescription,- toggleShowDirectories,- showDirectories,- toggleShowTags,- showTags,- toggleThumbnailsMode,- changeEntrySize,- changeSingleClickAction,- openHelpWebPage,- } = props;+ thumbnailMode,+ singleClickAction,+ gridPageLimit,+ haveLocalSetting,+ resetLocalSetting,+ setSettings,+ saveSettings,+ } = usePerspectiveSettingsContext();+ const { sortBy, orderBy } = useSortedDirContext();+ const [ignored, forceUpdate] = useReducer((x: number) => x + 1, 0, undefined);- let newGridPageLimit = gridPageLimit;+ const theme = useTheme();+ const { open, onClose, openHelpWebPage } = props;const handleGridPaginationLimit = (event: React.ChangeEvent<HTMLInputElement>,@@ -114,9 +86,9 @@ function GridSettingsDialog(props: Props) {const { value, name } = target;if (name === 'limit') {- newGridPageLimit = roughScale(value);+ const newGridPageLimit = roughScale(value);+ setSettings({ gridPageLimit: newGridPageLimit });}- props.setGridPageLimit(newGridPageLimit);};function roughScale(x) {@@ -137,7 +109,7 @@ function GridSettingsDialog(props: Props) {/></DialogTitle><DialogContent>- {props.isLocal && (+ {haveLocalSetting() && (<><Typographystyle={{ color: theme.palette.text.primary }}@@ -150,7 +122,8 @@ function GridSettingsDialog(props: Props) {data-tid="resetLocalSettingsTID"title={t('core:resetLocalSettings')}onClick={() => {- props.resetLocalSettings();+ resetLocalSetting();+ onClose();// forceUpdate();}}>@@ -160,14 +133,7 @@ function GridSettingsDialog(props: Props) {)}<Divider /><Box style={{ display: 'flex' }}>- <ZoomComponent- entrySize={entrySize.current}- changeEntrySize={(eSize: EntrySizes) => {- changeEntrySize(eSize);- entrySize.current = eSize;- forceUpdate();- }}- />+ <ZoomComponent preview={true} /><Typographystyle={{ color: theme.palette.text.primary, alignSelf: 'center' }}variant="body1"@@ -183,7 +149,9 @@ function GridSettingsDialog(props: Props) {<Switchdata-tid="gridPerspectiveToggleShowDirectories"defaultChecked={showDirectories}- onChange={toggleShowDirectories}+ onChange={() => {+ setSettings({ showDirectories: !showDirectories });+ }}name="checkedD"color="primary"/>@@ -196,7 +164,9 @@ function GridSettingsDialog(props: Props) {<Switchdata-tid="gridPerspectiveToggleShowTags"defaultChecked={showTags}- onChange={toggleShowTags}+ onChange={() => {+ setSettings({ showTags: !showTags });+ }}name="checkedT"color="primary"/>@@ -209,7 +179,11 @@ function GridSettingsDialog(props: Props) {<Switchdata-tid="gridPerspectiveToggleShowEntriesDescription"defaultChecked={showEntriesDescription}- onChange={toggleShowEntriesDescription}+ onChange={() => {+ setSettings({+ showEntriesDescription: !showEntriesDescription,+ });+ }}name={t('core:showHideEntriesDescription')}color="primary"/>@@ -222,20 +196,24 @@ function GridSettingsDialog(props: Props) {<Switchdata-tid="gridPerspectiveToggleShowDetails"defaultChecked={showDetails}- onChange={toggleShowDetails}+ onChange={() => {+ setSettings({ showDetails: !showDetails });+ }}name={t('core:showHideDetails')}color="primary"/>}label={t('core:showHideDetails')}/>- {toggleShowDescription && (+ {showDescription != undefined && (<FormControlLabelcontrol={<Switchdata-tid="gridPerspectiveToggleShowDescription"defaultChecked={showDescription}- onChange={toggleShowDescription}+ onChange={() => {+ setSettings({ showDescription: !showDescription });+ }}name={t('core:showHideDescription')}color="primary"/>@@ -250,12 +228,14 @@ function GridSettingsDialog(props: Props) {title={t('core:toggleThumbnailModeTitle')}aria-label={t('core:toggleThumbnailMode')}onClick={() => {- thumbnailMode.current = toggleThumbnailsMode();+ setSettings({+ thumbnailMode: thumbnailMode === 'cover' ? 'contain' : 'cover',+ });forceUpdate();}}><ListItemIcon>- {thumbnailMode.current === 'cover' ? (+ {thumbnailMode === 'cover' ? (<ThumbnailCoverIcon />) : (<ThumbnailContainIcon />@@ -345,13 +325,12 @@ function GridSettingsDialog(props: Props) {title={t('core:singleClickOpenInternally')}aria-label={t('core:singleClickOpenInternally')}onClick={() => {- changeSingleClickAction('openInternal');- singleClickAction.current = 'openInternal';+ setSettings({ singleClickAction: 'openInternal' });forceUpdate();}}><ListItemIcon>- {singleClickAction.current === 'openInternal' ? (+ {singleClickAction === 'openInternal' ? (<RadioCheckedIcon />) : (<RadioUncheckedIcon />@@ -364,13 +343,12 @@ function GridSettingsDialog(props: Props) {title={t('core:singleClickOpenExternally')}aria-label={t('core:singleClickOpenExternally')}onClick={() => {- changeSingleClickAction('openExternal');- singleClickAction.current = 'openExternal';+ setSettings({ singleClickAction: 'openExternal' });forceUpdate();}}><ListItemIcon>- {singleClickAction.current === 'openExternal' ? (+ {singleClickAction === 'openExternal' ? (<RadioCheckedIcon />) : (<RadioUncheckedIcon />@@ -383,13 +361,12 @@ function GridSettingsDialog(props: Props) {title={t('core:singleClickSelects')}aria-label={t('core:singleClickSelects')}onClick={() => {- changeSingleClickAction('selects');- singleClickAction.current = 'selects';+ setSettings({ singleClickAction: 'selects' });forceUpdate();}}><ListItemIcon>- {singleClickAction.current === 'selects' ? (+ {singleClickAction === 'selects' ? (<RadioCheckedIcon />) : (<RadioUncheckedIcon />@@ -425,7 +402,8 @@ function GridSettingsDialog(props: Props) {<Buttondata-tid="defaultSettings"onClick={() => {- onClose(true);+ saveSettings(true);+ onClose();}}color="primary">@@ -435,7 +413,8 @@ function GridSettingsDialog(props: Props) {<Buttondata-tid="directorySettings"onClick={() => {- onClose(false);+ saveSettings(false);+ onClose();}}color="primary">diff --git a/src/renderer/perspectives/grid-perspective/components/MainContainer.tsx b/src/renderer/perspectives/grid-perspective/components/MainContainer.tsxindex d50546e83..c517fcc01 100644--- a/src/renderer/perspectives/grid-perspective/components/MainContainer.tsx+++ b/src/renderer/perspectives/grid-perspective/components/MainContainer.tsx@@ -16,7 +16,7 @@**/-import React, { useEffect, useReducer, useRef, useState } from 'react';+import React, { useEffect, useRef, useState } from 'react';import { useSelector, useDispatch } from 'react-redux';import { GlobalHotKeys } from 'react-hotkeys';import { isObj } from '@tagspaces/tagspaces-common/misc';@@ -31,7 +31,7 @@ import TagDropContainer from '-/components/TagDropContainer';import { actions as AppActions, AppDispatch } from '-/reducers/app';import GridCell, {calculateEntryHeight,- calculateEntryWitdth,+ calculateEntryWidth,} from './GridCell';import MainToolbar from '-/perspectives/grid-perspective/components/MainToolbar';import SortingMenu from '-/perspectives/grid-perspective/components/SortingMenu';@@ -40,49 +40,30 @@ import PlatformIO from '-/services/platform-facade';import GridPagination from '-/perspectives/grid-perspective/components/GridPagination';import GridSettingsDialog from '-/perspectives/grid-perspective/components/GridSettingsDialog';import AddTagToTagGroupDialog from '-/components/dialogs/AddTagToTagGroupDialog';-import { EntrySizes } from '-/components/ZoomComponent';import { TS } from '-/tagspaces.namespace';import { Pro } from '-/pro';import Links from 'assets/links';import { defaultSettings } from '../index';-import { PerspectiveIDs } from '-/perspectives';import { fileOperationsEnabled } from '-/perspectives/common/main-container';-import useFirstRender from '-/utils/useFirstRender';import { openURLExternally } from '-/services/utils-io';import { useSortedDirContext } from '-/perspectives/grid-perspective/hooks/useSortedDirContext';import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';import { useFsActionsContext } from '-/hooks/useFsActionsContext';+import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';+import { GridCellsStyleContextProvider } from '-/perspectives/grid-perspective/hooks/GridCellsStyleProvider';interface Props {openRenameEntryDialog: () => void;}-function getSettings(directoryMeta: TS.FileSystemEntryMeta): TS.FolderSettings {- if (- Pro &&- directoryMeta &&- directoryMeta.perspectiveSettings &&- directoryMeta.perspectiveSettings[PerspectiveIDs.GRID]- ) {- return directoryMeta.perspectiveSettings[PerspectiveIDs.GRID];- } else {- // loading settings for not Pro- return JSON.parse(localStorage.getItem(defaultSettings.settingsKey));- }-}-function GridPerspective(props: Props) {const { openRenameEntryDialog } = props;const { openEntry, openPrevFile, openNextFile } = useOpenedEntryContext();- const {- directoryMeta,- openDirectory,- currentDirectoryPath,- setDirectoryMeta,- } = useDirectoryContentContext();+ const { entrySize, showDirectories } = usePerspectiveSettingsContext();+ const { openDirectory, currentDirectoryPath } = useDirectoryContentContext();const { openFileNatively, duplicateFile } = useFsActionsContext();const dispatch: AppDispatch = useDispatch();@@ -95,19 +76,12 @@ function GridPerspective(props: Props) {// Create functions that dispatch actionsconst handleSetSelectedEntries = (entries: Array<TS.FileSystemEntry>) => {- const selected = showDirectories.current+ const selected = showDirectories? entries: entries.filter((entry) => entry.isFile);setSelectedEntries(selected);};- const isLocal =- Pro &&- directoryMeta &&- directoryMeta.perspectiveSettings &&- directoryMeta.perspectiveSettings[PerspectiveIDs.GRID];- const settings = getSettings(directoryMeta);-const ShareFilesDialog = Pro && Pro.UI ? Pro.UI.ShareFilesDialog : false;const [mouseX, setMouseX] = useState<number>(undefined);@@ -128,46 +102,6 @@ function GridPerspective(props: Props) {useState<null | HTMLElement>(null);const [isAddTagDialogOpened, setIsAddTagDialogOpened] =useState<TS.Tag>(undefined);- const singleClickAction = useRef<string>(- settings && settings.singleClickAction- ? settings.singleClickAction- : defaultSettings.singleClickAction,- );- const entrySize = useRef<EntrySizes>(- settings && settings.entrySize- ? settings.entrySize- : defaultSettings.entrySize,- );- const thumbnailMode = useRef<string>(- settings && settings.thumbnailMode- ? settings.thumbnailMode- : defaultSettings.thumbnailMode,- );- const showDirectories = useRef<boolean>(- settings && typeof settings.showDirectories !== 'undefined'- ? settings.showDirectories- : defaultSettings.showDirectories,- );- const showDetails = useRef<boolean>(- settings && typeof settings.showDetails !== 'undefined'- ? settings.showDetails- : defaultSettings.showDetails,- );- const showDescription = useRef<boolean>(- settings && typeof settings.showDescription !== 'undefined'- ? settings.showDescription- : defaultSettings.showDescription,- );- const showEntriesDescription = useRef<boolean>(- settings && typeof settings.showEntriesDescription !== 'undefined'- ? settings.showEntriesDescription- : defaultSettings.showEntriesDescription,- );- const showTags = useRef<boolean>(- settings && typeof settings.showTags !== 'undefined'- ? settings.showTags- : defaultSettings.showTags,- );const [isMoveCopyFilesDialogOpened, setIsMoveCopyFilesDialogOpened] =useState<boolean>(false);const [isShareFilesDialogOpened, setIsShareFilesDialogOpened] =@@ -176,15 +110,6 @@ function GridPerspective(props: Props) {useState<boolean>(false);const [isGridSettingsDialogOpened, setIsGridSettingsDialogOpened] =useState<boolean>(false);- const gridPageLimit = useRef<number>(- settings && settings.gridPageLimit- ? settings.gridPageLimit- : defaultSettings.gridPageLimit,- );- // true: save in default settings; false: save per folder settings; undefined - dont save changes- const isDefaultSetting = useRef<boolean>(undefined);- const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);- const firstRender = useFirstRender();useEffect(() => {if (selectedEntries.length === 1) {@@ -192,108 +117,6 @@ function GridPerspective(props: Props) {}}, [selectedEntries]);- useEffect(() => {- if (!firstRender) {- const perspectiveSettings = getSettings(directoryMeta);- showDirectories.current =- perspectiveSettings && perspectiveSettings.showDirectories !== undefined- ? perspectiveSettings.showDirectories- : defaultSettings.showDirectories;- showDescription.current =- perspectiveSettings && perspectiveSettings.showDescription !== undefined- ? perspectiveSettings.showDescription- : defaultSettings.showDescription;- showEntriesDescription.current =- perspectiveSettings &&- perspectiveSettings.showEntriesDescription !== undefined- ? perspectiveSettings.showEntriesDescription- : defaultSettings.showEntriesDescription;- showDetails.current =- perspectiveSettings && perspectiveSettings.showDetails !== undefined- ? perspectiveSettings.showDetails- : defaultSettings.showDetails;- showTags.current =- perspectiveSettings && perspectiveSettings.showTags !== undefined- ? perspectiveSettings.showTags- : defaultSettings.showTags;- setOrderBy(- perspectiveSettings && perspectiveSettings.orderBy !== undefined- ? perspectiveSettings.orderBy- : defaultSettings.orderBy,- );- setSortBy(- perspectiveSettings && perspectiveSettings.sortBy !== undefined- ? perspectiveSettings.sortBy- : defaultSettings.sortBy,- );- singleClickAction.current =- perspectiveSettings &&- perspectiveSettings.singleClickAction !== undefined- ? perspectiveSettings.singleClickAction- : defaultSettings.singleClickAction;- entrySize.current =- perspectiveSettings && perspectiveSettings.entrySize !== undefined- ? perspectiveSettings.entrySize- : defaultSettings.entrySize;- thumbnailMode.current =- perspectiveSettings && perspectiveSettings.thumbnailMode !== undefined- ? perspectiveSettings.thumbnailMode- : defaultSettings.thumbnailMode;- gridPageLimit.current =- perspectiveSettings && perspectiveSettings.gridPageLimit !== undefined- ? perspectiveSettings.gridPageLimit- : defaultSettings.gridPageLimit;- forceUpdate();- }- }, [directoryMeta]);-- useEffect(() => {- if (!firstRender && isDefaultSetting.current !== undefined) {- const perspectiveSettings = {- showDirectories: showDirectories.current,- showDescription: showDescription.current,- showEntriesDescription: showEntriesDescription.current,- showDetails: showDetails.current,- showTags: showTags.current,- orderBy: orderBy,- sortBy: sortBy,- singleClickAction: singleClickAction.current,- entrySize: entrySize.current,- thumbnailMode: thumbnailMode.current,- gridPageLimit: gridPageLimit.current,- };- if (Pro && !isDefaultSetting.current) {- Pro.MetaOperations.savePerspectiveSettings(- currentDirectoryPath,- PerspectiveIDs.GRID,- perspectiveSettings,- ).then((fsEntryMeta: TS.FileSystemEntryMeta) => {- setDirectoryMeta(fsEntryMeta);- });- } else {- localStorage.setItem(- defaultSettings.settingsKey,- JSON.stringify(perspectiveSettings),- );- forceUpdate();- }- isDefaultSetting.current = undefined;- }- }, [- isDefaultSetting.current,- showDirectories.current,- showDescription.current,- showEntriesDescription.current,- showDetails.current,- showTags.current,- orderBy,- sortBy,- singleClickAction.current,- entrySize.current,- thumbnailMode.current,- gridPageLimit.current,- ]);-const makeFirstSelectedEntryVisible = () => {if (selectedEntries && selectedEntries.length > 0) {try {@@ -312,11 +135,6 @@ function GridPerspective(props: Props) {}};- const handleGridPageLimit = (limit: number) => {- gridPageLimit.current = limit;- // forceUpdate();- };-const handleSortBy = (handleSort) => {if (sortBy !== handleSort) {setSortBy(handleSort);@@ -355,53 +173,6 @@ function GridPerspective(props: Props) {}};- const toggleShowDirectories = () => {- closeOptionsMenu();- showDirectories.current = !showDirectories.current;- // forceUpdate();- };-- const toggleShowDetails = () => {- closeOptionsMenu();- showDetails.current = !showDetails.current;- };-- const toggleShowDescription = () => {- closeOptionsMenu();- showDescription.current = !showDescription.current;- };-- const toggleShowEntriesDescription = () => {- closeOptionsMenu();- showEntriesDescription.current = !showEntriesDescription.current;- };-- const toggleShowTags = () => {- closeOptionsMenu();- showTags.current = !showTags.current;- // forceUpdate();- };-- const toggleThumbnailsMode = () => {- closeOptionsMenu();- const thumbMode = thumbnailMode.current === 'cover' ? 'contain' : 'cover';- thumbnailMode.current = thumbMode;- // forceUpdate();- return thumbMode;- };-- const changeEntrySize = (size) => {- closeOptionsMenu();- entrySize.current = size;- // forceUpdate();- };-- const changeSingleClickAction = (singleClick) => {- closeOptionsMenu();- singleClickAction.current = singleClick;- // forceUpdate();- };-const openHelpWebPage = () => {closeOptionsMenu();openURLExternally(Links.documentationLinks.defaultPerspective, true);@@ -580,15 +351,11 @@ function GridPerspective(props: Props) {<GridCellselected={selected}fsEntry={fsEntry}- showEntriesDescription={showEntriesDescription.current}- entrySize={entrySize.current}isLast={isLast}- thumbnailMode={thumbnailMode.current}selectEntry={selectEntry}selectionMode={selectionMode}deselectEntry={deselectEntry}handleTagMenu={handleTagMenu}- showTags={showTags.current}handleGridContextMenu={(event: React.MouseEvent<HTMLDivElement>,fsEntry: TS.FileSystemEntry,@@ -618,8 +385,6 @@ function GridPerspective(props: Props) {openMoveCopyFilesDialog={openMoveCopyFilesDialog}handleSortingMenu={handleSortingMenu}handleExportCsvMenu={handleExportCsvMenu}- changeEntrySize={changeEntrySize}- entrySize={entrySize.current}openSettings={openSettings}openShareFilesDialog={PlatformIO.haveObjectStoreSupport() ? openShareFilesDialog : undefined@@ -630,45 +395,23 @@ function GridPerspective(props: Props) {handlers={keyBindingHandlers}allowChanges={true}>- <GridPagination- gridPageLimit={gridPageLimit.current}- style={{- margin: 0,- display: 'grid',- gridGap: '5px 5px',- padding: 5,- paddingBottom: 70,- gridTemplateColumns:- 'repeat(auto-fit,minmax(' +- calculateEntryWitdth(entrySize.current) +- 'px,1fr))',- gridTemplateRows:- 'repeat(auto-fit,minmax(' +- calculateEntryHeight(entrySize.current) +- 'px,1fr))',- }}- directories={sortedDirectories}- showDetails={showDetails.current}- showDescription={showDescription.current}- showDirectories={showDirectories.current}- desktopMode={desktopMode}- openRenameEntryDialog={openRenameEntryDialog}- showTags={showTags.current}- thumbnailMode={thumbnailMode.current}- entrySize={entrySize.current}- files={sortedFiles}- getCellContent={getCellContent}- currentDirectoryPath={currentDirectoryPath}- onClick={onClick}- onContextMenu={onContextMenu}- settings={settings}- selectedEntries={selectedEntries}- setSelectedEntries={handleSetSelectedEntries}- singleClickAction={singleClickAction.current}- setFileContextMenuAnchorEl={setFileContextMenuAnchorEl}- setDirContextMenuAnchorEl={setDirContextMenuAnchorEl}- clearSelection={clearSelection}- />+ <GridCellsStyleContextProvider>+ <GridPagination+ directories={sortedDirectories}+ desktopMode={desktopMode}+ openRenameEntryDialog={openRenameEntryDialog}+ files={sortedFiles}+ getCellContent={getCellContent}+ currentDirectoryPath={currentDirectoryPath}+ onClick={onClick}+ onContextMenu={onContextMenu}+ selectedEntries={selectedEntries}+ setSelectedEntries={handleSetSelectedEntries}+ setFileContextMenuAnchorEl={setFileContextMenuAnchorEl}+ setDirContextMenuAnchorEl={setDirContextMenuAnchorEl}+ clearSelection={clearSelection}+ />+ </GridCellsStyleContextProvider></GlobalHotKeys>{isAddRemoveTagsDialogOpened && (<AddRemoveTagsDialog@@ -686,40 +429,11 @@ function GridPerspective(props: Props) {{isGridSettingsDialogOpened && (<GridSettingsDialogopen={isGridSettingsDialogOpened}- onClose={(isDefault) => {+ onClose={() => {setIsGridSettingsDialogOpened(false);- isDefaultSetting.current = isDefault;}}- setGridPageLimit={handleGridPageLimit}- gridPageLimit={gridPageLimit.current}- toggleShowDirectories={toggleShowDirectories}- toggleShowTags={toggleShowTags}- toggleShowDetails={toggleShowDetails}- toggleShowDescription={toggleShowDescription}- toggleShowEntriesDescription={toggleShowEntriesDescription}- showDetails={showDetails.current}- showDescription={showDescription.current}- showEntriesDescription={showEntriesDescription.current}- showDirectories={showDirectories.current}- showTags={showTags.current}- toggleThumbnailsMode={toggleThumbnailsMode}- thumbnailMode={thumbnailMode.current}- changeEntrySize={changeEntrySize}- entrySize={entrySize.current}- changeSingleClickAction={changeSingleClickAction}- singleClickAction={singleClickAction.current}openHelpWebPage={openHelpWebPage}handleSortingMenu={handleSortingMenu}- isLocal={isLocal}- resetLocalSettings={() => {- Pro.MetaOperations.savePerspectiveSettings(- currentDirectoryPath,- PerspectiveIDs.GRID,- ).then((fsEntryMeta: TS.FileSystemEntryMeta) => {- setDirectoryMeta(fsEntryMeta);- setIsGridSettingsDialogOpened(false);- });- }}/>)}{isMoveCopyFilesDialogOpened && (@@ -792,16 +506,6 @@ function GridPerspective(props: Props) {open={Boolean(optionsContextMenuAnchorEl)}onClose={closeOptionsMenu}anchorEl={optionsContextMenuAnchorEl}- toggleShowDirectories={toggleShowDirectories}- showDirectories={showDirectories.current}- toggleShowTags={toggleShowTags}- showTags={showTags.current}- toggleThumbnailsMode={toggleThumbnailsMode}- thumbnailMode={thumbnailMode.current}- entrySize={entrySize.current}- changeSingleClickAction={changeSingleClickAction}- singleClickAction={singleClickAction.current}- changeEntrySize={changeEntrySize}openHelpWebPage={openHelpWebPage}openSettings={openSettings}/>diff --git a/src/renderer/perspectives/grid-perspective/components/MainToolbar.tsx b/src/renderer/perspectives/grid-perspective/components/MainToolbar.tsxindex af2f9ceb2..b2e95d80d 100644--- a/src/renderer/perspectives/grid-perspective/components/MainToolbar.tsx+++ b/src/renderer/perspectives/grid-perspective/components/MainToolbar.tsx@@ -37,7 +37,7 @@ import {import AppConfig from '-/AppConfig';import { Pro } from '-/pro';import { ProTooltip } from '-/components/HelperComponents';-import ZoomSlider, { EntrySizes } from '-/components/ZoomComponent';+import ZoomComponent from '-/components/ZoomComponent';import { getKeyBindingObject } from '-/reducers/settings';import { actions as AppActions, AppDispatch } from '-/reducers/app';import { useTranslation } from 'react-i18next';@@ -52,8 +52,6 @@ interface Props {openAddRemoveTagsDialog: () => void;openMoveCopyFilesDialog: () => void;handleSortingMenu: (event: Object) => void;- changeEntrySize: (entrySize: EntrySizes) => void;- entrySize: EntrySizes;handleExportCsvMenu: () => void;openSettings: () => void;openShareFilesDialog?: () => void;@@ -69,8 +67,6 @@ function MainToolbar(props: Props) {handleExportCsvMenu,openSettings,openShareFilesDialog,- entrySize,- changeEntrySize,} = props;const { t } = useTranslation();@@ -245,7 +241,7 @@ function MainToolbar(props: Props) {)}<Divider flexItem orientation="vertical" sx={{ mx: 0.5, my: 1 }} /><Box sx={{ display: { xs: 'none', sm: 'flex' } }}>- <ZoomSlider entrySize={entrySize} changeEntrySize={changeEntrySize} />+ <ZoomComponent preview={false} /><Divider flexItem orientation="vertical" sx={{ mx: 0.5, my: 1 }} /></Box><Box sx={{ flexGrow: 1 }} />diff --git a/src/renderer/perspectives/grid-perspective/hooks/GridCellsStyleProvider.tsx b/src/renderer/perspectives/grid-perspective/hooks/GridCellsStyleProvider.tsxnew file mode 100644index 000000000..e1b534cec--- /dev/null+++ b/src/renderer/perspectives/grid-perspective/hooks/GridCellsStyleProvider.tsx@@ -0,0 +1,68 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import React, { createContext, CSSProperties, useMemo } from 'react';+import {+ calculateEntryHeight,+ calculateEntryWidth,+} from '-/perspectives/grid-perspective/components/GridCell';+import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';++type GridCellsStyleData = {+ cellsStyle: CSSProperties;+};++export const GridCellsStyleContext = createContext<GridCellsStyleData>({+ cellsStyle: undefined,+});++export type GridCellsStyleContextProviderProps = {+ children: React.ReactNode;+};++export const GridCellsStyleContextProvider = ({+ children,+}: GridCellsStyleContextProviderProps) => {+ const { entrySize } = usePerspectiveSettingsContext();++ const context = useMemo(() => {+ return {+ cellsStyle: {+ margin: 0,+ display: 'grid',+ gridGap: '5px 5px',+ padding: 5,+ paddingBottom: 70,+ gridTemplateColumns:+ 'repeat(auto-fit,minmax(' ++ calculateEntryWidth(entrySize) ++ 'px,1fr))',+ gridTemplateRows:+ 'repeat(auto-fit,minmax(' ++ calculateEntryHeight(entrySize) ++ 'px,1fr))',+ },+ };+ }, [entrySize]);++ return (+ <GridCellsStyleContext.Provider value={context}>+ {children}+ </GridCellsStyleContext.Provider>+ );+};diff --git a/src/renderer/perspectives/grid-perspective/hooks/useGridCellsStyleContext.tsx b/src/renderer/perspectives/grid-perspective/hooks/useGridCellsStyleContext.tsxnew file mode 100644index 000000000..b8ee10f91--- /dev/null+++ b/src/renderer/perspectives/grid-perspective/hooks/useGridCellsStyleContext.tsx@@ -0,0 +1,5 @@+import { useContext } from 'react';++import { GridCellsStyleContext } from './GridCellsStyleProvider';++export const useGridCellsStyleContext = () => useContext(GridCellsStyleContext);diff --git a/src/renderer/perspectives/grid-perspective/index.tsx b/src/renderer/perspectives/grid-perspective/index.tsxindex 863e0a63b..dac483375 100644--- a/src/renderer/perspectives/grid-perspective/index.tsx+++ b/src/renderer/perspectives/grid-perspective/index.tsx@@ -1,6 +1,5 @@import React from 'react';export { default } from './components/MainContainer';-import { EntrySizes } from '-/components/ZoomComponent';// interface PerspectiveSettings {// settingsKey: string;@@ -21,7 +20,7 @@ export const defaultSettings = {sortBy: 'byName',layoutType: 'grid', // list gridsingleClickAction: 'openInternal', // openInternal openExternal- entrySize: EntrySizes.small,+ entrySize: 'small',thumbnailMode: 'contain', // cover containshowDirectories: true,showDetails: true,diff --git a/src/renderer/perspectives/list/components/ListCellsContainer.tsx b/src/renderer/perspectives/list/components/ListCellsContainer.tsxnew file mode 100644index 000000000..51eed9b23--- /dev/null+++ b/src/renderer/perspectives/list/components/ListCellsContainer.tsx@@ -0,0 +1,36 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import React from 'react';+import { useListCellsStyleContext } from '../hooks/useListCellsStyleContext';++export type ListCellsContainerProps = {+ children: React.ReactNode;+};++export const ListCellsContainer = ({ children }: ListCellsContainerProps) => {+ const { cellsStyle } = useListCellsStyleContext();++ return (+ <div style={cellsStyle} data-tid="perspectiveGridFileTable">+ {children}+ </div>+ );+};++export default ListCellsContainer;diff --git a/src/renderer/perspectives/list/components/MainContainer.tsx b/src/renderer/perspectives/list/components/MainContainer.tsxindex 52bdc4a36..4105137a4 100644--- a/src/renderer/perspectives/list/components/MainContainer.tsx+++ b/src/renderer/perspectives/list/components/MainContainer.tsx@@ -16,7 +16,7 @@**/-import React, { useEffect, useReducer, useRef, useState } from 'react';+import React, { useEffect, useRef, useState } from 'react';import { useSelector, useDispatch } from 'react-redux';import { GlobalHotKeys } from 'react-hotkeys';import { isObj } from '@tagspaces/tagspaces-common/misc';@@ -30,7 +30,6 @@ import MoveCopyFilesDialog from '-/components/dialogs/MoveCopyFilesDialog';import TagDropContainer from '-/components/TagDropContainer';import { actions as AppActions, AppDispatch } from '-/reducers/app';import RowCell from '-/perspectives/list/components/RowCell';-import { EntrySizes } from '-/components/ZoomComponent';import MainToolbar from '-/perspectives/grid-perspective/components/MainToolbar';import SortingMenu from '-/perspectives/grid-perspective/components/SortingMenu';import GridOptionsMenu from '-/perspectives/grid-perspective/components/GridOptionsMenu';@@ -42,44 +41,26 @@ import { TS } from '-/tagspaces.namespace';import { Pro } from '-/pro';import Links from 'assets/links';import { defaultSettings } from '../index';-import { PerspectiveIDs } from '-/perspectives';import { fileOperationsEnabled } from '-/perspectives/common/main-container';-import useFirstRender from '-/utils/useFirstRender';import { openURLExternally } from '-/services/utils-io';import { useSortedDirContext } from '-/perspectives/grid-perspective/hooks/useSortedDirContext';import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';import { useFsActionsContext } from '-/hooks/useFsActionsContext';+import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';+import { ListCellsStyleContextProvider } from '../hooks/ListCellsStyleProvider';interface Props {openRenameEntryDialog: () => void;}-function getSettings(directoryMeta: TS.FileSystemEntryMeta): TS.FolderSettings {- if (- Pro &&- directoryMeta &&- directoryMeta.perspectiveSettings &&- directoryMeta.perspectiveSettings[PerspectiveIDs.LIST]- ) {- return directoryMeta.perspectiveSettings[PerspectiveIDs.LIST];- } else {- // loading settings for not Pro- return JSON.parse(localStorage.getItem(defaultSettings.settingsKey));- }-}-function ListPerspective(props: Props) {const { openRenameEntryDialog } = props;const { openEntry, openPrevFile, openNextFile } = useOpenedEntryContext();- const {- directoryMeta,- openDirectory,- currentDirectoryPath,- setDirectoryMeta,- } = useDirectoryContentContext();+ const { entrySize, showDirectories } = usePerspectiveSettingsContext();+ const { openDirectory, currentDirectoryPath } = useDirectoryContentContext();const { openFileNatively, duplicateFile } = useFsActionsContext();const dispatch: AppDispatch = useDispatch();@@ -89,26 +70,15 @@ function ListPerspective(props: Props) {const { selectedEntries, setSelectedEntries, lastSelectedEntryPath } =useSelectedEntriesContext();const keyBindings = useSelector(getKeyBindingObject);- //const searchFilter: string = useSelector(getSearchFilter);- /*const editedEntryPaths: Array<TS.EditedEntryPath> = useSelector(- getEditedEntryPaths- );*/// Create functions that dispatch actionsconst handleSetSelectedEntries = (entries: Array<TS.FileSystemEntry>) => {- const selected = showDirectories.current+ const selected = showDirectories? entries: entries.filter((entry) => entry.isFile);setSelectedEntries(selected);};- const isLocal =- Pro &&- directoryMeta &&- directoryMeta.perspectiveSettings &&- directoryMeta.perspectiveSettings[PerspectiveIDs.LIST];- const settings = getSettings(directoryMeta);-const ShareFilesDialog = Pro && Pro.UI ? Pro.UI.ShareFilesDialog : false;const [mouseX, setMouseX] = useState<number>(undefined);@@ -129,54 +99,6 @@ function ListPerspective(props: Props) {useState<null | HTMLElement>(null);const [isAddTagDialogOpened, setIsAddTagDialogOpened] =useState<TS.Tag>(undefined);- /*const sortBy = useRef<string>(- settings && settings.sortBy ? settings.sortBy : defaultSettings.sortBy- );- const orderBy = useRef<null | boolean>(- settings && typeof settings.orderBy !== 'undefined'- ? settings.orderBy- : defaultSettings.orderBy- );*/- const singleClickAction = useRef<string>(- settings && settings.singleClickAction- ? settings.singleClickAction- : defaultSettings.singleClickAction,- );- const entrySize = useRef<EntrySizes>(- settings && settings.entrySize- ? settings.entrySize- : defaultSettings.entrySize,- );- const thumbnailMode = useRef<string>(- settings && settings.thumbnailMode- ? settings.thumbnailMode- : defaultSettings.thumbnailMode,- );- const showDirectories = useRef<boolean>(- settings && typeof settings.showDirectories !== 'undefined'- ? settings.showDirectories- : defaultSettings.showDirectories,- );- const showDetails = useRef<boolean>(- settings && typeof settings.showDetails !== 'undefined'- ? settings.showDetails- : defaultSettings.showDetails,- );- const showDescription = useRef<boolean>(- settings && typeof settings.showDescription !== 'undefined'- ? settings.showDescription- : defaultSettings.showDescription,- );- const showEntriesDescription = useRef<boolean>(- settings && typeof settings.showEntriesDescription !== 'undefined'- ? settings.showEntriesDescription- : defaultSettings.showEntriesDescription,- );- const showTags = useRef<boolean>(- settings && typeof settings.showTags !== 'undefined'- ? settings.showTags- : defaultSettings.showTags,- );const [isMoveCopyFilesDialogOpened, setIsMoveCopyFilesDialogOpened] =useState<boolean>(false);const [isShareFilesDialogOpened, setIsShareFilesDialogOpened] =@@ -185,15 +107,6 @@ function ListPerspective(props: Props) {useState<boolean>(false);const [isGridSettingsDialogOpened, setIsGridSettingsDialogOpened] =useState<boolean>(false);- const gridPageLimit = useRef<number>(- settings && settings.gridPageLimit- ? settings.gridPageLimit- : defaultSettings.gridPageLimit,- );- // true: save in default settings; false: save per folder settings; undefined - dont save changes- const isDefaultSetting = useRef<boolean>(undefined);- const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);- const firstRender = useFirstRender();useEffect(() => {if (selectedEntries.length === 1) {@@ -201,108 +114,6 @@ function ListPerspective(props: Props) {}}, [selectedEntries]);- useEffect(() => {- if (!firstRender) {- const perspectiveSettings = getSettings(directoryMeta);- showDirectories.current =- perspectiveSettings && perspectiveSettings.showDirectories !== undefined- ? perspectiveSettings.showDirectories- : defaultSettings.showDirectories;- showDescription.current =- perspectiveSettings && perspectiveSettings.showDescription !== undefined- ? perspectiveSettings.showDescription- : defaultSettings.showDescription;- showEntriesDescription.current =- perspectiveSettings &&- perspectiveSettings.showEntriesDescription !== undefined- ? perspectiveSettings.showEntriesDescription- : defaultSettings.showEntriesDescription;- showDetails.current =- perspectiveSettings && perspectiveSettings.showDetails !== undefined- ? perspectiveSettings.showDetails- : defaultSettings.showDetails;- showTags.current =- perspectiveSettings && perspectiveSettings.showTags !== undefined- ? perspectiveSettings.showTags- : defaultSettings.showTags;- setOrderBy(- perspectiveSettings && perspectiveSettings.orderBy !== undefined- ? perspectiveSettings.orderBy- : defaultSettings.orderBy,- );- setSortBy(- perspectiveSettings && perspectiveSettings.sortBy !== undefined- ? perspectiveSettings.sortBy- : defaultSettings.sortBy,- );- singleClickAction.current =- perspectiveSettings &&- perspectiveSettings.singleClickAction !== undefined- ? perspectiveSettings.singleClickAction- : defaultSettings.singleClickAction;- entrySize.current =- perspectiveSettings && perspectiveSettings.entrySize !== undefined- ? perspectiveSettings.entrySize- : defaultSettings.entrySize;- thumbnailMode.current =- perspectiveSettings && perspectiveSettings.thumbnailMode !== undefined- ? perspectiveSettings.thumbnailMode- : defaultSettings.thumbnailMode;- gridPageLimit.current =- perspectiveSettings && perspectiveSettings.gridPageLimit !== undefined- ? perspectiveSettings.gridPageLimit- : defaultSettings.gridPageLimit;- forceUpdate();- }- }, [directoryMeta]);-- useEffect(() => {- if (!firstRender && isDefaultSetting.current !== undefined) {- const perspectiveSettings = {- showDirectories: showDirectories.current,- showDescription: showDescription.current,- showEntriesDescription: showEntriesDescription.current,- showDetails: showDetails.current,- showTags: showTags.current,- orderBy: orderBy,- sortBy: sortBy,- singleClickAction: singleClickAction.current,- entrySize: entrySize.current,- thumbnailMode: thumbnailMode.current,- gridPageLimit: gridPageLimit.current,- };- if (Pro && !isDefaultSetting.current) {- Pro.MetaOperations.savePerspectiveSettings(- currentDirectoryPath,- PerspectiveIDs.LIST,- perspectiveSettings,- ).then((fsEntryMeta: TS.FileSystemEntryMeta) => {- setDirectoryMeta(fsEntryMeta);- });- } else {- localStorage.setItem(- defaultSettings.settingsKey,- JSON.stringify(perspectiveSettings),- );- forceUpdate();- }- isDefaultSetting.current = undefined;- }- }, [- isDefaultSetting.current,- showDirectories.current,- showDescription.current,- showEntriesDescription.current,- showDetails.current,- showTags.current,- orderBy,- sortBy,- singleClickAction.current,- entrySize.current,- thumbnailMode.current,- gridPageLimit.current,- ]);-const makeFirstSelectedEntryVisible = () => {if (selectedEntries && selectedEntries.length > 0) {try {@@ -321,11 +132,6 @@ function ListPerspective(props: Props) {}};- const handleGridPageLimit = (limit: number) => {- gridPageLimit.current = limit;- // forceUpdate();- };-const handleSortBy = (handleSort) => {if (sortBy !== handleSort) {setSortBy(handleSort);@@ -364,56 +170,9 @@ function ListPerspective(props: Props) {}};- const toggleShowDirectories = () => {- closeOptionsMenu();- showDirectories.current = !showDirectories.current;- // forceUpdate();- };-- const toggleShowDetails = () => {- closeOptionsMenu();- showDetails.current = !showDetails.current;- };-- const toggleShowDescription = () => {- closeOptionsMenu();- showDescription.current = !showDescription.current;- };-- const toggleShowEntriesDescription = () => {- closeOptionsMenu();- showEntriesDescription.current = !showEntriesDescription.current;- };-- const toggleShowTags = () => {- closeOptionsMenu();- showTags.current = !showTags.current;- // forceUpdate();- };-- const toggleThumbnailsMode = () => {- closeOptionsMenu();- const thumbMode = thumbnailMode.current === 'cover' ? 'contain' : 'cover';- thumbnailMode.current = thumbMode;- // forceUpdate();- return thumbMode;- };-- const changeEntrySize = (size) => {- closeOptionsMenu();- entrySize.current = size;- // forceUpdate();- };-- const changeSingleClickAction = (singleClick) => {- closeOptionsMenu();- singleClickAction.current = singleClick;- // forceUpdate();- };-const openHelpWebPage = () => {closeOptionsMenu();- openURLExternally(Links.documentationLinks.defaultPerspective);+ openURLExternally(Links.documentationLinks.defaultPerspective, true);};const openSettings = () => {@@ -548,15 +307,6 @@ function ListPerspective(props: Props) {const sortedDirectories = sortedDirContent.filter((entry) => !entry.isFile);const sortedFiles = sortedDirContent.filter((entry) => entry.isFile);- let entryWidth = 200;- if (entrySize.current === 'small') {- entryWidth = 150;- } else if (entrySize.current === 'normal') {- entryWidth = 200;- } else if (entrySize.current === 'big') {- entryWidth = 300;- }-const getCellContent = (fsEntry: TS.FileSystemEntry,selectedEntries: Array<TS.FileSystemEntry>,@@ -588,7 +338,6 @@ function ListPerspective(props: Props) {};const selectionMode = selectedEntries.length > 0;-return (<TagDropContainerentryPath={fsEntry.path} // TODO remove entryPath it is already included in selectedEntries@@ -599,15 +348,11 @@ function ListPerspective(props: Props) {<RowCellselected={selected}fsEntry={fsEntry}- showEntriesDescription={showEntriesDescription.current}- entrySize={entrySize.current}isLast={isLast}- selectionMode={selectionMode}- thumbnailMode={thumbnailMode.current}selectEntry={selectEntry}+ selectionMode={selectionMode}deselectEntry={deselectEntry}handleTagMenu={handleTagMenu}- showTags={showTags.current}handleGridContextMenu={(event: React.MouseEvent<HTMLDivElement>,fsEntry: TS.FileSystemEntry,@@ -637,8 +382,6 @@ function ListPerspective(props: Props) {openMoveCopyFilesDialog={openMoveCopyFilesDialog}handleSortingMenu={handleSortingMenu}handleExportCsvMenu={handleExportCsvMenu}- changeEntrySize={changeEntrySize}- entrySize={entrySize.current}openSettings={openSettings}openShareFilesDialog={PlatformIO.haveObjectStoreSupport() ? openShareFilesDialog : undefined@@ -649,37 +392,23 @@ function ListPerspective(props: Props) {handlers={keyBindingHandlers}allowChanges={true}>- <GridPagination- gridPageLimit={gridPageLimit.current}- style={{- marginTop: 5,- marginBottom: 70,- paddingRight: 4,- paddingLeft: 4,- gridTemplateColumns: 'none',- }}- directories={sortedDirectories}- showDetails={showDetails.current}- showDescription={showDescription.current}- showDirectories={showDirectories.current}- desktopMode={desktopMode}- openRenameEntryDialog={openRenameEntryDialog}- showTags={showTags.current}- thumbnailMode={thumbnailMode.current}- entrySize={entrySize.current}- files={sortedFiles}- getCellContent={getCellContent}- currentDirectoryPath={currentDirectoryPath}- onClick={onClick}- onContextMenu={onContextMenu}- settings={settings}- selectedEntries={selectedEntries}- setSelectedEntries={handleSetSelectedEntries}- singleClickAction={singleClickAction.current}- setFileContextMenuAnchorEl={setFileContextMenuAnchorEl}- setDirContextMenuAnchorEl={setDirContextMenuAnchorEl}- clearSelection={clearSelection}- />+ <ListCellsStyleContextProvider>+ <GridPagination+ directories={sortedDirectories}+ desktopMode={desktopMode}+ openRenameEntryDialog={openRenameEntryDialog}+ files={sortedFiles}+ getCellContent={getCellContent}+ currentDirectoryPath={currentDirectoryPath}+ onClick={onClick}+ onContextMenu={onContextMenu}+ selectedEntries={selectedEntries}+ setSelectedEntries={handleSetSelectedEntries}+ setFileContextMenuAnchorEl={setFileContextMenuAnchorEl}+ setDirContextMenuAnchorEl={setDirContextMenuAnchorEl}+ clearSelection={clearSelection}+ />+ </ListCellsStyleContextProvider></GlobalHotKeys>{isAddRemoveTagsDialogOpened && (<AddRemoveTagsDialog@@ -697,40 +426,11 @@ function ListPerspective(props: Props) {{isGridSettingsDialogOpened && (<GridSettingsDialogopen={isGridSettingsDialogOpened}- onClose={(isDefault) => {+ onClose={() => {setIsGridSettingsDialogOpened(false);- isDefaultSetting.current = isDefault;}}- setGridPageLimit={handleGridPageLimit}- gridPageLimit={gridPageLimit.current}- toggleShowDirectories={toggleShowDirectories}- toggleShowTags={toggleShowTags}- toggleShowDetails={toggleShowDetails}- toggleShowDescription={toggleShowDescription}- toggleShowEntriesDescription={toggleShowEntriesDescription}- showDetails={showDetails.current}- showDescription={showDescription.current}- showEntriesDescription={showEntriesDescription.current}- showDirectories={showDirectories.current}- showTags={showTags.current}- toggleThumbnailsMode={toggleThumbnailsMode}- thumbnailMode={thumbnailMode.current}- changeEntrySize={changeEntrySize}- entrySize={entrySize.current}- changeSingleClickAction={changeSingleClickAction}- singleClickAction={singleClickAction.current}openHelpWebPage={openHelpWebPage}handleSortingMenu={handleSortingMenu}- isLocal={isLocal}- resetLocalSettings={() => {- Pro.MetaOperations.savePerspectiveSettings(- currentDirectoryPath,- PerspectiveIDs.LIST,- ).then((fsEntryMeta: TS.FileSystemEntryMeta) => {- setDirectoryMeta(fsEntryMeta);- setIsGridSettingsDialogOpened(false);- });- }}/>)}{isMoveCopyFilesDialogOpened && (@@ -766,7 +466,6 @@ function ListPerspective(props: Props) {}/>)}- {/* {Boolean(dirContextMenuAnchorEl) && ( // todo move dialogs from DirectoryMenu */}<DirectoryMenuopen={Boolean(dirContextMenuAnchorEl)}onClose={() => {@@ -804,16 +503,6 @@ function ListPerspective(props: Props) {open={Boolean(optionsContextMenuAnchorEl)}onClose={closeOptionsMenu}anchorEl={optionsContextMenuAnchorEl}- toggleShowDirectories={toggleShowDirectories}- showDirectories={showDirectories.current}- toggleShowTags={toggleShowTags}- showTags={showTags.current}- toggleThumbnailsMode={toggleThumbnailsMode}- thumbnailMode={thumbnailMode.current}- entrySize={entrySize.current}- changeSingleClickAction={changeSingleClickAction}- singleClickAction={singleClickAction.current}- changeEntrySize={changeEntrySize}openHelpWebPage={openHelpWebPage}openSettings={openSettings}/>diff --git a/src/renderer/perspectives/list/components/RowCell.tsx b/src/renderer/perspectives/list/components/RowCell.tsxindex 7a3319aad..269fd4aa3 100644--- a/src/renderer/perspectives/list/components/RowCell.tsx+++ b/src/renderer/perspectives/list/components/RowCell.tsx@@ -54,13 +54,14 @@ import {AppDispatch,getLastThumbnailImageChange,} from '-/reducers/app';-import { EntrySizes } from '-/components/ZoomComponent';+import { FolderIcon } from '-/components/CommonIcons';import { getSupportedFileTypes, isReorderTags } from '-/reducers/settings';import { defaultSettings } from '../index';import { useTranslation } from 'react-i18next';import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';+import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';const PREFIX = 'RowStyles';export const classes = {@@ -94,13 +95,10 @@ interface Props {selected: boolean;isLast?: boolean;fsEntry: TS.FileSystemEntry;- entrySize: EntrySizes;style?: any;- thumbnailMode: any;selectEntry: (fsEntry: TS.FileSystemEntry) => void;deselectEntry: (fsEntry: TS.FileSystemEntry) => void;selectionMode: boolean;- showTags: boolean;handleTagMenu: (event: Object, tag: TS.Tag, entryPath: string) => void;handleGridContextMenu: (event: Object, fsEntry: TS.FileSystemEntry) => void;handleGridCellDblClick: (event: Object, fsEntry: TS.FileSystemEntry) => void;@@ -108,17 +106,17 @@ interface Props {showEntriesDescription?: boolean;}-export function calculateEntryHeight(entrySize: EntrySizes) {+export function calculateEntryHeight(entrySize: TS.EntrySizes) {let entryHeight = 200;- if (entrySize === EntrySizes.tiny) {+ if (entrySize === 'tiny') {entryHeight = 30;- } else if (entrySize === EntrySizes.small) {+ } else if (entrySize === 'small') {entryHeight = 70;- } else if (entrySize === EntrySizes.normal) {+ } else if (entrySize === 'normal') {entryHeight = 90;- } else if (entrySize === EntrySizes.big) {+ } else if (entrySize === 'big') {entryHeight = 120;- } else if (entrySize === EntrySizes.huge) {+ } else if (entrySize === 'huge') {entryHeight = 150;}return entryHeight;@@ -128,14 +126,11 @@ function RowCell(props: Props) {const {selected,fsEntry,- entrySize,- thumbnailMode,handleTagMenu,handleGridContextMenu,handleGridCellDblClick,handleGridCellClick,showEntriesDescription,- showTags,selectEntry,deselectEntry,selectionMode,@@ -145,6 +140,8 @@ function RowCell(props: Props) {const { t } = useTranslation();const theme = useTheme();const { selectedEntries } = useSelectedEntriesContext();+ const { entrySize, showTags, thumbnailMode } =+ usePerspectiveSettingsContext();const { addTags, editTagForEntry } = useTaggingActionsContext();const { readOnlyMode } = useCurrentLocationContext();const supportedFileTypes = useSelector(getSupportedFileTypes);@@ -209,7 +206,6 @@ function RowCell(props: Props) {fSystemEntry.name,AppConfig.tagDelimiter,PlatformIO.getDirSeparator(),- PlatformIO.getDirSeparator(),);}@@ -357,7 +353,7 @@ function RowCell(props: Props) {}const entryHeight = calculateEntryHeight(entrySize);- const isSmall = entrySize === EntrySizes.tiny; // || entrySize === EntrySizes.small;+ const isSmall = entrySize === 'tiny'; // || entrySize === 'small';const backgroundColor = selected? theme.palette.primary.lightdiff --git a/src/renderer/perspectives/list/hooks/ListCellsStyleProvider.tsx b/src/renderer/perspectives/list/hooks/ListCellsStyleProvider.tsxnew file mode 100644index 000000000..c7c5fe113--- /dev/null+++ b/src/renderer/perspectives/list/hooks/ListCellsStyleProvider.tsx@@ -0,0 +1,53 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import React, { createContext, CSSProperties, useMemo } from 'react';++type ListCellsStyleData = {+ cellsStyle: CSSProperties;+};++export const ListCellsStyleContext = createContext<ListCellsStyleData>({+ cellsStyle: undefined,+});++export type ListCellsStyleContextProviderProps = {+ children: React.ReactNode;+};++export const ListCellsStyleContextProvider = ({+ children,+}: ListCellsStyleContextProviderProps) => {+ const context = useMemo(() => {+ return {+ cellsStyle: {+ marginTop: 5,+ marginBottom: 70,+ paddingRight: 4,+ paddingLeft: 4,+ gridTemplateColumns: 'none',+ },+ };+ }, []);++ return (+ <ListCellsStyleContext.Provider value={context}>+ {children}+ </ListCellsStyleContext.Provider>+ );+};diff --git a/src/renderer/perspectives/list/hooks/useListCellsStyleContext.tsx b/src/renderer/perspectives/list/hooks/useListCellsStyleContext.tsxnew file mode 100644index 000000000..f219d6bcd--- /dev/null+++ b/src/renderer/perspectives/list/hooks/useListCellsStyleContext.tsx@@ -0,0 +1,5 @@+import { useContext } from 'react';++import { ListCellsStyleContext } from './ListCellsStyleProvider';++export const useListCellsStyleContext = () => useContext(ListCellsStyleContext);diff --git a/src/renderer/perspectives/list/index.tsx b/src/renderer/perspectives/list/index.tsxindex dd08efe9d..196af3310 100644--- a/src/renderer/perspectives/list/index.tsx+++ b/src/renderer/perspectives/list/index.tsx@@ -21,7 +21,7 @@ export const defaultSettings = {sortBy: 'byName',layoutType: 'row', // row gridsingleClickAction: 'openInternal', // openInternal openExternal- entrySize: 'small', // small, normal, big+ entrySize: 'small',thumbnailMode: 'contain', // cover containshowDirectories: true,showDetails: true,diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.tsindex 02bc4ce8e..c223c70c8 100644--- a/src/renderer/tagspaces.namespace.d.ts+++ b/src/renderer/tagspaces.namespace.d.ts@@ -178,7 +178,6 @@ export namespace TS {files?: Array<OrderVisibilitySettings>;}// editTag1Tag2 - prevent edit action react component cache and not reload component if add/remove tags- // todo fix prettier SyntaxError: Type expected and remove file from .prettierignoretype EditedEntryAction =| `edit${string}`| 'delete'@@ -186,6 +185,10 @@ export namespace TS {| 'createFile'| 'createDir';+ type EntrySizes = 'huge' | 'big' | 'normal' | 'small' | 'tiny';++ type ThumbnailMode = 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';+interface EditedEntryPath {action: EditedEntryAction;path: string;@@ -209,6 +212,14 @@ export namespace TS {creationTimeStamp: number;}+ type PerspectiveType =+ | 'grid'+ | 'list'+ | 'gallery'+ | 'mapique'+ | 'kanban'+ | 'unspecified';+interface PerspectiveSettings {grid?: FolderSettings;list?: FolderSettings;@@ -219,6 +230,7 @@ export namespace TS {}interface FolderSettings {+ settingsKey: string;showDirectories?: boolean;showTags?: boolean;showDetails?: boolean;@@ -234,7 +246,7 @@ export namespace TS {sortBy?: string;singleClickAction?: string;entrySize?: EntrySizes;- thumbnailMode?: string;+ thumbnailMode?: ThumbnailMode;gridPageLimit?: number;// isLocal?: boolean;}diff --git a/src/renderer/utils/metaoperations.ts b/src/renderer/utils/metaoperations.tsindex f1c2933a6..4d8542887 100644--- a/src/renderer/utils/metaoperations.ts+++ b/src/renderer/utils/metaoperations.ts@@ -54,3 +54,52 @@ export function savePerspective(});});}++export function removeFolderCustomSettings(+ path: string,+ perspective: string,+): Promise<TS.FileSystemEntryMeta> {+ return new Promise((resolve, reject) => {+ loadMetaDataPromise(path, true)+ .then((fsEntryMeta: TS.FileSystemEntryMeta) => {+ let updatedFsEntryMeta: TS.FileSystemEntryMeta = {+ ...fsEntryMeta,+ perspectiveSettings: {+ ...fsEntryMeta.perspectiveSettings,+ [perspective]: undefined,+ },+ };++ saveMetaDataPromise(path, updatedFsEntryMeta)+ .then(() => {+ resolve(updatedFsEntryMeta);+ return true;+ })+ .catch((err) => {+ console.warn(+ 'Error adding perspective for ' + path + ' with ' + err,+ );+ reject();+ });+ return true;+ })+ .catch(() => {+ const newFsEntryMeta: TS.FileSystemEntryMeta = mergeFsEntryMeta({+ perspectiveSettings: {+ [perspective]: undefined,+ },+ });+ saveMetaDataPromise(path, newFsEntryMeta)+ .then(() => {+ resolve(newFsEntryMeta);+ return true;+ })+ .catch((error) => {+ console.warn(+ 'Error adding perspective for ' + path + ' with ' + error,+ );+ reject();+ });+ });+ });+}