2020-09-15 15:01:07 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
import { useEffect, useRef } from 'react';
|
|
|
|
import SearchBar from '../SearchBar/SearchBar';
|
|
|
|
import Button, { ButtonLevel } from '../Button/Button';
|
2020-11-07 17:59:37 +02:00
|
|
|
import CommandService from '@joplin/lib/services/CommandService';
|
2020-09-15 15:01:07 +02:00
|
|
|
import { runtime as focusSearchRuntime } from './commands/focusSearch';
|
|
|
|
const styled = require('styled-components').default;
|
|
|
|
|
2020-09-29 13:31:19 +02:00
|
|
|
interface Props {
|
2020-11-12 21:29:22 +02:00
|
|
|
showNewNoteButtons: boolean;
|
2020-09-29 13:31:19 +02:00
|
|
|
}
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
const StyledRoot = styled.div`
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
2020-11-12 21:13:28 +02:00
|
|
|
padding: ${(props: any) => props.theme.mainPadding}px;
|
|
|
|
background-color: ${(props: any) => props.theme.backgroundColor3};
|
2020-09-15 15:01:07 +02:00
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledButton = styled(Button)`
|
|
|
|
margin-left: 8px;
|
|
|
|
`;
|
|
|
|
|
2020-09-29 13:31:19 +02:00
|
|
|
const ButtonContainer = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
`;
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
export default function NoteListControls(props: Props) {
|
2020-09-15 15:01:07 +02:00
|
|
|
const searchBarRef = useRef(null);
|
|
|
|
|
|
|
|
useEffect(function() {
|
|
|
|
CommandService.instance().registerRuntime('focusSearch', focusSearchRuntime(searchBarRef));
|
|
|
|
|
|
|
|
return function() {
|
|
|
|
CommandService.instance().unregisterRuntime('focusSearch');
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
function onNewTodoButtonClick() {
|
|
|
|
CommandService.instance().execute('newTodo');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onNewNoteButtonClick() {
|
|
|
|
CommandService.instance().execute('newNote');
|
|
|
|
}
|
|
|
|
|
2020-09-29 13:31:19 +02:00
|
|
|
function renderNewNoteButtons() {
|
|
|
|
if (!props.showNewNoteButtons) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ButtonContainer>
|
|
|
|
<StyledButton
|
2020-10-18 22:52:10 +02:00
|
|
|
tooltip={CommandService.instance().label('newTodo')}
|
2020-09-29 13:31:19 +02:00
|
|
|
iconName="far fa-check-square"
|
|
|
|
level={ButtonLevel.Primary}
|
|
|
|
onClick={onNewTodoButtonClick}
|
|
|
|
/>
|
|
|
|
<StyledButton
|
2020-10-18 22:52:10 +02:00
|
|
|
tooltip={CommandService.instance().label('newNote')}
|
2020-09-29 13:31:19 +02:00
|
|
|
iconName="icon-note"
|
|
|
|
level={ButtonLevel.Primary}
|
|
|
|
onClick={onNewNoteButtonClick}
|
|
|
|
/>
|
|
|
|
</ButtonContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
return (
|
|
|
|
<StyledRoot>
|
|
|
|
<SearchBar inputRef={searchBarRef}/>
|
2020-09-29 13:31:19 +02:00
|
|
|
{renderNewNoteButtons()}
|
2020-09-15 15:01:07 +02:00
|
|
|
</StyledRoot>
|
|
|
|
);
|
|
|
|
}
|