From 015a2fd66c9ac2d9e3c4a5543da76901c7e27ea8 Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 4 Oct 2022 22:41:49 +1100 Subject: [PATCH] fix fetching login routes stuff --- TODO.md | 6 +----- api/src/rpc.ts | 7 ++++++- client/src/app.tsx | 11 ++++++++--- client/src/components/nav.tsx | 15 +++++++++------ client/src/routes/login.tsx | 3 +++ client/src/style/index.less | 1 + 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/TODO.md b/TODO.md index caeffef..5dcebbb 100644 --- a/TODO.md +++ b/TODO.md @@ -1,14 +1,10 @@ # TODO -acp page needs to fetch offers list - -want added -> wants added - spamming discogs and generating offers on every want add +status stepper push offers cover off admin routes and commands - listen / notify on offers notify admins diff --git a/api/src/rpc.ts b/api/src/rpc.ts index d26ba7b..574b208 100644 --- a/api/src/rpc.ts +++ b/api/src/rpc.ts @@ -73,7 +73,7 @@ export default function createRpc(log: Log, pg: Pg, user: User, ws, discogs, off if (!user) { log.debug('anon rpc call'); - return [RpcMessageType.Pong, []]; + return [RpcMessageType.WhoDis, []]; } if (msgType !== RpcMessageType.Ping) log.info({ msgType, params }, 'rpc message'); @@ -137,6 +137,9 @@ export enum RpcMessageType { Ping = 'Ping', Pong = 'Pong', + // points out user is anon + WhoDis = 'WhoDis', + Bundles = 'Bundles', Offers = 'Offers', List = 'List', @@ -156,6 +159,7 @@ export enum RpcMessageType { type ErrorMessage = [RpcMessageType.Error, string]; type PongMessage = [RpcMessageType.Pong, []]; type PingMessage = [RpcMessageType.Ping, []]; +type WhoDisMessage = [RpcMessageType.WhoDis, []]; type UserMessage = [RpcMessageType.User, User]; type WantsMessage = [RpcMessageType.Wants, Want[]]; type OffersMessage = [RpcMessageType.Offers, Offer[]]; @@ -167,6 +171,7 @@ type AcpOffersMessage = [RpcMessageType.AcpOffers, Offer[]]; export type RpcMessage = PingMessage | PongMessage | + WhoDisMessage | UserMessage | diff --git a/client/src/app.tsx b/client/src/app.tsx index cf60a90..cdd5a05 100644 --- a/client/src/app.tsx +++ b/client/src/app.tsx @@ -16,7 +16,6 @@ import List from './routes/list'; import Info from './routes/info'; import store, { userState, wsState, State } from './store' - const Main = () => { const dispatch = useDispatch() @@ -28,10 +27,16 @@ const Main = () => { dispatch(wsState.actions.set(ws)); }, [dispatch]) + function routeChange(e) { + const { ws } = store.getState(); + if (!ws) return null; + if (e.url === '/acp') return ws.sendAcpOffers(); + } + return (
); diff --git a/client/src/components/nav.tsx b/client/src/components/nav.tsx index afc5718..1f748ec 100644 --- a/client/src/components/nav.tsx +++ b/client/src/components/nav.tsx @@ -1,10 +1,10 @@ import { h } from 'preact'; import { route } from 'preact-router'; import { useEffect } from 'preact/hooks'; -import { useSelector, useDispatch } from 'react-redux' +import { useSelector } from 'react-redux' import http from './../http'; -import { State, userState } from './../store'; +import { State } from './../store'; function showAdmin(user) { return user && user.email === 'ntr@mnml.gg'; @@ -13,12 +13,15 @@ function showAdmin(user) { const DEFAULT_ROUTE = '/'; const Nav = () => { - const dispatch = useDispatch() const user = useSelector((state: State) => state.user); useEffect(() => { - if (!user) return route('/login'); - return route(DEFAULT_ROUTE) + if (!user) { + route('/login'); + return; + } + route(DEFAULT_ROUTE) + return; }, [user]) async function logoutClick(e) { @@ -44,7 +47,7 @@ const Nav = () => { const adminNav = () => ( ) diff --git a/client/src/routes/login.tsx b/client/src/routes/login.tsx index 6d3d763..dc420b6 100644 --- a/client/src/routes/login.tsx +++ b/client/src/routes/login.tsx @@ -9,6 +9,7 @@ import { State, userState } from './../store'; const Login = ({ mode }) => { const dispatch = useDispatch() const user = useSelector((state: State) => state.user); + const ws = useSelector((state: State) => state.ws); const [email, setEmail] = useState('') const [password, setPassword] = useState(''); @@ -20,6 +21,8 @@ const Login = ({ mode }) => { if (error) return setError(error); route('/'); dispatch(userState.actions.set(user)); + // reconnect ws to get logged in methods + ws.connect(); } async function postRegister() { diff --git a/client/src/style/index.less b/client/src/style/index.less index fc2efb5..820e068 100644 --- a/client/src/style/index.less +++ b/client/src/style/index.less @@ -150,6 +150,7 @@ button, [type=button], [type=reset], [type=submit] { font-family: var(--secondary-font-family); font-size: var(--small-font-size); + font-weight: bold; text-transform: uppercase; &:hover {