From f6f03730e3603ad9e26618b7889bb4b818d7173b Mon Sep 17 00:00:00 2001 From: ntr Date: Sun, 18 Sep 2022 21:04:01 +1000 Subject: [PATCH] login check effect --- TODO.md | 3 +++ api/index.ts | 2 +- api/src/rpc.ts | 6 ++++++ client/src/components/header.tsx | 8 ++++++-- client/src/ws.ts | 5 +++++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 9dae747..8497ed6 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,8 @@ # TODO +want added -> wants added + spamming discogs and generating offers on every want add + push offers cover off admin routes and commands 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/rpc.ts b/api/src/rpc.ts index 5726bd3..d26ba7b 100644 --- a/api/src/rpc.ts +++ b/api/src/rpc.ts @@ -27,6 +27,10 @@ export default function createRpc(log: Log, pg: Pg, user: User, ws, discogs, off return [RpcMessageType.Offers, await pg.userOffers(user)]; } + async function userWants(): Promise { + return [RpcMessageType.Wants, await pg.userWants(user)]; + } + async function offerStatusSet(params: OfferStatusSetParams): Promise { const { id, status } = params; assert(id, 'no id supplied'); @@ -82,6 +86,8 @@ export default function createRpc(log: Log, pg: Pg, user: User, ws, discogs, off case RpcMessageType.Offers: return userOffers(); + case RpcMessageType.Wants: + return userWants(); case RpcMessageType.OfferStatusSet: return offerStatusSet(params); diff --git a/client/src/components/header.tsx b/client/src/components/header.tsx index e006dfb..2c17ced 100644 --- a/client/src/components/header.tsx +++ b/client/src/components/header.tsx @@ -1,5 +1,6 @@ import { h } from 'preact'; import { route } from 'preact-router'; +import { useEffect } from 'preact/hooks'; import { useSelector, useDispatch } from 'react-redux' import http from './../http'; @@ -13,11 +14,14 @@ const Header = () => { const dispatch = useDispatch() const user = useSelector((state: State) => state.user); + useEffect(() => { + if (!user) route('/login'); + }, [user]) + async function logoutClick(e) { e.preventDefault(); await http.postLogout(); - route('/login'); - dispatch(userState.actions.set(null)); + window.location.reload(); } const nav = () => ( diff --git a/client/src/ws.ts b/client/src/ws.ts index fbc9f89..69fbe68 100644 --- a/client/src/ws.ts +++ b/client/src/ws.ts @@ -38,6 +38,10 @@ export default function createSocket(dispatch) { send(['Offers', {}]); } + function sendWants() { + send(['Wants', {}]); + } + function sendAcpOffers() { send(['AcpOffers', {}]); } @@ -109,6 +113,7 @@ export default function createSocket(dispatch) { sendPing(); sendAcpOffers(); sendOffers(); + sendWants(); } function onError(event) {