TagSpaces is an offline, open source, document manager with tagging support
Make file history free feature (#2268)
Stanimir26fca86c9b6d
diff --git a/package-lock.json b/package-lock.jsonindex 67327ebb5..10ffe70c7 100644--- a/package-lock.json+++ b/package-lock.json@@ -205,7 +205,7 @@"yarn": "please-use-npm"},"optionalDependencies": {- "@tagspacespro/tagspacespro": "5.0.126"+ "@tagspacespro/tagspacespro": "5.0.127"}},"node_modules/@adobe/css-tools": {@@ -19825,9 +19825,9 @@}},"node_modules/@tagspacespro/tagspacespro": {- "version": "5.0.126",- "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.126/939e75a92adf3389537b105adbbb28960094115d",- "integrity": "sha512-xI2Qd48mq4F0OPRyOmoiB6cp3FO3CRootVXAUmD7jyrje3axZWuc6aTNfVxiyJQTjZVxsbciaFfodKNdrqMPMg==",+ "version": "5.0.127",+ "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.127/1ebaede5af58f67d408b993764969cd9e91d325a",+ "integrity": "sha512-QRZLkHZKIbJ6Fv4Emyj5wtyblVlus43TUSU1d9CW8Et6ZCDf5ETDO3o4di0z+oKzjyKm674DXgpCDx34ThCjaQ==","license": "Proprietary","optional": true},diff --git a/package.json b/package.jsonindex 77e2475a0..e284ee34f 100644--- a/package.json+++ b/package.json@@ -244,7 +244,7 @@"zod-to-json-schema": "^3.24.1"},"optionalDependencies": {- "@tagspacespro/tagspacespro": "5.0.126"+ "@tagspacespro/tagspacespro": "5.0.127"},"devDependencies": {"@electron/notarize": "^2.5.0",diff --git a/src/renderer/components/RenderHistory.tsx b/src/renderer/components/RenderHistory.tsxindex be7a0478e..0948f0ef5 100644--- a/src/renderer/components/RenderHistory.tsx+++ b/src/renderer/components/RenderHistory.tsx@@ -36,6 +36,7 @@ import {} from '@tagspaces/tagspaces-common/paths';import { useContext } from 'react';import { useTranslation } from 'react-i18next';+import { useHistoryContext } from '-/hooks/useHistoryContext';interface Props {historyKey: string;@@ -47,12 +48,10 @@ interface Props {function RenderHistory(props: Props) {const { t } = useTranslation();const { openHistoryItem } = useBrowserHistoryContext();+ const { delHistory } = useHistoryContext();const bookmarksContext = Pro?.contextProviders?.BookmarksContext? useContext<TS.BookmarksContextData>(Pro.contextProviders.BookmarksContext): undefined;- const historyContext = Pro?.contextProviders?.HistoryContext- ? useContext<TS.HistoryContextData>(Pro.contextProviders.HistoryContext)- : undefined;const { historyKey, items, update, maxItems, showDelete = true } = props;return (@@ -95,7 +94,7 @@ function RenderHistory(props: Props) {</span>}>- {historyKey === Pro.keys.bookmarksKey ? (+ {historyKey === Pro?.keys.bookmarksKey ? (<EntryBookmarkIcon />) : (<HistoryIcon />@@ -118,14 +117,11 @@ function RenderHistory(props: Props) {tooltip={t('delete')}aria-label={t('core:clearHistory')}onClick={() => {- if (historyKey === Pro.keys.bookmarksKey) {+ if (historyKey === Pro?.keys.bookmarksKey) {//del bookmarksbookmarksContext.delBookmark(item.path);} else {- historyContext.delHistory(- historyKey,- item.creationTimeStamp,- );+ delHistory(historyKey, item.creationTimeStamp);}update();}}diff --git a/src/renderer/components/SearchAutocomplete.tsx b/src/renderer/components/SearchAutocomplete.tsxindex 0f476c892..de6f9a367 100644--- a/src/renderer/components/SearchAutocomplete.tsx+++ b/src/renderer/components/SearchAutocomplete.tsx@@ -72,6 +72,7 @@ import React, {import { useTranslation } from 'react-i18next';import { useDispatch, useSelector } from 'react-redux';import { actions as AppActions, AppDispatch } from '../reducers/app';+import { useHistoryContext } from '-/hooks/useHistoryContext';interface Props {style?: any;@@ -107,12 +108,12 @@ function SearchAutocomplete(props: Props) {const { isIndexing, searchAllLocations, searchLocationIndex } =useLocationIndexContext();const { searches } = useSavedSearchesContext();+ const { fileOpenHistory, fileEditHistory, folderOpenHistory, searchHistory } =+ useHistoryContext();+const bookmarksContext = Pro?.contextProviders?.BookmarksContext? useContext<TS.BookmarksContextData>(Pro.contextProviders.BookmarksContext): undefined;- const historyContext = Pro?.contextProviders?.HistoryContext- ? useContext<TS.HistoryContextData>(Pro.contextProviders.HistoryContext)- : undefined;const dispatch: AppDispatch = useDispatch();const maxSearchResults = useSelector(getMaxSearchResults);const showUnixHiddenEntries = useSelector(getShowUnixHiddenEntries);@@ -588,23 +589,10 @@ function SearchAutocomplete(props: Props) {if (currentOptions.current !== action) {currentOptions.current = action;- const fileOpenHistoryItems: Array<TS.HistoryItem> = Pro- ? historyContext.fileOpenHistory- : [];- const folderOpenHistoryItems: Array<TS.HistoryItem> = Pro- ? historyContext.folderOpenHistory- : [];- const fileEditHistoryItems: Array<TS.HistoryItem> = Pro- ? historyContext.fileEditHistory- : [];-searchOptions.current = [- ...getHistoryOptions(fileOpenHistoryItems, t('core:fileOpenHistory')),- ...getHistoryOptions(- folderOpenHistoryItems,- t('core:folderOpenHistory'),- ),- ...getHistoryOptions(fileEditHistoryItems, t('core:fileEditHistory')),+ ...getHistoryOptions(fileOpenHistory, t('core:fileOpenHistory')),+ ...getHistoryOptions(folderOpenHistory, t('core:folderOpenHistory')),+ ...getHistoryOptions(fileEditHistory, t('core:fileEditHistory')),];}} else if (isAction(action, SearchActions.BOOK)) {@@ -638,11 +626,8 @@ function SearchAutocomplete(props: Props) {);}} else if (isAction(action, SearchActions.SEARCH_HISTORY)) {- const searchHistoryItems: Array<TS.HistoryItem> = Pro- ? historyContext.searchHistory- : [];searchOptions.current = getHistoryOptions(- searchHistoryItems,+ searchHistory,t('core:searchHistory'),);} else if (isAction(action, SearchActions.SEARCH)) {@@ -920,7 +905,7 @@ function SearchAutocomplete(props: Props) {setSearchQuery(option.searchQuery);} else {}- } else if (Pro) {+ } else {const item: TS.HistoryItem = {path: option.label,url: option.fullName,diff --git a/src/renderer/components/StoredSearches.tsx b/src/renderer/components/StoredSearches.tsxindex 5c8473866..593724244 100644--- a/src/renderer/components/StoredSearches.tsx+++ b/src/renderer/components/StoredSearches.tsx@@ -49,6 +49,8 @@ import { useTranslation } from 'react-i18next';import { connect } from 'react-redux';import { bindActionCreators } from 'redux';import { Pro } from '../pro';+import { useHistoryContext } from '-/hooks/useHistoryContext';+import { historyKeys } from '-/hooks/HistoryContextProvider';interface Props {style?: any;@@ -70,14 +72,13 @@ function StoredSearches(props: Props) {const { t } = useTranslation();const { searches, findFromSavedSearch } = useSavedSearchesContext();const { openSaveSearchDialog } = useSearchQueryContext();+ const { delAllHistory, fileOpenHistory, fileEditHistory, folderOpenHistory } =+ useHistoryContext();const bookmarksContext = Pro?.contextProviders?.BookmarksContext? useContext<TS.BookmarksContextData>(Pro?.contextProviders?.BookmarksContext,): undefined;- const historyContext = Pro?.contextProviders?.HistoryContext- ? useContext<TS.HistoryContextData>(Pro.contextProviders.HistoryContext)- : undefined;const [searchMenuAnchorEl, setSearchMenuAnchorEl] =useState<null | HTMLElement>(null);const [historyMenuAnchorEl, setHistoryMenuAnchorEl] =@@ -92,7 +93,6 @@ function StoredSearches(props: Props) {const [importFile, setImportFile] = useState<File>(undefined);const fileInputRef = useRef<HTMLInputElement>(null);const menuHistoryKey = useRef<string>(undefined);- const historyKeys = Pro ? Pro.keys.historyKeys : {};const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);const ExportSearchesDialog =@@ -126,23 +126,12 @@ function StoredSearches(props: Props) {Pro && bookmarksContext? bookmarksContext.bookmarks //getBookmarks(): [];- const fileOpenHistoryItems: Array<TS.HistoryItem> = Pro- ? historyContext.fileOpenHistory- : [];- const fileEditHistoryItems: Array<TS.HistoryItem> = Pro- ? historyContext.fileEditHistory- : [];- const folderOpenHistoryItems: Array<TS.HistoryItem> = Pro- ? historyContext.folderOpenHistory- : [];const bookmarksAvailable = bookmarkItems && bookmarkItems.length > 0;- const openedFilesAvailable =- fileOpenHistoryItems && fileOpenHistoryItems.length > 0;- const editedFilesAvailable =- fileEditHistoryItems && fileEditHistoryItems.length > 0;+ const openedFilesAvailable = fileOpenHistory && fileOpenHistory.length > 0;+ const editedFilesAvailable = fileEditHistory && fileEditHistory.length > 0;const openedFoldersAvailable =- folderOpenHistoryItems && folderOpenHistoryItems.length > 0;+ folderOpenHistory && folderOpenHistory.length > 0;return (<SidePanel@@ -373,7 +362,7 @@ function StoredSearches(props: Props) {{props.fileOpenHistory && (<RenderHistoryhistoryKey={historyKeys.fileOpenKey}- items={fileOpenHistoryItems}+ items={fileOpenHistory}update={forceUpdate}/>)}@@ -421,7 +410,7 @@ function StoredSearches(props: Props) {{props.fileEditHistory && (<RenderHistoryhistoryKey={historyKeys.fileEditKey}- items={fileEditHistoryItems}+ items={fileEditHistory}update={forceUpdate}/>)}@@ -473,9 +462,7 @@ function StoredSearches(props: Props) {onClose={() => setHistoryMenuAnchorEl(null)}refreshHistory={() => forceUpdate()}clearAll={() => {- if (Pro) {- historyContext.delAllHistory(menuHistoryKey.current);- }+ delAllHistory(menuHistoryKey.current);forceUpdate();}}/>@@ -501,7 +488,7 @@ function StoredSearches(props: Props) {{props.folderOpenHistory && (<RenderHistoryhistoryKey={historyKeys.folderOpenKey}- items={folderOpenHistoryItems}+ items={folderOpenHistory}update={forceUpdate}/>)}diff --git a/src/renderer/components/WelcomePanel.tsx b/src/renderer/components/WelcomePanel.tsxindex a46c0d73c..ec91ea9f4 100644--- a/src/renderer/components/WelcomePanel.tsx+++ b/src/renderer/components/WelcomePanel.tsx@@ -32,15 +32,12 @@ import {} from '-/components/CommonIcons';import HowToStart from '-/components/HowToStart';import RenderHistory from '-/components/RenderHistory';-import { useAboutDialogContext } from '-/components/dialogs/hooks/useAboutDialogContext';import { useCreateEditLocationDialogContext } from '-/components/dialogs/hooks/useCreateEditLocationDialogContext';import { useKeyboardDialogContext } from '-/components/dialogs/hooks/useKeyboardDialogContext';import { useLinkDialogContext } from '-/components/dialogs/hooks/useLinkDialogContext';import { useNewFileDialogContext } from '-/components/dialogs/hooks/useNewFileDialogContext';-import { Pro } from '-/pro';import { getDesktopMode } from '-/reducers/settings';import { openURLExternally } from '-/services/utils-io';-import { TS } from '-/tagspaces.namespace';import Box from '@mui/material/Box';import Divider from '@mui/material/Divider';import Grid from '@mui/material/Grid2';@@ -51,9 +48,11 @@ import ListItemText from '@mui/material/ListItemText';import Typography from '@mui/material/Typography';import { styled, useTheme } from '@mui/material/styles';import Links from 'assets/links';-import { useContext, useReducer } from 'react';+import { useReducer } from 'react';import { useTranslation } from 'react-i18next';import { useSelector } from 'react-redux';+import { useHistoryContext } from '-/hooks/useHistoryContext';+import { historyKeys } from '-/hooks/HistoryContextProvider';const PREFIX = 'WelcomePanel';@@ -87,27 +86,14 @@ function WelcomePanel() {const theme = useTheme();const { openCreateEditLocationDialog } = useCreateEditLocationDialogContext();const { openNewFileDialog } = useNewFileDialogContext();- const { openAboutDialog } = useAboutDialogContext();const { openKeyboardDialog } = useKeyboardDialogContext();const { openLinkDialog } = useLinkDialogContext();- const historyContext = Pro?.contextProviders?.HistoryContext- ? useContext<TS.HistoryContextData>(Pro.contextProviders.HistoryContext)- : undefined;+ const { fileOpenHistory, fileEditHistory, folderOpenHistory } =+ useHistoryContext();const desktopMode = useSelector(getDesktopMode);const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);- const historyKeys = Pro ? Pro.keys.historyKeys : {};- const fileOpenHistoryItems: Array<TS.HistoryItem> = Pro- ? historyContext.fileOpenHistory- : [];- const fileEditHistoryItems: Array<TS.HistoryItem> = Pro- ? historyContext.fileEditHistory- : [];- const folderOpenHistoryItems: Array<TS.HistoryItem> = Pro- ? historyContext.folderOpenHistory- : [];-const showDelete = false;const maxRecentItems = 5;@@ -117,11 +103,11 @@ function WelcomePanel() {<Typography variant="inherit" className={classes.recentTitle} noWrap>{t('core:fileOpenHistory')}</Typography>- {fileOpenHistoryItems ? (+ {fileOpenHistory ? (<List><RenderHistoryhistoryKey={historyKeys.fileOpenKey}- items={fileOpenHistoryItems}+ items={fileOpenHistory}update={forceUpdate}maxItems={maxRecentItems}showDelete={showDelete}@@ -135,11 +121,11 @@ function WelcomePanel() {<Typography variant="inherit" className={classes.recentTitle} noWrap>{t('core:fileEditHistory')}</Typography>- {fileEditHistoryItems ? (+ {fileEditHistory ? (<List><RenderHistoryhistoryKey={historyKeys.fileEditKey}- items={fileEditHistoryItems}+ items={fileEditHistory}update={forceUpdate}maxItems={maxRecentItems}showDelete={showDelete}@@ -153,11 +139,11 @@ function WelcomePanel() {<Typography variant="inherit" className={classes.recentTitle} noWrap>{t('core:folderOpenHistory')}</Typography>- {folderOpenHistoryItems ? (+ {folderOpenHistory ? (<List><RenderHistoryhistoryKey={historyKeys.folderOpenKey}- items={folderOpenHistoryItems}+ items={folderOpenHistory}update={forceUpdate}maxItems={maxRecentItems}showDelete={showDelete}@@ -351,22 +337,20 @@ function WelcomePanel() {</div></Grid>)}- {Pro && (- <Grid style={{ height: '100%', minWidth: 300 }}>- <div- style={{- margin: 'auto',- marginTop: 55,- marginBottom: 15,- overflowY: 'auto',- height: 'calc(100% - 50px)',- backgroundColor: theme.palette.background.default,- }}- >- {renderRecentItems()}- </div>- </Grid>- )}+ <Grid style={{ height: '100%', minWidth: 300 }}>+ <div+ style={{+ margin: 'auto',+ marginTop: 55,+ marginBottom: 15,+ overflowY: 'auto',+ height: 'calc(100% - 50px)',+ backgroundColor: theme.palette.background.default,+ }}+ >+ {renderRecentItems()}+ </div>+ </Grid></Grid></Root>);diff --git a/src/renderer/components/dialogs/SaveSearchDialog.tsx b/src/renderer/components/dialogs/SaveSearchDialog.tsxindex b160723d1..c35c26439 100644--- a/src/renderer/components/dialogs/SaveSearchDialog.tsx+++ b/src/renderer/components/dialogs/SaveSearchDialog.tsx@@ -53,11 +53,18 @@ function SaveSearchDialog(props: Props) {const { t } = useTranslation();const inputError = useRef<string>(undefined);const title = useRef<string>(getTitle());+ const titleChanged = useRef<boolean>(false);const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);+ useEffect(() => {+ titleChanged.current = false;+ }, [open]);+useEffect(() => {if (tempSearchQuery) {- title.current = getTitle();+ if (!titleChanged.current || !title.current) {+ title.current = getTitle();+ }if (tempSearchQuery.uuid === undefined) {handleValidation();} else if (inputError.current) {@@ -161,6 +168,7 @@ function SaveSearchDialog(props: Props) {onChange={(event) => {const { target } = event;title.current = target.value;+ titleChanged.current = true;handleValidation();forceUpdate();}}diff --git a/src/renderer/components/dialogs/components/SettingsAdvanced.tsx b/src/renderer/components/dialogs/components/SettingsAdvanced.tsxindex e53f484c6..60003abe7 100644--- a/src/renderer/components/dialogs/components/SettingsAdvanced.tsx+++ b/src/renderer/components/dialogs/components/SettingsAdvanced.tsx@@ -48,19 +48,17 @@ import Switch from '@mui/material/Switch';import React, { useContext, useState } from 'react';import { useTranslation } from 'react-i18next';import { useDispatch, useSelector } from 'react-redux';+import { useHistoryContext } from '-/hooks/useHistoryContext';+import { historyKeys } from '-/hooks/HistoryContextProvider';interface Props {showResetSettings: (showDialog: boolean) => void;}-const historyKeys = Pro ? Pro.keys.historyKeys : {};-function SettingsAdvanced(props: Props) {const { showResetSettings } = props;const { t } = useTranslation();- const historyContext = Pro?.contextProviders?.HistoryContext- ? useContext<TS.HistoryContextData>(Pro.contextProviders.HistoryContext)- : undefined;+ const { delAllHistory } = useHistoryContext();const dispatch: AppDispatch = useDispatch();const settings = useSelector(getSettings);const maxCollectedTag = useSelector(getMaxCollectedTag);@@ -202,138 +200,132 @@ function SettingsAdvanced(props: Props) {}/></ListItem>- {Pro && (- <>- <ListItem>- <ListItemText primary={t('core:fileOpenHistory')} />- <ListItemIcon>- <TsIconButton- tooltip={t('clearHistory')}- aria-label={t('core:clearHistory')}- onClick={() => setConfirmDialogKey(historyKeys.fileOpenKey)}- data-tid="clearSearchTID"- >- <DeleteIcon />- </TsIconButton>- </ListItemIcon>- <TsSelect- data-tid="fileOpenTID"- fullWidth={false}- title={t('core:fileOpenHistoryTitle')}- value={settings[historyKeys.fileOpenKey]}- onChange={(event) =>- setHistory(historyKeys.fileOpenKey, event.target.value)- }- >- <MenuItem value={0}>{t('core:disabled')}</MenuItem>- <MenuItem value={10}>10</MenuItem>- <MenuItem value={50}>50</MenuItem>- <MenuItem value={100}>100</MenuItem>- </TsSelect>- </ListItem>- <ListItem>- <ListItemText primary={t('core:folderOpenHistory')} />- <ListItemIcon>- <TsIconButton- tooltip={t('clearHistory')}- aria-label={t('core:clearHistory')}- onClick={() => setConfirmDialogKey(historyKeys.folderOpenKey)}- data-tid="clearSearchTID"- >- <DeleteIcon />- </TsIconButton>- </ListItemIcon>- <TsSelect- data-tid="folderOpenTID"- fullWidth={false}- title={t('core:folderOpenHistoryTitle')}- value={settings[historyKeys.folderOpenKey]}- onChange={(event: any) =>- setHistory(historyKeys.folderOpenKey, event.target.value)- }- >- <MenuItem value={0}>{t('core:disabled')}</MenuItem>- <MenuItem value={10}>10</MenuItem>- <MenuItem value={50}>50</MenuItem>- <MenuItem value={100}>100</MenuItem>- </TsSelect>- </ListItem>- <ListItem>- <ListItemText primary={t('core:fileEditHistory')} />- <ListItemIcon>- <TsIconButton- tooltip={t('clearHistory')}- aria-label={t('core:clearHistory')}- onClick={() => setConfirmDialogKey(historyKeys.fileEditKey)}- data-tid="clearSearchTID"- >- <DeleteIcon />- </TsIconButton>- </ListItemIcon>- <TsSelect- data-tid="fileEditTID"- fullWidth={false}- title={t('core:fileEditHistoryTitle')}- value={settings[historyKeys.fileEditKey]}- onChange={(event: any) =>- setHistory(historyKeys.fileEditKey, event.target.value)- }- >- <MenuItem value={0}>{t('core:disabled')}</MenuItem>- <MenuItem value={10}>10</MenuItem>- <MenuItem value={50}>50</MenuItem>- <MenuItem value={100}>100</MenuItem>- </TsSelect>- </ListItem>- <ListItem>- <ListItemText primary={t('core:searchHistory')} />- <ListItemIcon>- <TsIconButton- tooltip={t('clearHistory')}- aria-label={t('core:clearHistory')}- onClick={() =>- setConfirmDialogKey(historyKeys.searchHistoryKey)- }- data-tid="clearSearchTID"- >- <DeleteIcon />- </TsIconButton>- </ListItemIcon>- <TsSelect- data-tid="searchHistoryTID"- fullWidth={false}- title={t('core:searchHistoryTitle')}- value={settings[historyKeys.searchHistoryKey]}- onChange={(event: any) =>- setHistory(historyKeys.searchHistoryKey, event.target.value)- }- >- <MenuItem value={0}>{t('core:disabled')}</MenuItem>- <MenuItem value={10}>10</MenuItem>- <MenuItem value={50}>50</MenuItem>- <MenuItem value={100}>100</MenuItem>- </TsSelect>- </ListItem>- <ConfirmDialog- open={confirmDialogKey !== null}- onClose={() => {- setConfirmDialogKey(null);- }}- title="Confirm"- content={t('core:confirm' + confirmDialogKey + 'Deletion')}- confirmCallback={(result) => {- if (result) {- historyContext.delAllHistory(confirmDialogKey);- }- }}- cancelDialogTID={'cancelDelete' + confirmDialogKey + 'Dialog'}- confirmDialogTID={'confirmDelete' + confirmDialogKey + 'Dialog'}- confirmDialogContentTID={- 'confirmDelete' + confirmDialogKey + 'DialogContent'- }- />- </>- )}+ <ListItem>+ <ListItemText primary={t('core:fileOpenHistory')} />+ <ListItemIcon>+ <TsIconButton+ tooltip={t('clearHistory')}+ aria-label={t('core:clearHistory')}+ onClick={() => setConfirmDialogKey(historyKeys.fileOpenKey)}+ data-tid="clearSearchTID"+ >+ <DeleteIcon />+ </TsIconButton>+ </ListItemIcon>+ <TsSelect+ data-tid="fileOpenTID"+ fullWidth={false}+ title={t('core:fileOpenHistoryTitle')}+ value={settings[historyKeys.fileOpenKey]}+ onChange={(event) =>+ setHistory(historyKeys.fileOpenKey, event.target.value)+ }+ >+ <MenuItem value={0}>{t('core:disabled')}</MenuItem>+ <MenuItem value={10}>10</MenuItem>+ <MenuItem value={50}>50</MenuItem>+ <MenuItem value={100}>100</MenuItem>+ </TsSelect>+ </ListItem>+ <ListItem>+ <ListItemText primary={t('core:folderOpenHistory')} />+ <ListItemIcon>+ <TsIconButton+ tooltip={t('clearHistory')}+ aria-label={t('core:clearHistory')}+ onClick={() => setConfirmDialogKey(historyKeys.folderOpenKey)}+ data-tid="clearSearchTID"+ >+ <DeleteIcon />+ </TsIconButton>+ </ListItemIcon>+ <TsSelect+ data-tid="folderOpenTID"+ fullWidth={false}+ title={t('core:folderOpenHistoryTitle')}+ value={settings[historyKeys.folderOpenKey]}+ onChange={(event: any) =>+ setHistory(historyKeys.folderOpenKey, event.target.value)+ }+ >+ <MenuItem value={0}>{t('core:disabled')}</MenuItem>+ <MenuItem value={10}>10</MenuItem>+ <MenuItem value={50}>50</MenuItem>+ <MenuItem value={100}>100</MenuItem>+ </TsSelect>+ </ListItem>+ <ListItem>+ <ListItemText primary={t('core:fileEditHistory')} />+ <ListItemIcon>+ <TsIconButton+ tooltip={t('clearHistory')}+ aria-label={t('core:clearHistory')}+ onClick={() => setConfirmDialogKey(historyKeys.fileEditKey)}+ data-tid="clearSearchTID"+ >+ <DeleteIcon />+ </TsIconButton>+ </ListItemIcon>+ <TsSelect+ data-tid="fileEditTID"+ fullWidth={false}+ title={t('core:fileEditHistoryTitle')}+ value={settings[historyKeys.fileEditKey]}+ onChange={(event: any) =>+ setHistory(historyKeys.fileEditKey, event.target.value)+ }+ >+ <MenuItem value={0}>{t('core:disabled')}</MenuItem>+ <MenuItem value={10}>10</MenuItem>+ <MenuItem value={50}>50</MenuItem>+ <MenuItem value={100}>100</MenuItem>+ </TsSelect>+ </ListItem>+ <ListItem>+ <ListItemText primary={t('core:searchHistory')} />+ <ListItemIcon>+ <TsIconButton+ tooltip={t('clearHistory')}+ aria-label={t('core:clearHistory')}+ onClick={() => setConfirmDialogKey(historyKeys.searchHistoryKey)}+ data-tid="clearSearchTID"+ >+ <DeleteIcon />+ </TsIconButton>+ </ListItemIcon>+ <TsSelect+ data-tid="searchHistoryTID"+ fullWidth={false}+ title={t('core:searchHistoryTitle')}+ value={settings[historyKeys.searchHistoryKey]}+ onChange={(event: any) =>+ setHistory(historyKeys.searchHistoryKey, event.target.value)+ }+ >+ <MenuItem value={0}>{t('core:disabled')}</MenuItem>+ <MenuItem value={10}>10</MenuItem>+ <MenuItem value={50}>50</MenuItem>+ <MenuItem value={100}>100</MenuItem>+ </TsSelect>+ </ListItem>+ <ConfirmDialog+ open={confirmDialogKey !== null}+ onClose={() => {+ setConfirmDialogKey(null);+ }}+ title="Confirm"+ content={t('core:confirm' + confirmDialogKey + 'Deletion')}+ confirmCallback={(result) => {+ if (result) {+ delAllHistory(confirmDialogKey);+ }+ }}+ cancelDialogTID={'cancelDelete' + confirmDialogKey + 'Dialog'}+ confirmDialogTID={'confirmDelete' + confirmDialogKey + 'Dialog'}+ confirmDialogContentTID={+ 'confirmDelete' + confirmDialogKey + 'DialogContent'+ }+ /><ListItem><ListItemTextprimary={diff --git a/src/renderer/components/menus/HistoryMenu.tsx b/src/renderer/components/menus/HistoryMenu.tsxindex 2960f4d44..1ace4ffbe 100644--- a/src/renderer/components/menus/HistoryMenu.tsx+++ b/src/renderer/components/menus/HistoryMenu.tsx@@ -18,7 +18,6 @@import { DeleteIcon, ReloadIcon } from '-/components/CommonIcons';import TsMenuList from '-/components/TsMenuList';-import { Pro } from '-/pro';import ListItemIcon from '@mui/material/ListItemIcon';import ListItemText from '@mui/material/ListItemText';import Menu from '@mui/material/Menu';@@ -37,14 +36,14 @@ interface Props {function HistoryMenu(props: Props) {const { t } = useTranslation();const menuItems = [];+ const { onClose, refreshHistory, clearAll, open, anchorEl } = props;menuItems.push(<MenuItem- disabled={!Pro}key="refreshHistoryTID"data-tid="refreshHistoryTID"onClick={() => {- props.onClose();- props.refreshHistory();+ onClose();+ refreshHistory();}}><ListItemIcon>@@ -55,12 +54,11 @@ function HistoryMenu(props: Props) {);menuItems.push(<MenuItem- disabled={!Pro}key="clearHistoryTID"data-tid="clearHistoryTID"onClick={() => {- props.onClose();- props.clearAll();+ onClose();+ clearAll();}}><ListItemIcon>@@ -72,7 +70,7 @@ function HistoryMenu(props: Props) {return (<div style={{ overflowY: 'hidden' }}>- <Menu anchorEl={props.anchorEl} open={props.open} onClose={props.onClose}>+ <Menu anchorEl={anchorEl} open={open} onClose={onClose}><TsMenuList>{menuItems}</TsMenuList></Menu></div>diff --git a/src/renderer/components/menus/SearchMenu.tsx b/src/renderer/components/menus/SearchMenu.tsxindex 0538cd7d6..f5a55d57a 100644--- a/src/renderer/components/menus/SearchMenu.tsx+++ b/src/renderer/components/menus/SearchMenu.tsx@@ -49,7 +49,6 @@ function SearchMenu(props: Props) {const menuItems = [];menuItems.push(<MenuItem- disabled={!Pro}key="openSavedSearch"data-tid="openSavedSearchTID"onClick={() => {@@ -60,14 +59,7 @@ function SearchMenu(props: Props) {<ListItemIcon><CreateFileIcon /></ListItemIcon>- <ListItemText- primary={- <>- {t('core:createNewSavedSearchTitle')}- <ProLabel />- </>- }- />+ <ListItemText primary={t('core:createNewSavedSearchTitle')} /></MenuItem>,);menuItems.push(diff --git a/src/renderer/containers/Root.tsx b/src/renderer/containers/Root.tsxindex d50cdb718..a97543736 100644--- a/src/renderer/containers/Root.tsx+++ b/src/renderer/containers/Root.tsx@@ -55,6 +55,7 @@ import { ChatContextProvider } from '-/hooks/ChatProvider';import { FileUploadDialogContextProvider } from '-/components/dialogs/hooks/FileUploadDialogContextProvider';import { EntryPropsTabsContextProvider } from '-/hooks/EntryPropsTabsContextProvider';import { SearchQueryContextProvider } from '-/hooks/SearchQueryContextProvider';+import { HistoryContextProvider } from '-/hooks/HistoryContextProvider';type RootType = {store: Store<{}>;@@ -102,9 +103,9 @@ export default function Root({ store, persistor }: RootType) {<BrowserHistoryContextProvider><FileUploadDialogContextProvider><ChatContextProvider>- {Pro ? (- <Pro.contextProviders.BookmarksContextProvider>- <Pro.contextProviders.HistoryContextProvider>+ <HistoryContextProvider>+ {Pro ? (+ <Pro.contextProviders.BookmarksContextProvider><Pro.contextProviders.KanBanImportDialogContextProvider><Pro.contextProviders.ThumbDialogContextProvider><Pro.contextProviders.BgndDialogContextProvider>@@ -114,13 +115,13 @@ export default function Root({ store, persistor }: RootType) {</Pro.contextProviders.BgndDialogContextProvider></Pro.contextProviders.ThumbDialogContextProvider></Pro.contextProviders.KanBanImportDialogContextProvider>- </Pro.contextProviders.HistoryContextProvider>- </Pro.contextProviders.BookmarksContextProvider>- ) : (- <DialogsRoot>- <MainPage />- </DialogsRoot>- )}+ </Pro.contextProviders.BookmarksContextProvider>+ ) : (+ <DialogsRoot>+ <MainPage />+ </DialogsRoot>+ )}+ </HistoryContextProvider></ChatContextProvider></FileUploadDialogContextProvider></BrowserHistoryContextProvider>diff --git a/src/renderer/hooks/HistoryContextProvider.tsx b/src/renderer/hooks/HistoryContextProvider.tsxnew file mode 100644index 000000000..a70e33a2b--- /dev/null+++ b/src/renderer/hooks/HistoryContextProvider.tsx@@ -0,0 +1,322 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces GmbH+ *+ * 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 { TS } from '-/tagspaces.namespace';+import {+ normalizePath,+ generateSharingLink,+} from '@tagspaces/tagspaces-common/paths';+import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';+import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';+import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';+import { getRelativeEntryPath, instanceId } from '-/services/utils-io';+import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';+import { useSelector } from 'react-redux';+import { defaultTitle } from '-/services/search';+import useFirstRender from '-/utils/useFirstRender';++export const historyKeys = {+ fileOpenKey: 'tsLastOpenedFilesHistory',+ folderOpenKey: 'tsLastOpenedFoldersHistory',+ fileEditKey: 'tsLastEditedFilesHistory',+ searchHistoryKey: 'tsSearchHistory',+};++export const HistoryContext = createContext<TS.HistoryContextData>({+ fileOpenHistory: undefined,+ folderOpenHistory: undefined,+ fileEditHistory: undefined,+ searchHistory: undefined,+ saveHistory: undefined,+ delAllHistory: undefined,+ delHistory: undefined,+ //openItem: undefined,+});++export type HistoryContextProviderProps = {+ children: React.ReactNode;+};++export const HistoryContextProvider = ({+ children,+}: HistoryContextProviderProps) => {+ const { actions } = useEditedEntryContext();+ const { findLocation } = useCurrentLocationContext();+ const { currentLocationPath, searchQuery, isSearchMode } =+ useDirectoryContentContext();+ const { openedEntry, openLink, openEntry } = useOpenedEntryContext();+ const fileOpenHistory = useRef<TS.HistoryItem[]>(+ getHistory(historyKeys.fileOpenKey),+ );+ const folderOpenHistory = useRef<TS.HistoryItem[]>(+ getHistory(historyKeys.folderOpenKey),+ );+ const fileEditHistory = useRef<TS.HistoryItem[]>(+ getHistory(historyKeys.fileEditKey),+ );+ const searchHistory = useRef<TS.HistoryItem[]>(+ getHistory(historyKeys.searchHistoryKey),+ );+ const fileOpenHistorySettings = useSelector(+ (state: any) => state.settings[historyKeys.fileOpenKey],+ );+ const folderOpenHistorySettings = useSelector(+ (state: any) => state.settings[historyKeys.folderOpenKey],+ );+ const fileEditHistorySettings = useSelector(+ (state: any) => state.settings[historyKeys.fileEditKey],+ );+ const searchHistoryKeySettings = useSelector(+ (state: any) => state.settings[historyKeys.searchHistoryKey],+ );+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);+ const firstRender = useFirstRender();+ const broadcast = new BroadcastChannel('history-sync');+ const currentLocation = findLocation();++ useEffect(() => {+ // Listen for messages from other tabs+ broadcast.onmessage = (event: MessageEvent) => {+ const action = event.data as TS.BroadcastMessage;+ if (instanceId !== action.uuid) {+ if (action.type === 'historyChanged') {+ reflectHistory(action.payload, getHistory(action.payload));+ }+ }+ };+ }, []);++ useEffect(() => {+ if (isSearchMode && currentLocation) {+ const searchTitle = defaultTitle(searchQuery);+ if (searchTitle.length > 0) {+ saveHistory(+ historyKeys.searchHistoryKey,+ {+ creationTimeStamp: new Date().getTime(),+ path:+ searchTitle ++ ' ' ++ (currentLocation.path+ ? currentLocation.path+ : currentLocation.name),+ url: '/',+ lid: currentLocation.uuid,+ searchQuery: searchQuery,+ },+ searchHistoryKeySettings,+ );+ }+ }+ }, [searchQuery]);++ useEffect(() => {+ if (openedEntry) {+ const relEntryPath = getRelativeEntryPath(+ currentLocationPath,+ openedEntry.path,+ );+ if (openedEntry.isFile) {+ saveHistory(+ historyKeys.fileOpenKey,+ {+ creationTimeStamp: new Date().getTime(),+ path: openedEntry.path,+ url: generateSharingLink(openedEntry.locationID, relEntryPath),+ lid: openedEntry.locationID,+ },+ fileOpenHistorySettings,+ );+ } else {+ saveHistory(+ historyKeys.folderOpenKey,+ {+ creationTimeStamp: new Date().getTime(),+ path: openedEntry.path,+ url: generateSharingLink(+ openedEntry.locationID,+ relEntryPath,+ relEntryPath,+ ),+ lid: openedEntry.locationID,+ },+ folderOpenHistorySettings,+ );+ }+ }+ }, [openedEntry]);++ useEffect(() => {+ if (!firstRender && actions && actions.length > 0) {+ for (const action of actions) {+ if (action.action === 'edit') {+ const relativePath = getRelativeEntryPath(+ currentLocationPath,+ action.entry.path,+ );+ saveHistory(+ historyKeys.fileEditKey,+ {+ creationTimeStamp: new Date().getTime(),+ path: relativePath,+ url: generateSharingLink(action.entry.locationID, relativePath),+ lid: action.entry.locationID,+ },+ fileEditHistorySettings,+ );+ }+ }+ }+ }, [actions]);++ function sendMessage(key: string) {+ const message: TS.BroadcastMessage = {+ uuid: instanceId,+ type: 'historyChanged',+ payload: key,+ };+ broadcast.postMessage(message);+ }++ /**+ * @param key+ * @param historyItem+ * @param limit if limit = 0 history is disabled+ */+ function saveHistory(+ key,+ historyItem: TS.HistoryItem,+ limit, // = SettingsDefault[key]+ ) {+ if (limit > 0) {+ let history: TS.HistoryItem[] = [];+ const file: TS.HistoryItem = {+ ...historyItem,+ path: normalizePath(historyItem.path),+ creationTimeStamp: new Date().getTime(),+ };+ const item = localStorage.getItem(key);+ if (item) {+ history = JSON.parse(item).filter((item) => item.path !== file.path);+ const historyLength = history.unshift(file);+ if (historyLength > limit) {+ history = history.slice(0, limit);+ }+ } else {+ history.push(file);+ }++ if (history && history.length > 0) {+ localStorage.setItem(key, JSON.stringify(history));+ reflectHistory(key, history);+ sendMessage(key);+ }+ }+ }++ function reflectHistory(key, items) {+ if (key === historyKeys.fileOpenKey) {+ fileOpenHistory.current = items;+ } else if (key === historyKeys.folderOpenKey) {+ folderOpenHistory.current = items;+ } else if (key === historyKeys.fileEditKey) {+ fileEditHistory.current = items;+ } else if (key === historyKeys.searchHistoryKey) {+ searchHistory.current = items;+ }+ forceUpdate();+ }++ function getHistory(key): Array<TS.HistoryItem> {+ const item = localStorage.getItem(key);+ if (item) {+ return JSON.parse(item);+ }+ return undefined;+ }++ function delAllHistory(key) {+ localStorage.removeItem(key);+ reflectHistory(key, []);+ sendMessage(key);+ }++ function delHistory(key, creationTimeStamp) {+ const item = localStorage.getItem(key);+ if (item) {+ const items = JSON.parse(item);+ const history = items.filter(+ (item) => item.creationTimeStamp !== creationTimeStamp,+ );+ localStorage.setItem(key, JSON.stringify(history));+ reflectHistory(key, history);+ sendMessage(key);+ }+ }++ /*function openItem(item: TS.HistoryItem) {+ if (item.url) {+ openLink(item.url, { fullWidth: false });+ } else {+ if (item.lid !== currentLocation.uuid) {+ openLocationById(item.lid);+ }+ openEntry(item.path);+ }+ }*/++ /*function delItem(item: TS.HistoryItem, key: string) {+ /!*if (key === bookmarksKey) {+ delBookmark(item.path);+ } else {*!/+ delHistory(key, item.creationTimeStamp);+ //}+ }*/++ const context = useMemo(() => {+ return {+ fileOpenHistory: fileOpenHistory.current,+ folderOpenHistory: folderOpenHistory.current,+ fileEditHistory: fileEditHistory.current,+ searchHistory: searchHistory.current,+ saveHistory,+ delAllHistory,+ delHistory,+ //openItem,+ };+ }, [+ fileOpenHistory.current,+ folderOpenHistory.current,+ fileEditHistory.current,+ searchHistory.current,+ currentLocation,+ ]);++ return (+ <HistoryContext.Provider value={context}>+ {children}+ </HistoryContext.Provider>+ );+};diff --git a/src/renderer/hooks/useHistoryContext.tsx b/src/renderer/hooks/useHistoryContext.tsxnew file mode 100644index 000000000..971c4572e--- /dev/null+++ b/src/renderer/hooks/useHistoryContext.tsx@@ -0,0 +1,23 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2023-present TagSpaces GmbH+ *+ * 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 { HistoryContext } from '-/hooks/HistoryContextProvider';++export const useHistoryContext = () => useContext(HistoryContext);