aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-05-09 21:37:29 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-05-09 21:37:29 -0500
commit3fa20dc72aa31cc1c836fc913e2e88168f0b7525 (patch)
tree0fc7b8ad845e832c5a108c25f68b4674c9feebaf /src/web
parent5e4ffa2aa90f60fccf9105db0cc6d164c158bee0 (diff)
downloadslskd-3fa20dc72aa31cc1c836fc913e2e88168f0b7525.tar.gz
stub SearchDetail
Diffstat (limited to 'src/web')
-rw-r--r--src/web/src/components/Search/Detail/SearchDetail.js27
-rw-r--r--src/web/src/components/Search/Searches.js29
2 files changed, 49 insertions, 7 deletions
diff --git a/src/web/src/components/Search/Detail/SearchDetail.js b/src/web/src/components/Search/Detail/SearchDetail.js
new file mode 100644
index 00000000..ff93319b
--- /dev/null
+++ b/src/web/src/components/Search/Detail/SearchDetail.js
@@ -0,0 +1,27 @@
+import React, { useEffect, useState } from 'react';
+
+import { getResponses } from '../../../lib/searches';
+
+const SearchDetail = ({ search }) => {
+ const [responses, setResponses] = useState([]);
+
+ useEffect(() => {
+ const get = async () => {
+ console.log('fetching responses')
+ const responses = await getResponses({ id: search.id });
+ console.log('responses', responses)
+ setResponses(responses);
+ }
+
+ get();
+ }, [search.id])
+
+ return (
+ <>
+ <span>{JSON.stringify(search)}</span>
+ {responses.map(r => <li>{JSON.stringify(r)}</li>)}
+ </>
+ )
+}
+
+export default SearchDetail; \ 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 e707f3d0..0a7c7418 100644
--- a/src/web/src/components/Search/Searches.js
+++ b/src/web/src/components/Search/Searches.js
@@ -1,9 +1,11 @@
import React, { useState, useEffect, useRef } from 'react';
import { v4 as uuidv4 } from 'uuid';
+import { useParams } 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,12 +16,15 @@ import {
Button,
} from 'semantic-ui-react';
+import SearchDetail from './Detail/SearchDetail';
+
const Searches = () => {
const [{ connected, connecting, connectError } , setConnected] = useState({ connected: false, connecting: true, connectError: false });
const [{ creating, createError }, setCreating] = useState({ creating: false, createError: false });
const [error, setError] = useState(undefined);
const [searches, setSearches] = useState({});
const inputRef = useRef();
+ const { id: searchId } = useParams();
const onConnecting = () => setConnected({ connected: false, connecting: true, connectError: false })
const onConnected = () => setConnected({ connected: true, connecting: false, connectError: false });
@@ -36,6 +41,7 @@ const Searches = () => {
const searchHub = createSearchHubConnection();
searchHub.on('list', searches => {
+ console.log('list of searches received', searches);
onUpdate(searches.reduce((acc, search) => {
acc[search.id] = search;
return acc;
@@ -44,6 +50,7 @@ const Searches = () => {
})
searchHub.on('update', search => {
+ console.log(search.responses)
onUpdate(old => ({ ...old, [search.id]: search }));
});
@@ -62,8 +69,10 @@ const Searches = () => {
const connect = async () => {
try {
+ console.log('connecting to search hub');
onConnecting();
await searchHub.start();
+ console.log('search hub connected');
} catch (error) {
onConnectionError(error?.message ?? 'Failed to connect')
}
@@ -72,7 +81,9 @@ const Searches = () => {
connect();
return () => {
+ console.log('stopping search hub');
searchHub.stop();
+ console.log('search hub stopped');
}
}, []);
@@ -124,13 +135,17 @@ const Searches = () => {
onKeyUp={(e) => e.key === 'Enter' ? create() : ''}
/>
</Segment>
- <SearchList
- connecting={connecting}
- error={error}
- searches={searches}
- onRemove={remove}
- onStop={stop}
- />
+ <Switch
+ detail={searchId && <SearchDetail search={searches[searchId]}/>}
+ >
+ <SearchList
+ connecting={connecting}
+ error={error}
+ searches={searches}
+ onRemove={remove}
+ onStop={stop}
+ />
+ </Switch>
</div>
)
};