From 6d18a8669723fda0494f50dacf0c313e82a1c913 Mon Sep 17 00:00:00 2001 From: ntr Date: Thu, 10 Nov 2022 17:36:52 +1100 Subject: [PATCH] search just uses query --- TODO.md | 2 ++ api/index.ts | 2 +- api/src/api.ts | 6 +++--- api/src/discogs.ts | 5 ++--- client/src/components/swirl.tsx | 2 ++ client/src/http.ts | 4 ++-- client/src/routes/search.tsx | 12 +++++------- client/src/style/index.less | 2 +- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/TODO.md b/TODO.md index 73731de..ff25f63 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,7 @@ # TODO +search input simplify + status stepper queue up wantlist adds to gracefully handle rate limiting diff --git a/api/index.ts b/api/index.ts index 4d12a0c..0c70153 100644 --- a/api/index.ts +++ b/api/index.ts @@ -28,7 +28,7 @@ async function start() { events, } = createServices(log); - // events.emit(Events.StartupSync); + events.emit(Events.StartupSync); // events.emit(Events.ListingsUpdated); api.listen(); diff --git a/api/src/api.ts b/api/src/api.ts index cebf1b4..af4de29 100644 --- a/api/src/api.ts +++ b/api/src/api.ts @@ -93,9 +93,9 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) { ctx.response.body = wants; }); - router.post('/want/search', async function wantPost(ctx, next) { - const { artist, title } = ctx.request.body; - const results = await discogs.search(artist, title); + router.post('/want/search', async function wantSearch(ctx, next) { + const { query } = ctx.request.body; + const results = await discogs.search(query); ctx.response.body = results; }); diff --git a/api/src/discogs.ts b/api/src/discogs.ts index 144ef20..d220281 100644 --- a/api/src/discogs.ts +++ b/api/src/discogs.ts @@ -58,10 +58,9 @@ export default function createDiscogs(log: Log, pg: Pg) { return data; } - async function search(artist: string, title: string) { + async function search(query: string) { const url = new URL(`${apiBase}/database/search`); - url.searchParams.append('artist', artist); - url.searchParams.append('title', title); + url.searchParams.append('query', query); url.searchParams.append('type', 'release'); url.searchParams.append('format', 'vinyl'); const { data: { results } } = await api.get(url.href); diff --git a/client/src/components/swirl.tsx b/client/src/components/swirl.tsx index 2d4a397..53b9776 100644 --- a/client/src/components/swirl.tsx +++ b/client/src/components/swirl.tsx @@ -1,3 +1,5 @@ +import { h } from 'preact'; + export default function Swirl() { return
; } diff --git a/client/src/http.ts b/client/src/http.ts index 6ac3225..29a92e2 100644 --- a/client/src/http.ts +++ b/client/src/http.ts @@ -48,8 +48,8 @@ const actions = { return api.get('/want/all'); }, - postWantSearch: async function postWantSearch(artist, title) { - return api.post('/want/search', { artist, title }); + postWantSearch: async function postWantSearch(query) { + return api.post('/want/search', { query }); }, postWant: async function postWant(releaseId) { diff --git a/client/src/routes/search.tsx b/client/src/routes/search.tsx index 92305fa..0b6faaa 100644 --- a/client/src/routes/search.tsx +++ b/client/src/routes/search.tsx @@ -33,14 +33,14 @@ function Result(r) { } const User = () => { - const [artist, setArtist] = useState('') + const [query, setQuery] = useState('') const [title, setTitle] = useState(''); const [username, setUsername] = useState(''); const [results, setResults] = useState([]); const [infoText, setInfoText] = useState(''); async function fetchResults() { - const [error, results] = await http.postWantSearch(artist, title); + const [error, results] = await http.postWantSearch(query); if (results.length === 0) { setResults([]); @@ -89,10 +89,8 @@ const User = () => {