fix fetching login routes stuff
This commit is contained in:
1 parent
77428aa7de
commit
015a2fd66c
6 files changed
+28
-15
No files matched your search
@@ -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
|
||||
|
||||
+6
-1
@@ -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 |
|
||||
|
||||
|
||||
+8
-3
@@ -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 (
|
||||
<main id="app">
|
||||
<Nav />
|
||||
<Router>
|
||||
<Router onChange={routeChange}>
|
||||
<Route path="/" component={Offers} />
|
||||
<Route path="/login" component={Login} mode="login" />
|
||||
<Route path="/register" component={Login} mode="register" />
|
||||
@@ -40,7 +45,7 @@ const Main = () => {
|
||||
<Route path="/info" component={Info} />
|
||||
|
||||
{/* ACP */}
|
||||
<Route path="/offers/acp" component={Acp} />
|
||||
<Route path="/acp" component={Acp} />
|
||||
</Router>
|
||||
</main>
|
||||
);
|
||||
|
||||
@@ -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 = () => (
|
||||
<nav>
|
||||
<a href='/offers/acp'>Offers ACP</a>
|
||||
<a href='/acp'>Offers ACP</a>
|
||||
</nav>
|
||||
)
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user