clean up wants flow and http usage

This commit is contained in:
ntr committed 2022-11-28 10:31:37 +11:00
1 parent e74ab36313
commit 631942bb41
8 files changed
+30 -34

No files matched your search

+2
View File
@@ -2,6 +2,8 @@
contact options on landing page contact options on landing page
move want add to rpc
listing ids overflowing listing ids overflowing
skip unofficial release skip unofficial release
+1 -1
View File
@@ -28,7 +28,7 @@ async function start() {
events, events,
} = createServices(log); } = createServices(log);
events.emit(Events.StartupSync); // events.emit(Events.StartupSync);
// events.emit(Events.ListingsUpdated); // events.emit(Events.ListingsUpdated);
api.listen(); api.listen();
-15
View File
@@ -59,13 +59,6 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
ctx.status = 200; 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) { router.post('/want', async function wantPost(ctx, next) {
ctx.assert(ctx.isAuthenticated(), 401, 'log in required'); ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
const { releaseId } = ctx.request.body; const { releaseId } = ctx.request.body;
@@ -85,14 +78,6 @@ export default function createApi(log: Log, pg: Pg, discogs, offers, events) {
ctx.response.body = wants; 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) { router.post('/want/search', async function wantSearch(ctx, next) {
const { query } = ctx.request.body; const { query } = ctx.request.body;
const results = await discogs.search(query); const results = await discogs.search(query);
+1
View File
@@ -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'); log.info({ event: Events.WantsAdded, wants: wants.map(w => wantDetails(w)) }, 'starting listings population');
await updateWantListings(wants); await updateWantListings(wants);
log.info({ event: Events.WantsAdded, wants: wants.map(w => wantDetails(w)) }, 'finished populating listings'); 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() { events.on(Events.StartupSync, async function startupSync() {
+11
View File
@@ -10,6 +10,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@reduxjs/toolkit": "^1.8.5", "@reduxjs/toolkit": "^1.8.5",
"izitoast": "^1.4.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"logrocket": "^3.0.1", "logrocket": "^3.0.1",
"preact": "^10.10.0", "preact": "^10.10.0",
@@ -10844,6 +10845,11 @@
"node": ">=8" "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": { "node_modules/jake": {
"version": "10.8.5", "version": "10.8.5",
"resolved": "https://registry.npmjs.org/jake/-/jake-10.8.5.tgz", "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.5.tgz",
@@ -29566,6 +29572,11 @@
"istanbul-lib-report": "^3.0.0" "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": { "jake": {
"version": "10.8.5", "version": "10.8.5",
"resolved": "https://registry.npmjs.org/jake/-/jake-10.8.5.tgz", "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.5.tgz",
+1
View File
@@ -10,6 +10,7 @@
}, },
"dependencies": { "dependencies": {
"@reduxjs/toolkit": "^1.8.5", "@reduxjs/toolkit": "^1.8.5",
"izitoast": "^1.4.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"logrocket": "^3.0.1", "logrocket": "^3.0.1",
"preact": "^10.10.0", "preact": "^10.10.0",
+4 -15
View File
@@ -32,21 +32,7 @@ function onError(error) {
api.interceptors.response.use(onSuccess, onError); api.interceptors.response.use(onSuccess, onError);
const actions = { const actions = {
getBundles: async function getBundles() { // TODO move to rpc
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');
},
postWantSearch: async function postWantSearch(query) { postWantSearch: async function postWantSearch(query) {
return api.post('/want/search', { query }); return api.post('/want/search', { query });
@@ -60,6 +46,9 @@ const actions = {
return api.post('/want/discogs', { username }); return api.post('/want/discogs', { username });
}, },
// --------------------------------
// require as http to set cookies
getLogin: async function getLogin() { getLogin: async function getLogin() {
return api.get('/auth/login') return api.get('/auth/login')
}, },
+10 -3
View File
@@ -1,10 +1,13 @@
import { h } from 'preact'; import { h } from 'preact';
import { useState, useRef, useEffect } from 'preact/hooks'; import { useState, useRef, useEffect } from 'preact/hooks';
import { ExternalLink, Check } from 'react-feather'; import { ExternalLink, Check } from 'react-feather';
import { useSelector } from 'react-redux'
import { State } from './../store';
import http from '../http'; import http from '../http';
function Result(r) { function Result(r, wants) {
const [added, setAdded] = useState(false) const [added, setAdded] = useState(false)
async function onClick() { async function onClick() {
@@ -13,7 +16,9 @@ function Result(r) {
setAdded(true); setAdded(true);
} }
const classes = `${added ? 'added' : ''}`; const wanted = wants.some(w => w.release === r.id);
const classes = `${added || wanted ? 'added' : ''}`;
const btnText = added const btnText = added
? <Check /> ? <Check />
: '+'; : '+';
@@ -39,6 +44,8 @@ const User = () => {
const [results, setResults] = useState([]); const [results, setResults] = useState([]);
const [infoText, setInfoText] = useState(''); const [infoText, setInfoText] = useState('');
const wants = useSelector((state: State) => state.wants);
async function fetchResults() { async function fetchResults() {
const [error, results] = await http.postWantSearch(query); const [error, results] = await http.postWantSearch(query);
@@ -106,7 +113,7 @@ const User = () => {
</div> </div>
<div class='results'> <div class='results'>
{infoEl} {infoEl}
{results.map(Result)} {results.map(r => Result(r, wants))}
{topEl} {topEl}
</div> </div>
</div> </div>