From 5fc74c62e0a8b2be43f69b9e612776add8b4ad53 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 14 May 2022 22:57:57 -0500 Subject: wip --- src/web/src/components/Search/Searches.js | 93 ++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/web/src/components/Search/Searches.js b/src/web/src/components/Search/Searches.js index 0a7c7418..273d0c0a 100644 --- a/src/web/src/components/Search/Searches.js +++ b/src/web/src/components/Search/Searches.js @@ -1,11 +1,10 @@ import React, { useState, useEffect, useRef } from 'react'; import { v4 as uuidv4 } from 'uuid'; -import { useParams } from 'react-router-dom'; +import { useParams, useHistory, useRouteMatch } from 'react-router-dom'; import * as lib from '../../lib/searches'; import { createSearchHubConnection } from '../../lib/hubFactory'; -import Switch from '../Shared/Switch'; import SearchList from './List/SearchList'; import './Search.css'; @@ -14,9 +13,11 @@ import { Input, Segment, Button, + Loader, } from 'semantic-ui-react'; import SearchDetail from './Detail/SearchDetail'; +import ErrorSegment from '../Shared/ErrorSegment'; const Searches = () => { const [{ connected, connecting, connectError } , setConnected] = useState({ connected: false, connecting: true, connectError: false }); @@ -24,7 +25,11 @@ const Searches = () => { const [error, setError] = useState(undefined); const [searches, setSearches] = useState({}); const inputRef = useRef(); + const searchRef = useRef(); + const { id: searchId } = useParams(); + const history = useHistory(); + const match = useRouteMatch(); const onConnecting = () => setConnected({ connected: false, connecting: true, connectError: false }) const onConnected = () => setConnected({ connected: true, connecting: false, connectError: false }); @@ -87,15 +92,19 @@ const Searches = () => { } }, []); - const create = async () => { + const create = async ({ navigate = false } = {}) => { const searchText = inputRef.current.inputRef.current.value; const id = uuidv4(); - + try { setCreating({ creating: true, createError: false }) - lib.create({ id, searchText }) + await lib.create({ id, searchText }) setCreating({ creating: false, createError: false }) inputRef.current.inputRef.current.value = ''; + + if (navigate) { + history.push(`${match.url}/${id}`) + } } catch (error) { setCreating({ creating: false, createError: error.message }) } @@ -117,27 +126,62 @@ const Searches = () => { await lib.stop({ id: search.id }) } + if (connecting) { + return ; + } + + if (connectError) { + return ; + } + + if (searchId) { + if (searches[searchId]) { + const { searchText } = searches[searchId]; + + return ( +
+ + {/* } + size='big' + ref={searchRef} + disabled={true} + className='search-input' + placeholder="Search phrase" + action={
+ ); + } + + return ( +
+ +
+ ); + } + return (
- - } - size='big' - ref={inputRef} - loading={creating} - disabled={creating} - className='search-input' - placeholder="Search phrase" - action={<> -
) }; -- cgit v1.2.3