diff --git a/TODO.md b/TODO.md index 350864d..abbb330 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,8 @@ contact options on landing page +move want add to rpc + listing ids overflowing skip unofficial release diff --git a/api/index.ts b/api/index.ts index 0c70153..4d12a0c 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 af4de29..6da1d9a 100644 --- a/api/src/api.ts +++ b/api/src/api.ts @@ -59,13 +59,6 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) { ctx.status = 200; }); - router.get('/user/offers', async function userOffersGet(ctx, next) { - ctx.assert(ctx.isAuthenticated(), 401, 'log in required'); - const user = ctx.state.user; - const offers = await pg.userOffers(user); - ctx.response.body = offers; - }); - router.post('/want', async function wantPost(ctx, next) { ctx.assert(ctx.isAuthenticated(), 401, 'log in required'); const { releaseId } = ctx.request.body; @@ -85,14 +78,6 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) { ctx.response.body = wants; }); - router.get('/want/all', async function wantGet(ctx, next) { - ctx.assert(ctx.isAuthenticated(), 401, 'log in required'); - const user = ctx.state.user; - const wants = await pg.wantList(user); - - ctx.response.body = wants; - }); - router.post('/want/search', async function wantSearch(ctx, next) { const { query } = ctx.request.body; const results = await discogs.search(query); diff --git a/api/src/events.ts b/api/src/events.ts index 0618e24..bdc465e 100644 --- a/api/src/events.ts +++ b/api/src/events.ts @@ -51,6 +51,7 @@ export default function createEvents(log: Log, pg: Pg, discogs, offers) { log.info({ event: Events.WantsAdded, wants: wants.map(w => wantDetails(w)) }, 'starting listings population'); await updateWantListings(wants); log.info({ event: Events.WantsAdded, wants: wants.map(w => wantDetails(w)) }, 'finished populating listings'); + events.emit(Events.ListingsUpdated); }); events.on(Events.StartupSync, async function startupSync() { diff --git a/client/package-lock.json b/client/package-lock.json index dc36a28..fb24194 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "@reduxjs/toolkit": "^1.8.5", + "izitoast": "^1.4.0", "lodash": "^4.17.21", "logrocket": "^3.0.1", "preact": "^10.10.0", @@ -10844,6 +10845,11 @@ "node": ">=8" } }, + "node_modules/izitoast": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/izitoast/-/izitoast-1.4.0.tgz", + "integrity": "sha512-Oc1X2wiQtPp39i5VpIjf3GJf5sfCtHKXZ5szx7RareyEeFLUlcEW0FSfBni28+Ul6KNKZRKzhVuWzSP4Xngh0w==" + }, "node_modules/jake": { "version": "10.8.5", "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.5.tgz", @@ -29566,6 +29572,11 @@ "istanbul-lib-report": "^3.0.0" } }, + "izitoast": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/izitoast/-/izitoast-1.4.0.tgz", + "integrity": "sha512-Oc1X2wiQtPp39i5VpIjf3GJf5sfCtHKXZ5szx7RareyEeFLUlcEW0FSfBni28+Ul6KNKZRKzhVuWzSP4Xngh0w==" + }, "jake": { "version": "10.8.5", "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.5.tgz", diff --git a/client/package.json b/client/package.json index a44f292..4b24086 100644 --- a/client/package.json +++ b/client/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "@reduxjs/toolkit": "^1.8.5", + "izitoast": "^1.4.0", "lodash": "^4.17.21", "logrocket": "^3.0.1", "preact": "^10.10.0", diff --git a/client/src/http.ts b/client/src/http.ts index 29a92e2..a1e9605 100644 --- a/client/src/http.ts +++ b/client/src/http.ts @@ -32,21 +32,7 @@ function onError(error) { api.interceptors.response.use(onSuccess, onError); const actions = { - getBundles: async function getBundles() { - return api.get('/acp/bundles'); - }, - - getOffers: async function getOffers() { - return api.get('/user/offers'); - }, - - getOffersAcp: async function getOffersAcp() { - return api.get('/acp/offers'); - }, - - getWants: async function getWants() { - return api.get('/want/all'); - }, + // TODO move to rpc postWantSearch: async function postWantSearch(query) { return api.post('/want/search', { query }); @@ -60,6 +46,9 @@ const actions = { return api.post('/want/discogs', { username }); }, + // -------------------------------- + // require as http to set cookies + getLogin: async function getLogin() { return api.get('/auth/login') }, diff --git a/client/src/routes/search.tsx b/client/src/routes/search.tsx index 2394b89..46ec12a 100644 --- a/client/src/routes/search.tsx +++ b/client/src/routes/search.tsx @@ -1,10 +1,13 @@ import { h } from 'preact'; import { useState, useRef, useEffect } from 'preact/hooks'; import { ExternalLink, Check } from 'react-feather'; +import { useSelector } from 'react-redux' + +import { State } from './../store'; import http from '../http'; -function Result(r) { +function Result(r, wants) { const [added, setAdded] = useState(false) async function onClick() { @@ -13,7 +16,9 @@ function Result(r) { setAdded(true); } - const classes = `${added ? 'added' : ''}`; + const wanted = wants.some(w => w.release === r.id); + + const classes = `${added || wanted ? 'added' : ''}`; const btnText = added ? : '+'; @@ -39,6 +44,8 @@ const User = () => { const [results, setResults] = useState([]); const [infoText, setInfoText] = useState(''); + const wants = useSelector((state: State) => state.wants); + async function fetchResults() { const [error, results] = await http.postWantSearch(query); @@ -106,7 +113,7 @@ const User = () => {
{infoEl} - {results.map(Result)} + {results.map(r => Result(r, wants))} {topEl}