aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-06-21 14:11:56 -0500
committerJP Dillingham <jp@dillingham.me>2026-06-21 14:11:56 -0500
commit651d94a28ddced7e65c005448dabce7075505625 (patch)
tree99d1517188f65326b2a153d7921ecbb7d497d8f2 /src/web
parent3edca3166d53d1a7970f07c7014773d7d5408bed (diff)
downloadslskd-651d94a28ddced7e65c005448dabce7075505625.tar.gz
stub dashboard
Diffstat (limited to 'src/web')
-rw-r--r--src/web/src/components/Dashboard/Dashboard.jsx12
-rw-r--r--src/web/src/components/Dashboard/SearchBar.jsx102
2 files changed, 114 insertions, 0 deletions
diff --git a/src/web/src/components/Dashboard/Dashboard.jsx b/src/web/src/components/Dashboard/Dashboard.jsx
new file mode 100644
index 00000000..01dd1aa0
--- /dev/null
+++ b/src/web/src/components/Dashboard/Dashboard.jsx
@@ -0,0 +1,12 @@
+import SearchBar from './SearchBar';
+import React from 'react';
+
+const Dashboard = ({ server } = {}) => {
+ return (
+ <div className="dashboard">
+ <SearchBar server={server} />
+ </div>
+ );
+};
+
+export default Dashboard;
diff --git a/src/web/src/components/Dashboard/SearchBar.jsx b/src/web/src/components/Dashboard/SearchBar.jsx
new file mode 100644
index 00000000..e8c0b7e4
--- /dev/null
+++ b/src/web/src/components/Dashboard/SearchBar.jsx
@@ -0,0 +1,102 @@
+import '../Search/Search.css';
+import { urlBase } from '../../config';
+import * as library from '../../lib/searches';
+import React, { useRef, useState } from 'react';
+import { Link, useHistory } from 'react-router-dom';
+import { toast } from 'react-toastify';
+import { Button, Icon, Input, Segment } from 'semantic-ui-react';
+import { v4 as uuidv4 } from 'uuid';
+
+const SearchBar = ({ server } = {}) => {
+ const [creating, setCreating] = useState(false);
+
+ const inputRef = useRef();
+ const history = useHistory();
+
+ const create = async ({ navigate = false } = {}) => {
+ const ref = inputRef?.current?.inputRef?.current;
+ const searchText = ref.value;
+ const id = uuidv4();
+
+ try {
+ setCreating(true);
+ await library.create({ id, searchText });
+
+ ref.value = '';
+ ref.focus();
+
+ setCreating(false);
+
+ if (navigate) {
+ history.push(`${urlBase}/searches/${id}`);
+ } else {
+ const label =
+ searchText.length > 30 ? `${searchText.slice(0, 15)}...` : searchText;
+ toast.info(
+ <span>
+ Search for &lsquo;{label}&rsquo; started.{' '}
+ <Link to={`${urlBase}/searches/${id}`}>View results</Link>
+ </span>,
+ );
+ }
+ } catch (createError) {
+ console.error(createError);
+ toast.error(
+ createError?.response?.data ?? createError?.message ?? createError,
+ );
+ setCreating(false);
+ }
+ };
+
+ inputRef?.current?.inputRef?.current?.focus();
+
+ return (
+ <Segment
+ className="search-segment"
+ raised
+ >
+ <div className="search-segment-icon">
+ <Icon
+ name="search"
+ size="big"
+ />
+ </div>
+ <Input
+ action={
+ <>
+ <Button
+ disabled={creating || !server?.isConnected}
+ icon="plus"
+ onClick={create}
+ />
+ <Button
+ disabled={creating || !server?.isConnected}
+ icon="search"
+ onClick={() => create({ navigate: true })}
+ />
+ </>
+ }
+ className="search-input"
+ disabled={creating || !server?.isConnected}
+ input={
+ <input
+ data-lpignore="true"
+ placeholder={
+ server?.isConnected
+ ? 'Search phrase'
+ : 'Connect to server to perform a search'
+ }
+ type="search"
+ />
+ }
+ loading={creating}
+ onKeyUp={(keyUpEvent) => (keyUpEvent.key === 'Enter' ? create() : '')}
+ placeholder="Search phrase"
+ ref={inputRef}
+ size="big"
+ />
+ </Segment>
+ );
+};
+
+export default SearchBar;