TagSpaces is an offline, open source, document manager with tagging support
Tsn491 migrate search to functional component (#1233)
Stanimir6b9542e86a15
diff --git a/.eslintrc b/.eslintrcindex 76a8ee82f..48430b37e 100644--- a/.eslintrc+++ b/.eslintrc@@ -4,7 +4,7 @@"sourceType": "module","allowImportExportEverywhere": true},- "extends": ["airbnb", "prettier"],+ "extends": ["airbnb", "prettier", "prettier/react"],"env": {"browser": true,"node": truediff --git a/app/components/MobileNavigation.tsx b/app/components/MobileNavigation.tsxindex 0539555ef..118fa7091 100644--- a/app/components/MobileNavigation.tsx+++ b/app/components/MobileNavigation.tsx@@ -145,6 +145,7 @@ class MobileNavigation extends React.Component<Props, State> {/>{isTagLibraryPanelOpened && <TagLibrary />}<Search+ isSearchPanelOpened={isSearchPanelOpened}hideDrawer={hideDrawer}style={{ display: isSearchPanelOpened ? 'block' : 'none' }}/>diff --git a/app/components/Search.tsx b/app/components/Search.tsxindex 5960345a4..449e7f432 100644--- a/app/components/Search.tsx+++ b/app/components/Search.tsx@@ -16,7 +16,7 @@**/-import React from 'react';+import React, { useEffect, useRef, useState } from 'react';import { bindActionCreators } from 'redux';import { connect } from 'react-redux';import { withStyles } from '@material-ui/core/styles';@@ -61,15 +61,14 @@ import {isIndexing,getSearchQuery} from '../reducers/location-index';-import { getMaxSearchResults } from '../reducers/settings';+import { getMaxSearchResults } from '-/reducers/settings';import styles from './SidePanels.css';import i18n from '../services/i18n';-import { FileTypeGroups, SearchQuery } from '../services/search';+import { FileTypeGroups, SearchQuery } from '-/services/search';import { Pro } from '../pro';import SearchMenu from './menus/SearchMenu';-import { Tag } from '../reducers/taglibrary';-import { formatDateTime, extractTimePeriod } from '../utils/dates';-import { isPlusCode, parseLatLon } from '../utils/misc';+import { formatDateTime, extractTimePeriod } from '-/utils/dates';+import { isPlusCode, parseLatLon } from '-/utils/misc';import PlatformIO from '../services/platform-io';interface Props {@@ -81,197 +80,199 @@ interface Props {loadDirectoryContent: (path: string) => void;openURLExternally: (url: string) => void;hideDrawer?: () => void;- searchQuery: () => any;+ searchQuery: SearchQuery; // () => any;setSearchResults: (entries: Array<any>) => void;setSearchQuery: (searchQuery: SearchQuery) => void;currentDirectory: string;indexedEntriesCount: number;maxSearchResults: number;indexing: boolean;+ isSearchPanelOpened: boolean;}-interface State {- textQuery: string;- tagsAND: Array<Tag>;- tagsOR: Array<Tag>;- tagsNOT: Array<Tag>;- fileTypes: Array<string>;- searchBoxing: 'location' | 'folder' | 'global';- lastModified: string;- tagTimePeriod: string;- tagTimePeriodHelper: string;- tagPlace: string;- tagPlaceHelper: string;- tagTimePeriodFrom: Date | null;- tagTimePeriodTo: Date | null;- tagPlaceLat: number | null;- tagPlaceLong: number | null;- tagPlaceRadius: number;- fileSize: string;- forceIndexing: boolean;- searchMenuOpened: boolean;- searchMenuAnchorEl: Element | null;-}--class Search extends React.Component<Props, State> {- // @ts-ignore- state = {- textQuery: '',- tagsAND: [],- tagsOR: [],- tagsNOT: [],- fileTypes: FileTypeGroups.any,- searchBoxing: 'location',- lastModified: '',- tagTimePeriod: '',- tagTimePeriodHelper: ' ',- tagPlace: '',- tagPlaceHelper: ' ',- tagTimePeriodFrom: null,- tagTimePeriodTo: null,- tagPlaceLat: null,- tagPlaceLong: null,- tagPlaceRadius: 0,- forceIndexing: false,- fileSize: '',- searchMenuOpened: false,- searchMenuAnchorEl: null- };-- static getDerivedStateFromProps(nextProps, prevState) {- const { searchBoxing } = prevState;- // console.log('Path: ' + nextProps.currentDirectory);- // if (- // Pro &&- // (!nextProps.currentDirectory || nextProps.currentDirectory.length < 1)- // ) {- // searchBoxing = 'global';- // }- if (- prevState.tagsAND.length < 1 &&- nextProps.searchQuery &&- nextProps.searchQuery.tagsAND- ) {- return {- ...prevState,- searchBoxing,- tagsAND: nextProps.searchQuery.tagsAND+const Search = React.memo((props: Props) => {+ const [textQuery, setTextQuery] = useState<string>('');+ // const [tagsAND, setTagsAND] = useState<Array<Tag>>(props.searchQuery.tagsAND);+ // const [tagsOR, setTagsOR] = useState<Array<Tag>>(props.searchQuery.tagsAND);+ // const [tagsNOT, setTagsNOT] = useState<Array<Tag>>(props.searchQuery.tagsAND);+ const [fileTypes, setFileTypes] = useState<Array<string>>(FileTypeGroups.any);+ const [searchBoxing, setSearchBoxing] = useState<+ 'location' | 'folder' | 'global'+ >('location');+ const [lastModified, setLastModified] = useState<string>('');+ const [tagTimePeriod, setTagTimePeriod] = useState<string>('');+ const [tagTimePeriodHelper, setTagTimePeriodHelper] = useState<string>(' ');+ const [tagPlace, setTagPlace] = useState<string>(' ');+ const [tagPlaceHelper, setTagPlaceHelper] = useState<string>(' ');+ const [tagTimePeriodFrom, setTagTimePeriodFrom] = useState<Date | null>(null);+ const [tagTimePeriodTo, setTagTimePeriodTo] = useState<Date | null>(null);+ const [tagPlaceLat, setTagPlaceLat] = useState<number | null>(null);+ const [tagPlaceLong, setTagPlaceLong] = useState<number | null>(null);+ // const [tagPlaceRadius, setTagPlaceRadius] = useState<number>(0);+ const [forceIndexing, setForceIndexing] = useState<boolean>(false);+ const [fileSize, setFileSize] = useState<string>('');+ const [+ searchMenuAnchorEl,+ setSearchMenuAnchorEl+ ] = useState<null | HTMLElement>(null);++ const mainSearchField = useRef<HTMLInputElement>(null);++ useEffect(() => {+ focusMainSearchFiled();+ }, [props.isSearchPanelOpened]);++ const focusMainSearchFiled = () => {+ if (mainSearchField) {+ // https://github.com/mui-org/material-ui/issues/1594+ const timeout = setTimeout(() => {+ mainSearchField.current.focus();+ }, 100);++ return () => {+ clearTimeout(timeout);};}- return {- ...prevState,- searchBoxing- };- }-- componentDidUpdate() {- const {- textQuery,- tagPlace,- tagTimePeriod,- tagsAND,- tagsOR,- tagsNOT- } = this.state;- if (- !textQuery.length &&- !tagPlace.length &&- !tagTimePeriod.length &&- !tagsAND.length &&- !tagsOR.length &&- !tagsNOT.length- ) {- this.focusMainSearchFiled();- }- }-- mainSearchField;-- focusMainSearchFiled = () => {- if (this.mainSearchField) {- this.mainSearchField.focus();- }};- handleFileTypeChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ const handleFileTypeChange = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;const { value, name } = target;if (name === 'fileTypes') {// @ts-ignore- this.setState({ fileTypes: value }, () => {- if (this.state.searchBoxing !== 'global') {- this.executeSearch();- }- });+ setFileTypes(value);+ if (searchBoxing !== 'global') {+ props.searchLocationIndex({+ ...props.searchQuery,+ // @ts-ignore+ fileTypes: value+ });+ }}};- handleFileSizeChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ const handleFileSizeChange = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;const { value, name } = target;if (name === 'fileSize') {- this.setState({ fileSize: value }, () => {- if (this.state.searchBoxing !== 'global') {- this.executeSearch();- }- });+ setFileSize(value);+ if (searchBoxing !== 'global') {+ props.searchLocationIndex({+ ...props.searchQuery,+ fileSize: value+ });+ }}};- handleLastModifiedChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ const handleLastModifiedChange = (+ event: React.ChangeEvent<HTMLInputElement>+ ) => {const { target } = event;const { value, name } = target;if (name === 'lastModified') {- this.setState({ lastModified: value }, () => {- if (this.state.searchBoxing !== 'global') {- this.executeSearch();- }- });+ setLastModified(value);+ if (searchBoxing !== 'global') {+ props.searchLocationIndex({+ ...props.searchQuery,+ lastModified: value+ });+ }}};- handleTagFieldChange = (name, value) => {- // @ts-ignore- this.setState({ [name]: value }, () => {- if (this.state.searchBoxing !== 'global') {- this.executeSearch();+ function removeTags(tagsArray, removeTagsArray) {+ // eslint-disable-next-line react/no-access-state-in-setstate+ return tagsArray.filter(tag =>+ removeTagsArray.some(valueTag => valueTag.title !== tag.title)+ );+ }++ const handleTagFieldChange = (name, value, reason) => {+ let searchQuery;+ if (reason === 'remove-value') {+ if (name === 'tagsAND') {+ searchQuery = {+ ...props.searchQuery,+ tagsAND: removeTags(props.searchQuery.tagsAND, value)+ };+ } else if (name === 'tagsNOT') {+ searchQuery = {+ ...props.searchQuery,+ tagsNOT: removeTags(props.searchQuery.tagsNOT, value)+ };+ } else if (name === 'tagsOR') {+ searchQuery = {+ ...props.searchQuery,+ tagsOR: removeTags(props.searchQuery.tagsOR, value)+ };}- });+ if (!haveSearchFilters(searchQuery)) {+ clearSearch();+ }+ } else {+ // eslint-disable-next-line no-lonely-if+ if (name === 'tagsAND') {+ searchQuery = { ...props.searchQuery, tagsAND: value };+ } else if (name === 'tagsNOT') {+ searchQuery = { ...props.searchQuery, tagsNOT: value };+ } else if (name === 'tagsOR') {+ searchQuery = { ...props.searchQuery, tagsOR: value };+ }+ }+ // if (searchBoxing !== 'global') { // TODO disable automatic search in global mode+ // props.searchLocationIndex(searchQuery);+ // }};- handleTimePeriodChange = event => {+ function haveSearchFilters(searchQuery) {+ return (+ searchQuery.textQuery ||+ (searchQuery.tagsAND !== undefined && searchQuery.tagsAND.length > 0) ||+ (searchQuery.tagsNOT !== undefined && searchQuery.tagsNOT.length > 0) ||+ (searchQuery.tagsOR !== undefined && searchQuery.tagsOR.length > 0) ||+ (searchQuery.fileTypes !== undefined &&+ searchQuery.fileTypes !== FileTypeGroups.any) ||+ searchQuery.lastModified ||+ searchQuery.tagTimePeriodFrom ||+ searchQuery.tagTimePeriodTo ||+ searchQuery.tagPlaceLat ||+ searchQuery.tagPlaceLong ||+ searchQuery.fileSize+ );+ }++ const handleTimePeriodChange = event => {const { target } = event;const { value } = target;- let tagTimePeriodHelper = '';+ let tagTPeriodHelper = '';const { fromDateTime, toDateTime } = extractTimePeriod(value);if (toDateTime && fromDateTime) {- tagTimePeriodHelper =+ tagTPeriodHelper ='From: ' +formatDateTime(fromDateTime) +' To: ' +formatDateTime(toDateTime);} else {- tagTimePeriodHelper = '';+ tagTPeriodHelper = '';}- this.setState({- tagTimePeriod: value,- tagTimePeriodFrom: fromDateTime,- tagTimePeriodTo: toDateTime,- tagTimePeriodHelper- });+ setTagTimePeriod(value);+ setTagTimePeriodFrom(fromDateTime);+ setTagTimePeriodTo(toDateTime);+ setTagTimePeriodHelper(tagTPeriodHelper);};- handlePlaceChange = event => {+ const handlePlaceChange = event => {const { target } = event;const { value } = target;let lat = null;let lon = null;- let tagPlaceHelper;+ let tagPHelper;if (isPlusCode(value)) {const coord = OpenLocationCode.decode(value);@@ -280,34 +281,29 @@ class Search extends React.Component<Props, State> {} else {const latLon = parseLatLon(value);if (latLon) {- lat = latLon.lat;- lon = latLon.lon;+ ({ lat, lon } = latLon);}}if (lat && lon) {- tagPlaceHelper = 'Place at lat: ' + lat + ' long: ' + lon;+ tagPHelper = 'Place at lat: ' + lat + ' long: ' + lon;} else {- tagPlaceHelper = '';+ tagPHelper = '';}-- this.setState({- tagPlace: value,- tagPlaceLat: lat,- tagPlaceLong: lon,- tagPlaceHelper- });+ setTagPlace(value);+ setTagPlaceLat(lat);+ setTagPlaceLong(lon);+ setTagPlaceHelper(tagPHelper);};- clickSearchButton = () => {- this.executeSearch();- if (this.props.hideDrawer) {- this.props.hideDrawer();+ const clickSearchButton = () => {+ executeSearch();+ if (props.hideDrawer) {+ props.hideDrawer();}};- openPlace = () => {- const { tagPlaceLat, tagPlaceLong } = this.state;+ const openPlace = () => {if (tagPlaceLat && tagPlaceLong) {PlatformIO.openUrl('https://www.openstreetmap.org/#map=16/' +@@ -318,555 +314,491 @@ class Search extends React.Component<Props, State> {}};- startSearch = event => {+ const startSearch = event => {if (event.key === 'Enter' || event.keyCode === 13) {- if (this.props.hideDrawer) {- this.props.hideDrawer();+ if (props.hideDrawer) {+ props.hideDrawer();}- this.executeSearch();+ executeSearch();}};- clearSearch = () => {- const {- setSearchQuery,- loadDirectoryContent,- currentDirectory,- setSearchResults- } = this.props;- setSearchQuery({});- setTimeout(() => {- // TODO find solution without settimeout- this.setState(- {- textQuery: '',- tagsAND: [],- tagsOR: [],- tagsNOT: [],- searchBoxing: 'location',- fileTypes: FileTypeGroups.any,- lastModified: '',- tagTimePeriod: '',- tagTimePeriodHelper: ' ',- tagPlace: '',- tagPlaceHelper: ' ',- tagTimePeriodFrom: null,- tagTimePeriodTo: null,- tagPlaceLat: null,- tagPlaceLong: null,- tagPlaceRadius: 0,- forceIndexing: false,- fileSize: ''- },- () => {- if (currentDirectory) {- loadDirectoryContent(currentDirectory);- } else {- setSearchResults([]);- }- this.focusMainSearchFiled();- }- );- }, 100);+ function openCurrentDirectory() {+ if (props.currentDirectory) {+ props.loadDirectoryContent(props.currentDirectory);+ } else {+ props.setSearchResults([]);+ }+ }++ const clearSearch = () => {+ props.setSearchQuery({});+ openCurrentDirectory();+ setTextQuery('');+ setSearchBoxing('location');+ setFileTypes(FileTypeGroups.any);+ setLastModified('');+ setTagTimePeriod('');+ setTagTimePeriodHelper(' ');+ setTagPlace(' ');+ setTagPlaceHelper(' ');+ setTagTimePeriodFrom(null);+ setTagTimePeriodTo(null);+ setTagPlaceLat(null);+ setTagPlaceLong(null);+ // setTagPlaceRadius(0);+ setForceIndexing(false);+ setFileSize('');};- switchSearchBoxing = (+ const switchSearchBoxing = (event: React.MouseEvent<HTMLElement>,boxing: 'location' | 'folder' | 'global') => {- this.setState(prevState => ({- searchBoxing: boxing === null ? prevState.searchBoxing : boxing- }));+ if (boxing !== null) {+ setSearchBoxing(boxing);+ }};- executeSearch = () => {- const {- setSearchQuery,- searchAllLocations,- searchLocationIndex- } = this.props;+ const executeSearch = () => {+ const { searchAllLocations, searchLocationIndex } = props;const searchQuery: SearchQuery = {- textQuery: this.state.textQuery,- tagsAND: this.state.tagsAND,- tagsOR: this.state.tagsOR,- tagsNOT: this.state.tagsNOT,+ textQuery,+ tagsAND: props.searchQuery.tagsAND,+ tagsOR: props.searchQuery.tagsOR,+ tagsNOT: props.searchQuery.tagsNOT,// @ts-ignore- searchBoxing: this.state.searchBoxing,- fileTypes: this.state.fileTypes,- lastModified: this.state.lastModified,- fileSize: this.state.fileSize,- tagTimePeriodFrom: this.state.tagTimePeriodFrom- ? this.state.tagTimePeriodFrom.getTime()- : null,- tagTimePeriodTo: this.state.tagTimePeriodTo- ? this.state.tagTimePeriodTo.getTime()- : null,- tagPlaceLat: this.state.tagPlaceLat,- tagPlaceLong: this.state.tagPlaceLong,- tagPlaceRadius: this.state.tagPlaceRadius,- maxSearchResults: this.props.maxSearchResults,- currentDirectory: this.props.currentDirectory,- forceIndexing: this.state.forceIndexing+ searchBoxing,+ fileTypes,+ lastModified,+ fileSize,+ tagTimePeriodFrom: tagTimePeriodFrom ? tagTimePeriodFrom.getTime() : null,+ tagTimePeriodTo: tagTimePeriodTo ? tagTimePeriodTo.getTime() : null,+ tagPlaceLat,+ tagPlaceLong,+ // tagPlaceRadius,+ maxSearchResults: props.maxSearchResults,+ currentDirectory: props.currentDirectory,+ forceIndexing};console.log('Search object: ' + JSON.stringify(searchQuery));- setSearchQuery(searchQuery);- if (this.state.searchBoxing === 'global') {+ if (searchBoxing === 'global') {searchAllLocations(searchQuery);} else {searchLocationIndex(searchQuery);}};- handleSearchMenu = (event: any) => {- this.setState({- searchMenuOpened: true,- searchMenuAnchorEl: event.currentTarget- });+ const handleSearchMenu = (event: any) => {+ setSearchMenuAnchorEl(event.currentTarget);};- handleCloseSearchMenu = () => {- this.setState({ searchMenuOpened: false });+ const handleCloseSearchMenu = () => {+ setSearchMenuAnchorEl(null);};- render() {- const { classes, indexing, indexedEntriesCount } = this.props;-- const indexStatus = indexedEntriesCount- ? indexedEntriesCount + ' indexed entries'- : '';- return (- <div className={classes.panel} style={this.props.style}>- <CustomLogo />- <div className={classes.toolbar}>- <Typography- className={classNames(classes.panelTitle, classes.header)}- style={{ flex: 0 }}- >- {i18n.t('searchTitle')}- </Typography>- <Typography- variant="caption"- className={classes.header}- style={{ alignSelf: 'center', paddingLeft: 5, display: 'block' }}- >- {indexStatus}- </Typography>- <IconButton- style={{ marginLeft: 'auto' }}- data-tid="searchMenu"- onClick={this.handleSearchMenu}- >- <MoreVertIcon />- </IconButton>- </div>- <SearchMenu- anchorEl={this.state.searchMenuAnchorEl}- open={this.state.searchMenuOpened}- onClose={this.handleCloseSearchMenu}- createLocationsIndexes={this.props.createLocationsIndexes}- openURLExternally={this.props.openURLExternally}- />- <div className={classes.searchArea}>- <FormControl- className={classes.formControl}- style={{ marginTop: 10 }}- disabled={indexing}+ const { classes, indexing, indexedEntriesCount } = props;++ const indexStatus = indexedEntriesCount+ ? indexedEntriesCount + ' indexed entries'+ : '';+ return (+ <div className={classes.panel} style={props.style}>+ <CustomLogo />+ <div className={classes.toolbar}>+ <Typography+ className={classNames(classes.panelTitle, classes.header)}+ style={{ flex: 0 }}+ >+ {i18n.t('searchTitle')}+ </Typography>+ <Typography+ variant="caption"+ className={classes.header}+ style={{ alignSelf: 'center', paddingLeft: 5, display: 'block' }}+ >+ {indexStatus}+ </Typography>+ <IconButton+ style={{ marginLeft: 'auto' }}+ data-tid="searchMenu"+ onClick={handleSearchMenu}+ >+ <MoreVertIcon />+ </IconButton>+ </div>+ <SearchMenu+ anchorEl={searchMenuAnchorEl}+ open={Boolean(searchMenuAnchorEl)}+ onClose={handleCloseSearchMenu}+ createLocationsIndexes={props.createLocationsIndexes}+ openURLExternally={props.openURLExternally}+ />+ <div className={classes.searchArea}>+ <FormControl+ className={classes.formControl}+ style={{ marginTop: 10 }}+ disabled={indexing}+ >+ <OutlinedInput+ id="textQuery"+ name="textQuery"+ value={textQuery}+ onChange={event => {+ setTextQuery(event.target.value);+ }}+ inputRef={mainSearchField}+ margin="dense"+ autoFocus+ onKeyDown={startSearch}+ title={i18n.t('core:searchWordsWithInterval')}+ endAdornment={+ <InputAdornment position="end">+ <IconButton onClick={clearSearch} size="small" edge="end">+ <ClearSearchIcon />+ </IconButton>+ </InputAdornment>+ }+ />+ </FormControl>+ <FormControl className={classes.formControl} disabled={indexing}>+ <ToggleButtonGroup+ onChange={switchSearchBoxing}+ size="small"+ exclusive+ style={{ marginBottom: 10, alignSelf: 'center' }}+ value={searchBoxing}>- <OutlinedInput- id="textQuery"- name="textQuery"- value={this.state.textQuery}- onChange={event => {- this.setState({ textQuery: event.target.value });- }}- inputRef={input => {- this.mainSearchField = input;- }}- margin="dense"- autoFocus- onKeyDown={this.startSearch}- title={i18n.t('core:searchWordsWithInterval')}- endAdornment={- <InputAdornment position="end">- <IconButton- onClick={this.clearSearch}- size="small"- edge="end"- >- <ClearSearchIcon />- </IconButton>- </InputAdornment>- }+ <ToggleButton value="location" title={i18n.t('searchPlaceholder')}>+ {i18n.t('location')}+ </ToggleButton>+ <ToggleButton+ value="folder"+ title={i18n.t('searchCurrentFolderWithSubFolders')}+ >+ {i18n.t('folder')}+ </ToggleButton>+ <ToggleButton+ title="Search globally in all locations. Feature is in BETA status."+ disabled={!Pro}+ value="global"+ >+ {i18n.t('globalSearch')}+ <sub>{Pro ? ' BETA' : ' PRO'}</sub>+ </ToggleButton>+ </ToggleButtonGroup>+ </FormControl>+ <br />+ <FormControlLabel+ title={i18n.t('core:enableIndexingBySearch')}+ control={+ <Switch+ checked={forceIndexing}+ onChange={() => setForceIndexing(!forceIndexing)}+ name="forceIndexing"/>- </FormControl>- <FormControl className={classes.formControl} disabled={indexing}>- <ToggleButtonGroup- onChange={this.switchSearchBoxing}+ }+ label="Force reindexing"+ />+ <br />+ <br />+ <FormControl className={classes.formControl}>+ <ButtonGroup style={{ justifyContent: 'center' }}>+ <Button+ disabled={indexing}+ id="searchButton"+ variant="outlined"+ color="primary"+ onClick={clickSearchButton}+ style={{ width: '90%' }}size="small"- exclusive- style={{ marginBottom: 10, alignSelf: 'center' }}- value={this.state.searchBoxing}>- <ToggleButton- value="location"- title={i18n.t('searchPlaceholder')}- >- {i18n.t('location')}- </ToggleButton>- <ToggleButton- value="folder"- title={i18n.t('searchCurrentFolderWithSubFolders')}- >- {i18n.t('folder')}- </ToggleButton>- <ToggleButton- title="Search globally in all locations. Feature is in BETA status."- disabled={!Pro}- value="global"- >- {i18n.t('globalSearch')}- <sub>{Pro ? ' BETA' : ' PRO'}</sub>- </ToggleButton>- </ToggleButtonGroup>- </FormControl>- <br />- <FormControlLabel- title={i18n.t('core:enableIndexingBySearch')}- control={- <Switch- checked={this.state.forceIndexing}- onChange={() =>- this.setState(prevState => ({- forceIndexing: !prevState.forceIndexing- }))- }- name="forceIndexing"- />- }- label="Force reindexing"+ {indexing+ ? 'Search disabled while indexing'+ : i18n.t('searchTitle')}+ </Button>+ </ButtonGroup>+ </FormControl>+ <FormControl className={classes.formControl} disabled={indexing}>+ <TagsSelect+ placeholderText={i18n.t('core:selectTags')}+ label={i18n.t('core:mustContainTheseTags')}+ tags={props.searchQuery.tagsAND}+ handleChange={handleTagFieldChange}+ tagSearchType="tagsAND"+ tagMode="remove"/>- <br />- <br />- <FormControl className={classes.formControl}>- <ButtonGroup style={{ justifyContent: 'center' }}>- <Button- disabled={indexing}- id="searchButton"- variant="outlined"- color="primary"- onClick={this.clickSearchButton}- style={{ width: '90%' }}- size="small"- >- {indexing- ? 'Search disabled while indexing'- : i18n.t('searchTitle')}- </Button>- </ButtonGroup>- </FormControl>- <FormControl className={classes.formControl} disabled={indexing}>- <TagsSelect- placeholderText={i18n.t('core:selectTags')}- label={i18n.t('core:mustContainTheseTags')}- tags={this.state.tagsAND}- handleChange={this.handleTagFieldChange}- tagSearchType="tagsAND"- tagMode="remove"- />- </FormControl>- <FormControl className={classes.formControl} disabled={indexing}>- <TagsSelect- placeholderText={i18n.t('core:selectTags')}- tags={this.state.tagsOR}- label={i18n.t('core:atLeastOneOfTheseTags')}- handleChange={this.handleTagFieldChange}- tagSearchType="tagsOR"- tagMode="remove"- />- </FormControl>- <FormControl className={classes.formControl} disabled={indexing}>- <TagsSelect- placeholderText={i18n.t('core:selectTags')}- tags={this.state.tagsNOT}- label={i18n.t('core:noneOfTheseTags')}- handleChange={this.handleTagFieldChange}- tagSearchType="tagsNOT"- tagMode="remove"- />- </FormControl>- <FormControl- className={classes.formControl}- disabled={indexing || !Pro}- title={- !Pro- ? i18n.t('core:thisFunctionalityIsAvailableInPro')- : undefined- }+ </FormControl>+ <FormControl className={classes.formControl} disabled={indexing}>+ <TagsSelect+ placeholderText={i18n.t('core:selectTags')}+ tags={props.searchQuery.tagsOR}+ label={i18n.t('core:atLeastOneOfTheseTags')}+ handleChange={handleTagFieldChange}+ tagSearchType="tagsOR"+ tagMode="remove"+ />+ </FormControl>+ <FormControl className={classes.formControl} disabled={indexing}>+ <TagsSelect+ placeholderText={i18n.t('core:selectTags')}+ tags={props.searchQuery.tagsNOT}+ label={i18n.t('core:noneOfTheseTags')}+ handleChange={handleTagFieldChange}+ tagSearchType="tagsNOT"+ tagMode="remove"+ />+ </FormControl>+ <FormControl+ className={classes.formControl}+ disabled={indexing || !Pro}+ title={+ !Pro ? i18n.t('core:thisFunctionalityIsAvailableInPro') : undefined+ }+ >+ <InputLabel htmlFor="file-type">{i18n.t('core:fileType')}</InputLabel>+ <Select+ value={fileTypes}+ onChange={handleFileTypeChange}+ input={<Input name="fileTypes" id="file-type" />}>- <InputLabel htmlFor="file-type">- {i18n.t('core:fileType')}- </InputLabel>- <Select- value={this.state.fileTypes}- onChange={this.handleFileTypeChange}- input={<Input name="fileTypes" id="file-type" />}+ <MenuItem value={FileTypeGroups.any}>+ {i18n.t('core:anyType')}+ </MenuItem>+ <MenuItem value={FileTypeGroups.folders}>+ <IconButton>+ <FolderIcon />+ </IconButton>+ {i18n.t('core:searchFolders')}+ </MenuItem>+ <MenuItem value={FileTypeGroups.files}>+ <IconButton>+ <FileIcon />+ </IconButton>+ {i18n.t('core:searchFiles')}+ </MenuItem>+ <MenuItem value={FileTypeGroups.untagged}>+ <IconButton>+ <UntaggedIcon />+ </IconButton>+ {i18n.t('core:searchUntaggedEntries')}+ </MenuItem>+ <MenuItem+ value={FileTypeGroups.images}+ title={FileTypeGroups.images.toString()}>- <MenuItem value={FileTypeGroups.any}>- {i18n.t('core:anyType')}- </MenuItem>- <MenuItem value={FileTypeGroups.folders}>- <IconButton>- <FolderIcon />- </IconButton>- {i18n.t('core:searchFolders')}- </MenuItem>- <MenuItem value={FileTypeGroups.files}>- <IconButton>- <FileIcon />- </IconButton>- {i18n.t('core:searchFiles')}- </MenuItem>- <MenuItem value={FileTypeGroups.untagged}>- <IconButton>- <UntaggedIcon />- </IconButton>- {i18n.t('core:searchUntaggedEntries')}- </MenuItem>- <MenuItem- value={FileTypeGroups.images}- title={FileTypeGroups.images.toString()}- >- <IconButton>- <PictureIcon />- </IconButton>- {i18n.t('core:searchPictures')}- </MenuItem>- <MenuItem- value={FileTypeGroups.documents}- title={FileTypeGroups.documents.toString()}- >- <IconButton>- <DocumentIcon />- </IconButton>- {i18n.t('core:searchDocuments')}- </MenuItem>- <MenuItem- value={FileTypeGroups.notes}- title={FileTypeGroups.notes.toString()}- >- <IconButton>- <NoteIcon />- </IconButton>- {i18n.t('core:searchNotes')}- </MenuItem>- <MenuItem- value={FileTypeGroups.audio}- title={FileTypeGroups.audio.toString()}- >- <IconButton>- <AudioIcon />- </IconButton>- {i18n.t('core:searchAudio')}- </MenuItem>- <MenuItem- value={FileTypeGroups.video}- title={FileTypeGroups.video.toString()}- >- <IconButton>- <VideoIcon />- </IconButton>- {i18n.t('core:searchVideoFiles')}- </MenuItem>- <MenuItem- value={FileTypeGroups.archives}- title={FileTypeGroups.archives.toString()}- >- <IconButton>- <ArchiveIcon />- </IconButton>- {i18n.t('core:searchArchives')}- </MenuItem>- <MenuItem- value={FileTypeGroups.bookmarks}- title={FileTypeGroups.bookmarks.toString()}- >- <IconButton>- <BookmarkIcon />- </IconButton>- {i18n.t('core:searchBookmarks')}- </MenuItem>- <MenuItem- value={FileTypeGroups.ebooks}- title={FileTypeGroups.ebooks.toString()}- >- <IconButton>- <BookIcon />- </IconButton>- {i18n.t('core:searchEbooks')}- </MenuItem>- </Select>- {/* <FormHelperText>{i18n.t('core:searchFileTypes')}</FormHelperText> */}- </FormControl>- <FormControl- className={classes.formControl}- disabled={indexing || !Pro}- title={i18n.t('core:thisFunctionalityIsAvailableInPro')}- >- <InputLabel shrink htmlFor="file-size">- {i18n.t('core:sizeSearchTitle')}- </InputLabel>- <Select- value={this.state.fileSize}- onChange={this.handleFileSizeChange}- input={<Input name="fileSize" id="file-size" />}- displayEmpty+ <IconButton>+ <PictureIcon />+ </IconButton>+ {i18n.t('core:searchPictures')}+ </MenuItem>+ <MenuItem+ value={FileTypeGroups.documents}+ title={FileTypeGroups.documents.toString()}>- <MenuItem value="">{i18n.t('core:sizeAny')}</MenuItem>- <MenuItem value="sizeEmpty">{i18n.t('core:sizeEmpty')}</MenuItem>- <MenuItem value="sizeTiny">- {i18n.t('core:sizeTiny')}- (< 10KB)- </MenuItem>- <MenuItem value="sizeVerySmall">- {i18n.t('core:sizeVerySmall')}- (< 100KB)- </MenuItem>- <MenuItem value="sizeSmall">- {i18n.t('core:sizeSmall')}- (< 1MB)- </MenuItem>- <MenuItem value="sizeMedium">- {i18n.t('core:sizeMedium')}- (< 50MB)- </MenuItem>- <MenuItem value="sizeLarge">- {i18n.t('core:sizeLarge')}- (< 1GB)- </MenuItem>- <MenuItem value="sizeHuge">- {i18n.t('core:sizeHuge')}- (> 1GB)- </MenuItem>- </Select>- </FormControl>- <FormControl- className={classes.formControl}- disabled={indexing || !Pro}- title={- !Pro- ? i18n.t('core:thisFunctionalityIsAvailableInPro')- : undefined- }- >- <InputLabel shrink htmlFor="modification-date">- {i18n.t('core:lastModifiedSearchTitle')}- </InputLabel>- <Select- value={this.state.lastModified}- onChange={this.handleLastModifiedChange}- input={<Input name="lastModified" id="modification-date" />}- displayEmpty+ <IconButton>+ <DocumentIcon />+ </IconButton>+ {i18n.t('core:searchDocuments')}+ </MenuItem>+ <MenuItem+ value={FileTypeGroups.notes}+ title={FileTypeGroups.notes.toString()}>- <MenuItem value="">{i18n.t('core:anyTime')}</MenuItem>- <MenuItem value="today">{i18n.t('core:today')}</MenuItem>- <MenuItem value="yesterday">{i18n.t('core:yesterday')}</MenuItem>- <MenuItem value="past7Days">{i18n.t('core:past7Days')}</MenuItem>- <MenuItem value="past30Days">- {i18n.t('core:past30Days')}- </MenuItem>- <MenuItem value="past6Months">- {i18n.t('core:past6Months')}- </MenuItem>- <MenuItem value="pastYear">{i18n.t('core:pastYear')}</MenuItem>- <MenuItem value="moreThanYear">- {i18n.t('core:moreThanYear')}- </MenuItem>- </Select>- </FormControl>- <FormControl- className={classes.formControl}- title={- !Pro- ? i18n.t('core:thisFunctionalityIsAvailableInPro')- : undefined- }+ <IconButton>+ <NoteIcon />+ </IconButton>+ {i18n.t('core:searchNotes')}+ </MenuItem>+ <MenuItem+ value={FileTypeGroups.audio}+ title={FileTypeGroups.audio.toString()}+ >+ <IconButton>+ <AudioIcon />+ </IconButton>+ {i18n.t('core:searchAudio')}+ </MenuItem>+ <MenuItem+ value={FileTypeGroups.video}+ title={FileTypeGroups.video.toString()}+ >+ <IconButton>+ <VideoIcon />+ </IconButton>+ {i18n.t('core:searchVideoFiles')}+ </MenuItem>+ <MenuItem+ value={FileTypeGroups.archives}+ title={FileTypeGroups.archives.toString()}+ >+ <IconButton>+ <ArchiveIcon />+ </IconButton>+ {i18n.t('core:searchArchives')}+ </MenuItem>+ <MenuItem+ value={FileTypeGroups.bookmarks}+ title={FileTypeGroups.bookmarks.toString()}+ >+ <IconButton>+ <BookmarkIcon />+ </IconButton>+ {i18n.t('core:searchBookmarks')}+ </MenuItem>+ <MenuItem+ value={FileTypeGroups.ebooks}+ title={FileTypeGroups.ebooks.toString()}+ >+ <IconButton>+ <BookIcon />+ </IconButton>+ {i18n.t('core:searchEbooks')}+ </MenuItem>+ </Select>+ {/* <FormHelperText>{i18n.t('core:searchFileTypes')}</FormHelperText> */}+ </FormControl>+ <FormControl+ className={classes.formControl}+ disabled={indexing || !Pro}+ title={i18n.t('core:thisFunctionalityIsAvailableInPro')}+ >+ <InputLabel shrink htmlFor="file-size">+ {i18n.t('core:sizeSearchTitle')}+ </InputLabel>+ <Select+ value={fileSize}+ onChange={handleFileSizeChange}+ input={<Input name="fileSize" id="file-size" />}+ displayEmpty>- <TextField- id="tagTimePeriod"- label={i18n.t('Enter time period')}- value={this.state.tagTimePeriod}- disabled={indexing || !Pro}- onChange={this.handleTimePeriodChange}- onKeyDown={this.startSearch}- helperText={this.state.tagTimePeriodHelper}- error={this.state.tagTimePeriodHelper.length < 1}- InputProps={{- endAdornment: (- <InputAdornment- position="end"- title="201905 for May 2019 / 20190412 for 12th of April 2019 / 20190501~124523 for specific time"- >- <IconButton>- <DateIcon />- </IconButton>- </InputAdornment>- )- }}- />- <TextField- id="tagPlace"- label={i18n.t('GPS coordinates or plus code')}- value={this.state.tagPlace}- disabled={indexing || !Pro}- onChange={this.handlePlaceChange}- onKeyDown={this.startSearch}- helperText={this.state.tagPlaceHelper}- error={this.state.tagPlaceHelper.length < 1}- InputProps={{- endAdornment: (- <InputAdornment- position="end"- title="GPS: 49.23276,12.43123 PlusCode: 8FRG8Q87+6X"- >- <IconButton onClick={this.openPlace}>- <PlaceIcon />- </IconButton>- </InputAdornment>- )- }}- />- </FormControl>- <FormControl className={classes.formControl}>- <ButtonGroup style={{ justifyContent: 'center' }}>- {/* <Button- disabled={indexing}- id="searchButton"- variant="outlined"- color="primary"- onClick={this.clickSearchButton}- style={{ width: '70%' }}- >- {indexing- ? 'Search disabled while indexing'- : i18n.t('searchTitle')}- </Button> */}- <Button- variant="outlined"- color="secondary"- size="small"- style={{ width: '90%' }}- onClick={this.clearSearch}- id="resetSearchButton"- >- {i18n.t('resetBtn')}- </Button>- </ButtonGroup>- </FormControl>- </div>+ <MenuItem value="">{i18n.t('core:sizeAny')}</MenuItem>+ <MenuItem value="sizeEmpty">{i18n.t('core:sizeEmpty')}</MenuItem>+ <MenuItem value="sizeTiny">+ {i18n.t('core:sizeTiny')}+ (< 10KB)+ </MenuItem>+ <MenuItem value="sizeVerySmall">+ {i18n.t('core:sizeVerySmall')}+ (< 100KB)+ </MenuItem>+ <MenuItem value="sizeSmall">+ {i18n.t('core:sizeSmall')}+ (< 1MB)+ </MenuItem>+ <MenuItem value="sizeMedium">+ {i18n.t('core:sizeMedium')}+ (< 50MB)+ </MenuItem>+ <MenuItem value="sizeLarge">+ {i18n.t('core:sizeLarge')}+ (< 1GB)+ </MenuItem>+ <MenuItem value="sizeHuge">+ {i18n.t('core:sizeHuge')}+ (> 1GB)+ </MenuItem>+ </Select>+ </FormControl>+ <FormControl+ className={classes.formControl}+ disabled={indexing || !Pro}+ title={+ !Pro ? i18n.t('core:thisFunctionalityIsAvailableInPro') : undefined+ }+ >+ <InputLabel shrink htmlFor="modification-date">+ {i18n.t('core:lastModifiedSearchTitle')}+ </InputLabel>+ <Select+ value={lastModified}+ onChange={handleLastModifiedChange}+ input={<Input name="lastModified" id="modification-date" />}+ displayEmpty+ >+ <MenuItem value="">{i18n.t('core:anyTime')}</MenuItem>+ <MenuItem value="today">{i18n.t('core:today')}</MenuItem>+ <MenuItem value="yesterday">{i18n.t('core:yesterday')}</MenuItem>+ <MenuItem value="past7Days">{i18n.t('core:past7Days')}</MenuItem>+ <MenuItem value="past30Days">{i18n.t('core:past30Days')}</MenuItem>+ <MenuItem value="past6Months">+ {i18n.t('core:past6Months')}+ </MenuItem>+ <MenuItem value="pastYear">{i18n.t('core:pastYear')}</MenuItem>+ <MenuItem value="moreThanYear">+ {i18n.t('core:moreThanYear')}+ </MenuItem>+ </Select>+ </FormControl>+ <FormControl+ className={classes.formControl}+ title={+ !Pro ? i18n.t('core:thisFunctionalityIsAvailableInPro') : undefined+ }+ >+ <TextField+ id="tagTimePeriod"+ label={i18n.t('Enter time period')}+ value={tagTimePeriod}+ disabled={indexing || !Pro}+ onChange={handleTimePeriodChange}+ onKeyDown={startSearch}+ helperText={tagTimePeriodHelper}+ error={tagTimePeriodHelper.length < 1}+ InputProps={{+ endAdornment: (+ <InputAdornment+ position="end"+ title="201905 for May 2019 / 20190412 for 12th of April 2019 / 20190501~124523 for specific time"+ >+ <IconButton>+ <DateIcon />+ </IconButton>+ </InputAdornment>+ )+ }}+ />+ <TextField+ id="tagPlace"+ label={i18n.t('GPS coordinates or plus code')}+ value={tagPlace}+ disabled={indexing || !Pro}+ onChange={handlePlaceChange}+ onKeyDown={startSearch}+ helperText={tagPlaceHelper}+ error={tagPlaceHelper.length < 1}+ InputProps={{+ endAdornment: (+ <InputAdornment+ position="end"+ title="GPS: 49.23276,12.43123 PlusCode: 8FRG8Q87+6X"+ >+ <IconButton onClick={openPlace}>+ <PlaceIcon />+ </IconButton>+ </InputAdornment>+ )+ }}+ />+ </FormControl>+ <FormControl className={classes.formControl}>+ <ButtonGroup style={{ justifyContent: 'center' }}>+ <Button+ variant="outlined"+ color="secondary"+ size="small"+ style={{ width: '90%' }}+ onClick={clearSearch}+ id="resetSearchButton"+ >+ {i18n.t('resetBtn')}+ </Button>+ </ButtonGroup>+ </FormControl></div>- );- }-}+ </div>+ );+});function mapStateToProps(state) {return {diff --git a/app/components/VerticalNavigation.tsx b/app/components/VerticalNavigation.tsxindex 109c7db89..28f80019d 100644--- a/app/components/VerticalNavigation.tsx+++ b/app/components/VerticalNavigation.tsx@@ -399,6 +399,7 @@ class VerticalNavigation extends React.Component<Props, State> {/>{isTagLibraryPanelOpened && <TagLibrary />}<Search+ isSearchPanelOpened={isSearchPanelOpened}style={{ display: isSearchPanelOpened ? 'block' : 'none' }}/>{isHelpFeedbackPanelOpened && (diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.tsindex 508232a4a..65e10377c 100644--- a/app/reducers/location-index.ts+++ b/app/reducers/location-index.ts@@ -17,13 +17,13 @@*/import { Location, getLocation, getLocations, locationType } from './locations';-import { createDirectoryIndex, FileSystemEntry } from '../services/utils-io';+import { createDirectoryIndex, FileSystemEntry } from '-/services/utils-io';import { Pro } from '../pro';import {extractFileExtension,extractFileName,extractTagsAsObjects-} from '../utils/paths';+} from '-/utils/paths';import Search, { SearchQuery } from '../services/search';import { actions as AppActions } from './app';import i18n from '../services/i18n';diff --git a/app/reducers/tagging-actions.ts b/app/reducers/tagging-actions.tsindex e95f5755a..55445a6d7 100644--- a/app/reducers/tagging-actions.ts+++ b/app/reducers/tagging-actions.ts@@ -396,9 +396,10 @@ const actions = {changed: true}));- /* dispatch(+ // TODO rethink this updateCurrentDirEntry and not need for KanBan+ dispatch(AppActions.reflectUpdateSidecarTags(path, fsEntryMeta.tags)- ); */+ );return true;}).catch(err => {@@ -430,9 +431,10 @@ const actions = {changed: true}));- /* dispatch(+ // TODO rethink this updateCurrentDirEntry and not need for KanBan+ dispatch(AppActions.reflectUpdateSidecarTags(path, fsEntryMeta.tags)- ); */+ );return true;}).catch(err => {@@ -515,7 +517,8 @@ const actions = {};saveMetaDataPromise(path, updatedFsEntryMeta).then(() => {- // dispatch(AppActions.reflectUpdateSidecarTags(path, newTags));+ // TODO rethink this updateCurrentDirEntry and not need for KanBan+ dispatch(AppActions.reflectUpdateSidecarTags(path, newTags));dispatch(AppActions.updateOpenedFile(path, {tags: newTags,@@ -600,7 +603,8 @@ const actions = {};saveMetaDataPromise(path, updatedFsEntryMeta).then(() => {- // dispatch(AppActions.reflectUpdateSidecarTags(path, []));+ // TODO rethink this updateCurrentDirEntry and not need for KanBan+ dispatch(AppActions.reflectUpdateSidecarTags(path, []));dispatch(AppActions.updateOpenedFile(path, { tags: [], changed: true }));diff --git a/yarn.lock b/yarn.lockindex 989969be2..a4f5b98ba 100644--- a/yarn.lock+++ b/yarn.lock@@ -4238,9 +4238,9 @@ configstore@^5.0.1:xdg-basedir "^4.0.0"confusing-browser-globals@^1.0.5:- version "1.0.9"- resolved "https://registry.yarnpkg.com/confusing-browser-globals/-/confusing-browser-globals-1.0.9.tgz#72bc13b483c0276801681871d4898516f8f54fdd"- integrity sha512-KbS1Y0jMtyPgIxjO7ZzMAuUpAKMt1SzCL9fsrKsX6b0zJPTaT0SiSPmewwVZg9UAO83HVIlEhZF84LIjZ0lmAw==+ version "1.0.10"+ resolved "https://registry.yarnpkg.com/confusing-browser-globals/-/confusing-browser-globals-1.0.10.tgz#30d1e7f3d1b882b25ec4933d1d1adac353d20a59"+ integrity sha512-gNld/3lySHwuhaVluJUKLePYirM3QNCKzVxqAdhJII9/WXKVX5PURzMVJspS1jTslSqjeuG4KMVTSouit5YPHA==connect-history-api-fallback@^1.6.0:version "1.6.0"