From c775d1415b393387b99c6e1ba108bb836d92ae2b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 17 May 2022 10:42:39 -0500 Subject: remove deprecated Search component --- src/web/src/components/App.js | 1 - src/web/src/components/Search/Search.js | 319 ------------------------------ src/web/src/components/Search/Searches.js | 1 + 3 files changed, 1 insertion(+), 320 deletions(-) delete mode 100644 src/web/src/components/Search/Search.js (limited to 'src') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 5e1cda69..9654c2ff 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -8,7 +8,6 @@ import { urlBase } from '../config'; import { createApplicationHubConnection } from '../lib/hubFactory'; import './App.css'; -import Search from './Search/Search'; import Searches from './Search/Searches'; import Browse from './Browse/Browse'; import Users from './Users/Users'; diff --git a/src/web/src/components/Search/Search.js b/src/web/src/components/Search/Search.js deleted file mode 100644 index 4f270a5d..00000000 --- a/src/web/src/components/Search/Search.js +++ /dev/null @@ -1,319 +0,0 @@ -import { v4 as uuidv4 } from 'uuid'; -import React, { Component } from 'react'; -import * as searches from '../../lib/searches'; - -import './Search.css'; - -import Response from './Response'; -import SearchList from './List/SearchList'; -import PlaceholderSegment from '../Shared/PlaceholderSegment'; - -import { - Segment, - Input, - Loader, - Button, - Dropdown, - Checkbox -} from 'semantic-ui-react'; - -const initialState = { - searchPhrase: '', - searchId: undefined, - searchState: 'idle', - searchStatus: { - responseCount: 0, - fileCount: 0 - }, - results: [], - interval: undefined, - displayCount: 5, - resultSort: 'uploadSpeed', - hideNoFreeSlots: true, - hiddenResults: [], - hideLocked: true, - fetching: false, - resultFilters: '', - foldResults: false, -}; - -const sortOptions = { - uploadSpeed: { field: 'uploadSpeed', order: 'desc' }, - queueLength: { field: 'queueLength', order: 'asc' } -} - -const sortDropdownOptions = [ - { key: 'uploadSpeed', text: 'Upload Speed (Fastest to Slowest)', value: 'uploadSpeed' }, - { key: 'queueLength', text: 'Queue Depth (Least to Most)', value: 'queueLength' } -]; - -class Search extends Component { - state = initialState; - - search = () => { - const searchPhrase = this.inputtext.inputRef.current.value; - const searchId = uuidv4(); - - this.setState({ searchPhrase, searchId, searchState: 'pending' }, async () => { - this.saveState(); - searches.create({ id: searchId, searchText: searchPhrase }); - }); - } - - backgroundSearch = async () => { - const searchPhrase = this.inputtext.inputRef.current.value; - const searchId = uuidv4(); - await searches.create({ id: searchId, searchText: searchPhrase }); - this.setSearchText(); - this.inputtext.focus(); - } - - clear = () => { - this.setState(initialState, () => { - this.saveState(); - this.setSearchText(); - this.inputtext.focus(); - }); - } - - keyUp = (event) => event.key === 'Escape' ? this.clear() : ''; - - onSearchPhraseChange = (event, data) => { - this.setState({ searchPhrase: data.value }); - } - - onResultFilterChange = (event, data) => { - this.setState({ resultFilters: data.value }, () => this.saveState()); - } - - clearResultFilter = () => { - this.setState({ resultFilters: '' }, () => this.saveState()); - } - - saveState = () => { - try { - localStorage.setItem('soulseek-example-search-state', JSON.stringify({ ...this.state, results: [] })); - } catch(error) { - console.log(error); - } - } - - loadState = () => { - return new Promise((resolve) => - this.setState(JSON.parse(localStorage.getItem('soulseek-example-search-state')) || initialState, resolve)); - } - - componentDidMount = async () => { - await this.loadState(); - this.fetchResults(); - this.setState({ - interval: window.setInterval(this.fetchStatus, 500) - }, () => this.setSearchText()); - - document.addEventListener("keyup", this.keyUp, false); - } - - setSearchText = () => { - this.inputtext.inputRef.current.value = this.state.searchPhrase; - this.inputtext.inputRef.current.disabled = this.state.searchState !== 'idle'; - } - - componentWillUnmount = () => { - clearInterval(this.state.interval); - this.setState({ interval: undefined }); - document.removeEventListener("keyup", this.keyUp, false); - } - - fetchResults = async () => { - const { searchId } = this.state; - - if (!!searchId) { - this.setState({ fetching: true }, async () => { - try { - const responses = await searches.getResponses({ id: searchId }); - - this.setState({ - results: responses, - fetching: false - }, this.saveState); - } catch (error) { - console.log(error); - this.clear(); - } - }); - } - } - - fetchStatus = async () => { - const { searchState, searchId } = this.state; - - if (searchState === 'pending') { - this.setState({ fetching: true }, async () => { - const response = await searches.getStatus({ id: searchId }); - - if (response.isComplete) { - this.setState({ - searchState: 'complete' - }, this.fetchResults); - } else { - this.setState({ - searchStatus: response, - fetching: false - }, this.saveState); - } - }); - } - } - - showMore = () => { - this.setState({ displayCount: this.state.displayCount + 5 }, () => this.saveState()); - } - - sortAndFilterResults = () => { - const { results = [], hideNoFreeSlots, resultSort, resultFilters = '', hideLocked, hiddenResults = [] } = this.state; - const { field, order } = sortOptions[resultSort]; - - const filters = searches.parseFiltersFromString(resultFilters); - - return results - .filter(r => !hiddenResults.includes(r.username)) - .map(r => { - if (hideLocked) { - return { ...r, lockedFileCount: 0, lockedFiles: [] } - } - return r; - }) - .map(response => searches.filterResponse({ response, filters })) - .filter(r => r.fileCount + r.lockedFileCount > 0) - .filter(r => !(hideNoFreeSlots && r.freeUploadSlots === 0)) - .sort((a, b) => { - if (order === 'asc') { - return a[field] - b[field]; - } - - return b[field] - a[field]; - }); - } - - hideResult = (result) => { - this.setState({ hiddenResults: [...this.state.hiddenResults, result.username]}, () => { - if (this.state.hiddenResults.length === this.state.results.length) { - this.clear(); - } else { - this.saveState(); - } - }); - } - - render = () => { - let { searchState, searchStatus, results = [], displayCount, resultSort, hideNoFreeSlots, hideLocked, hiddenResults = [], fetching, resultFilters, foldResults } = this.state; - let pending = fetching || searchState === 'pending'; - - const sortedAndFilteredResults = this.sortAndFilterResults(); - - const remainingCount = sortedAndFilteredResults.length - displayCount; - const showMoreCount = remainingCount >= 5 ? 5 : remainingCount; - const hiddenCount = results.length - hiddenResults.length - sortedAndFilteredResults.length; - - return ( -
- - } - size='big' - ref={input => this.inputtext = input} - loading={pending} - disabled={pending} - className='search-input' - placeholder="Search phrase" - action={!pending && (searchState === 'idle' ? - <> - - : ''} -
} - - ) - } -} - -export default Search; \ No newline at end of file diff --git a/src/web/src/components/Search/Searches.js b/src/web/src/components/Search/Searches.js index 33fb4176..b21f62b6 100644 --- a/src/web/src/components/Search/Searches.js +++ b/src/web/src/components/Search/Searches.js @@ -87,6 +87,7 @@ const Searches = () => { return () => { searchHub.stop(); } + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); // create a new search, and optionally navigate to it to display the details -- cgit v1.2.3