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