1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/packages/app-desktop/gui/Sidebar/Sidebar.tsx

103 lines
3.3 KiB
TypeScript
Raw Normal View History

2020-09-15 15:01:07 +02:00
import * as React from 'react';
import { StyledRoot, StyledSyncReportText, StyledSyncReport, StyledSynchronizeButton } from './styles';
2020-09-15 15:01:07 +02:00
import { ButtonLevel } from '../Button/Button';
import CommandService from '@joplin/lib/services/CommandService';
import Synchronizer from '@joplin/lib/Synchronizer';
import { _ } from '@joplin/lib/locale';
import { AppState } from '../../app.reducer';
import { StateDecryptionWorker, StateResourceFetcher } from '@joplin/lib/reducer';
import { connect } from 'react-redux';
import { themeStyle } from '@joplin/lib/theme';
import { Dispatch } from 'redux';
import FolderAndTagList from './FolderAndTagList';
2020-09-15 15:01:07 +02:00
2020-09-15 15:01:07 +02:00
interface Props {
themeId: number;
dispatch: Dispatch;
decryptionWorker: StateDecryptionWorker;
resourceFetcher: StateResourceFetcher;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
syncReport: any;
syncStarted: boolean;
2020-09-15 15:01:07 +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
}}
/>
);
};
2020-09-15 15:01:07 +02:00
const theme = themeStyle(props.themeId);
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
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
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]}
</StyledSyncReportText>,
);
}
2020-09-15 15:01:07 +02:00
const syncButton = renderSynchronizeButton(props.syncStarted ? 'cancel' : 'sync');
2020-09-15 15:01:07 +02:00
const syncReportComp = !syncReportText.length ? null : (
<StyledSyncReport key="sync_report">
{syncReportText}
</StyledSyncReport>
);
2020-09-15 15:01:07 +02:00
return (
<StyledRoot className="sidebar">
<div style={{ flex: 1 }}><FolderAndTagList/></div>
<div style={{ flex: 0, padding: theme.mainPadding }}>
{syncReportComp}
{syncButton}
</div>
</StyledRoot>
);
};
2020-09-15 15:01:07 +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);