Skip to content

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

RenderHistory fix and optimize

sytolk776dae584bd6
diff --git a/app/components/RenderHistory.tsx b/app/components/RenderHistory.tsx
index 2e2f1acb9..2de47a55e 100644
--- a/app/components/RenderHistory.tsx
+++ b/app/components/RenderHistory.tsx
@@ -33,31 +33,34 @@ import IconButton from '@mui/material/IconButton';
import { RemoveIcon, HistoryIcon } from '-/components/CommonIcons';
import { dataTidFormat } from '-/services/test';
import { useTranslation } from 'react-i18next';
+import { useDispatch, useSelector } from 'react-redux';
+import {
+ actions as AppActions,
+ AppDispatch,
+ getCurrentLocationId
+} from '-/reducers/app';
interface Props {
- key: string;
+ historyKey: string;
items: Array<TS.HistoryItem> | Array<TS.BookmarkItem>;
update: () => void;
- currentLocationId: string;
- openLink: (url: string, options: any) => void;
- openLocationById: (locationId: string) => void;
- openEntry: (entryPath: string) => void;
maxItems?: number | undefined;
showDelete?: boolean;
}
function RenderHistory(props: Props) {
const { t } = useTranslation();
- const {
- key,
- items,
- update,
- currentLocationId,
- openLink,
- openLocationById,
- openEntry,
- maxItems,
- showDelete = true
- } = props;
+ const dispatch: AppDispatch = useDispatch();
+ const currentLocationId = useSelector(getCurrentLocationId);
+ const { historyKey, items, update, maxItems, showDelete = true } = props;
+
+ const openLinkDispatch = link => dispatch(AppActions.openLink(link));
+
+ const openLocationByIdDispatch = locationId =>
+ dispatch(AppActions.openLocationById(locationId));
+
+ const openEntryDispatch = entryPath =>
+ dispatch(AppActions.openEntry(entryPath));
+
return (
<>
{items &&
@@ -73,7 +76,7 @@ function RenderHistory(props: Props) {
>
<Grid item xs={10} style={{ minWidth: 245, maxWidth: 245 }}>
<Button
- data-tid={key + 'TID' + dataTidFormat(itemName)}
+ data-tid={historyKey + 'TID' + dataTidFormat(itemName)}
style={{
textTransform: 'none',
fontWeight: 'normal',
@@ -83,9 +86,9 @@ function RenderHistory(props: Props) {
Pro.history.openItem(
item,
currentLocationId,
- openLink,
- openLocationById,
- openEntry
+ openLinkDispatch,
+ openLocationByIdDispatch,
+ openEntryDispatch
)
}
>
@@ -104,7 +107,7 @@ function RenderHistory(props: Props) {
</span>
}
>
- {key === Pro.bookmarks.bookmarksKey ? (
+ {historyKey === Pro.bookmarks.bookmarksKey ? (
<BookmarkTwoToneIcon fontSize="small" />
) : (
<HistoryIcon fontSize="small" />
@@ -128,7 +131,7 @@ function RenderHistory(props: Props) {
<IconButton
aria-label={t('core:clearHistory')}
onClick={() => {
- Pro.history.delItem(item, key);
+ Pro.history.delItem(item, historyKey);
update();
}}
data-tid="deleteHistoryItemTID"
diff --git a/app/components/StoredSearches.tsx b/app/components/StoredSearches.tsx
index 65781184a..9369900f7 100644
--- a/app/components/StoredSearches.tsx
+++ b/app/components/StoredSearches.tsx
@@ -47,7 +47,7 @@ import { Pro } from '../pro';
import { actions as SearchActions, getSearches } from '-/reducers/searches';
import { TS } from '-/tagspaces.namespace';
import SearchMenu from '-/components/menus/SearchMenu';
-import { actions as AppActions, getCurrentLocationId } from '-/reducers/app';
+import { actions as AppActions } from '-/reducers/app';
import HistoryMenu from '-/components/menus/HistoryMenu';
import BookmarksMenu from '-/components/menus/BookmarksMenu';
import { classes, SidePanel } from '-/components/SidePanels.css';
@@ -64,10 +64,6 @@ interface Props {
showUnixHiddenEntries: boolean;
addSearches: (searches: Array<TS.SearchQuery>) => void;
reduceHeightBy: number;
- openEntry: (entryPath: string) => void;
- openLink: (url: string, options: any) => void;
- openLocationById: (locationId: string) => void;
- currentLocationId: string;
storedSearchesVisible: boolean;
showBookmarks: boolean;
fileOpenHistory: boolean;
@@ -354,13 +350,9 @@ function StoredSearches(props: Props) {
</Grid>
{Pro && props.showBookmarks && (
<RenderHistory
- key={Pro.bookmarks.bookmarksKey}
+ historyKey={Pro.bookmarks.bookmarksKey}
items={bookmarkItems}
update={forceUpdate}
- currentLocationId={props.currentLocationId}
- openLink={props.openLink}
- openLocationById={props.openLocationById}
- openEntry={props.openEntry}
/>
)}
<Grid container direction="row">
@@ -405,13 +397,9 @@ function StoredSearches(props: Props) {
</Grid>
{props.fileOpenHistory && (
<RenderHistory
- key={historyKeys.fileOpenKey}
+ historyKey={historyKeys.fileOpenKey}
items={fileOpenHistoryItems}
update={forceUpdate}
- currentLocationId={props.currentLocationId}
- openLink={props.openLink}
- openLocationById={props.openLocationById}
- openEntry={props.openEntry}
/>
)}
<Grid container direction="row">
@@ -457,13 +445,9 @@ function StoredSearches(props: Props) {
</Grid>
{props.fileEditHistory && (
<RenderHistory
- key={historyKeys.fileEditKey}
+ historyKey={historyKeys.fileEditKey}
items={fileEditHistoryItems}
update={forceUpdate}
- currentLocationId={props.currentLocationId}
- openLink={props.openLink}
- openLocationById={props.openLocationById}
- openEntry={props.openEntry}
/>
)}
<Grid container direction="row">
@@ -536,13 +520,9 @@ function StoredSearches(props: Props) {
</Grid>
{props.folderOpenHistory && (
<RenderHistory
- key={historyKeys.folderOpenKey}
+ historyKey={historyKeys.folderOpenKey}
items={folderOpenHistoryItems}
update={forceUpdate}
- currentLocationId={props.currentLocationId}
- openLink={props.openLink}
- openLocationById={props.openLocationById}
- openEntry={props.openEntry}
/>
)}
{SaveSearchDialog && saveSearchDialogOpened !== undefined && (
@@ -606,7 +586,6 @@ function mapStateToProps(state) {
searchQuery: getSearchQuery(state),
searches: getSearches(state),
showUnixHiddenEntries: getShowUnixHiddenEntries(state),
- currentLocationId: getCurrentLocationId(state),
storedSearchesVisible: getStoredSearchesVisible(state),
showBookmarks: getShowBookmarks(state),
fileOpenHistory: getFileOpenHistory(state),
@@ -620,11 +599,6 @@ function mapDispatchToProps(dispatch) {
{
addSearches: SearchActions.addSearches,
setSearchQuery: LocationIndexActions.setSearchQuery,
- // searchAllLocations: LocationIndexActions.searchAllLocations,
- // searchLocationIndex: LocationIndexActions.searchLocationIndex,
- openEntry: AppActions.openEntry,
- openLink: AppActions.openLink,
- openLocationById: AppActions.openLocationById,
setStoredSearchesVisible: SettingsActions.setStoredSearchesVisible,
setShowBookmarks: SettingsActions.setShowBookmarks,
setFileOpenHistory: SettingsActions.setFileOpenHistory,
diff --git a/app/components/WelcomePanel.tsx b/app/components/WelcomePanel.tsx
index ba6993cb4..e3d7c2f91 100644
--- a/app/components/WelcomePanel.tsx
+++ b/app/components/WelcomePanel.tsx
@@ -42,11 +42,7 @@ import {
KeyShortcutsIcon,
HelpIcon
} from '-/components/CommonIcons';
-import {
- actions as AppActions,
- AppDispatch,
- getCurrentLocationId
-} from '-/reducers/app';
+import { actions as AppActions, AppDispatch } from '-/reducers/app';
import { getDesktopMode } from '-/reducers/settings';
import Links from '-/content/links';
import { Pro } from '-/pro';
@@ -88,7 +84,6 @@ function WelcomePanel() {
const theme = useTheme();
const dispatch: AppDispatch = useDispatch();
const desktopMode = useSelector(getDesktopMode);
- const currentLocationId = useSelector(getCurrentLocationId);
const toggleNewFileDialogDispatch = () =>
dispatch(AppActions.toggleNewFileDialog());
@@ -98,11 +93,6 @@ function WelcomePanel() {
dispatch(AppActions.toggleOpenLinkDialog());
const toggleKeysDialogDispatch = () =>
dispatch(AppActions.toggleKeysDialog());
- const openEntryDispatch = entryPath =>
- dispatch(AppActions.openEntry(entryPath));
- const openLinkDispatch = link => dispatch(AppActions.openLink(link));
- const openLocationByIdDispatch = locationId =>
- dispatch(AppActions.openLocationById(locationId));
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
@@ -143,13 +133,9 @@ function WelcomePanel() {
{fileOpenHistoryItems ? (
<List>
<RenderHistory
- key={historyKeys.fileOpenKey}
+ historyKey={historyKeys.fileOpenKey}
items={fileOpenHistoryItems}
update={forceUpdate}
- currentLocationId={currentLocationId}
- openLink={openLinkDispatch}
- openLocationById={openLocationByIdDispatch}
- openEntry={openEntryDispatch}
maxItems={maxRecentItems}
showDelete={showDelete}
/>
@@ -165,13 +151,9 @@ function WelcomePanel() {
{fileEditHistoryItems ? (
<List>
<RenderHistory
- key={historyKeys.fileEditKey}
+ historyKey={historyKeys.fileEditKey}
items={fileEditHistoryItems}
update={forceUpdate}
- currentLocationId={currentLocationId}
- openLink={openLinkDispatch}
- openLocationById={openLocationByIdDispatch}
- openEntry={openEntryDispatch}
maxItems={maxRecentItems}
showDelete={showDelete}
/>
@@ -187,13 +169,9 @@ function WelcomePanel() {
{folderOpenHistoryItems ? (
<List>
<RenderHistory
- key={historyKeys.folderOpenKey}
+ historyKey={historyKeys.folderOpenKey}
items={folderOpenHistoryItems}
update={forceUpdate}
- currentLocationId={currentLocationId}
- openLink={openLinkDispatch}
- openLocationById={openLocationByIdDispatch}
- openEntry={openEntryDispatch}
maxItems={maxRecentItems}
showDelete={showDelete}
/>