2020-09-15 15:01:07 +02:00
|
|
|
import * as React from 'react';
|
2024-04-25 16:31:18 +02:00
|
|
|
import { StyledRoot, StyledSyncReportText, StyledSyncReport, StyledSynchronizeButton } from './styles';
|
2020-09-15 15:01:07 +02:00
|
|
|
import { ButtonLevel } from '../Button/Button';
|
2020-11-07 17:59:37 +02:00
|
|
|
import CommandService from '@joplin/lib/services/CommandService';
|
|
|
|
import Synchronizer from '@joplin/lib/Synchronizer';
|
|
|
|
import { _ } from '@joplin/lib/locale';
|
2021-09-04 19:11:29 +02:00
|
|
|
import { AppState } from '../../app.reducer';
|
2024-04-25 16:31:18 +02:00
|
|
|
import { StateDecryptionWorker, StateResourceFetcher } from '@joplin/lib/reducer';
|
2024-04-15 19:15:18 +02:00
|
|
|
import { connect } from 'react-redux';
|
2024-04-25 16:31:18 +02:00
|
|
|
import { themeStyle } from '@joplin/lib/theme';
|
2024-04-15 19:15:18 +02:00
|
|
|
import { Dispatch } from 'redux';
|
2024-04-25 16:31:18 +02:00
|
|
|
import FolderAndTagList from './FolderAndTagList';
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2021-05-13 18:57:37 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
interface Props {
|
2020-11-12 21:29:22 +02:00
|
|
|
themeId: number;
|
2024-04-15 19:15:18 +02:00
|
|
|
dispatch: Dispatch;
|
|
|
|
decryptionWorker: StateDecryptionWorker;
|
|
|
|
resourceFetcher: StateResourceFetcher;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
syncReport: any;
|
|
|
|
syncStarted: boolean;
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
2022-09-05 17:21:26 +02:00
|
|
|
const SidebarComponent = (props: Props) => {
|
|
|
|
const renderSynchronizeButton = (type: string) => {
|
2020-09-15 15:01:07 +02:00
|
|
|
const label = type === 'sync' ? _('Synchronise') : _('Cancel');
|
|
|
|
const iconAnimation = type !== 'sync' ? 'icon-infinite-rotation 1s linear infinite' : '';
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StyledSynchronizeButton
|
2021-01-12 14:28:55 +02:00
|
|
|
level={ButtonLevel.SidebarSecondary}
|
2020-09-15 15:01:07 +02:00
|
|
|
iconName="icon-sync"
|
|
|
|
key="sync_button"
|
|
|
|
iconAnimation={iconAnimation}
|
|
|
|
title={label}
|
|
|
|
onClick={() => {
|
2020-11-25 16:40:25 +02:00
|
|
|
void CommandService.instance().execute('synchronize', type !== 'sync');
|
2020-09-15 15:01:07 +02:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2022-09-05 17:21:26 +02:00
|
|
|
};
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2022-09-05 17:21:26 +02:00
|
|
|
const theme = themeStyle(props.themeId);
|
2020-12-11 15:28:59 +02:00
|
|
|
|
2022-09-05 17:21:26 +02:00
|
|
|
let decryptionReportText = '';
|
|
|
|
if (props.decryptionWorker && props.decryptionWorker.state !== 'idle' && props.decryptionWorker.itemCount) {
|
|
|
|
decryptionReportText = _('Decrypting items: %d/%d', props.decryptionWorker.itemIndex + 1, props.decryptionWorker.itemCount);
|
|
|
|
}
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2022-09-05 17:21:26 +02:00
|
|
|
let resourceFetcherText = '';
|
|
|
|
if (props.resourceFetcher && props.resourceFetcher.toFetchCount) {
|
|
|
|
resourceFetcherText = _('Fetching resources: %d/%d', props.resourceFetcher.fetchingCount, props.resourceFetcher.toFetchCount);
|
|
|
|
}
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2022-09-05 17:21:26 +02:00
|
|
|
const lines = Synchronizer.reportToLines(props.syncReport);
|
|
|
|
if (resourceFetcherText) lines.push(resourceFetcherText);
|
|
|
|
if (decryptionReportText) lines.push(decryptionReportText);
|
|
|
|
const syncReportText = [];
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
|
syncReportText.push(
|
|
|
|
<StyledSyncReportText key={i}>
|
|
|
|
{lines[i]}
|
2023-08-22 12:58:53 +02:00
|
|
|
</StyledSyncReportText>,
|
2022-09-05 17:21:26 +02:00
|
|
|
);
|
|
|
|
}
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2022-09-05 17:21:26 +02:00
|
|
|
const syncButton = renderSynchronizeButton(props.syncStarted ? 'cancel' : 'sync');
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2022-09-05 17:21:26 +02:00
|
|
|
const syncReportComp = !syncReportText.length ? null : (
|
|
|
|
<StyledSyncReport key="sync_report">
|
|
|
|
{syncReportText}
|
|
|
|
</StyledSyncReport>
|
|
|
|
);
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2022-09-05 17:21:26 +02:00
|
|
|
return (
|
2024-04-25 16:31:18 +02:00
|
|
|
<StyledRoot className="sidebar">
|
|
|
|
<div style={{ flex: 1 }}><FolderAndTagList/></div>
|
2022-09-05 17:21:26 +02:00
|
|
|
<div style={{ flex: 0, padding: theme.mainPadding }}>
|
|
|
|
{syncReportComp}
|
|
|
|
{syncButton}
|
|
|
|
</div>
|
|
|
|
</StyledRoot>
|
|
|
|
);
|
|
|
|
};
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2020-12-11 15:28:59 +02:00
|
|
|
const mapStateToProps = (state: AppState) => {
|
2020-09-15 15:01:07 +02:00
|
|
|
return {
|
|
|
|
searches: state.searches,
|
|
|
|
syncStarted: state.syncStarted,
|
|
|
|
syncReport: state.syncReport,
|
|
|
|
selectedSearchId: state.selectedSearchId,
|
|
|
|
selectedSmartFilterId: state.selectedSmartFilterId,
|
|
|
|
locale: state.settings.locale,
|
|
|
|
themeId: state.settings.theme,
|
|
|
|
collapsedFolderIds: state.collapsedFolderIds,
|
|
|
|
decryptionWorker: state.decryptionWorker,
|
|
|
|
resourceFetcher: state.resourceFetcher,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-01-12 14:28:55 +02:00
|
|
|
export default connect(mapStateToProps)(SidebarComponent);
|