login check effect
This commit is contained in:
1 parent
3bd8691ebf
commit
f6f03730e3
5 files changed
+21
-3
No files matched your search
@@ -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
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ async function start() {
|
||||
events,
|
||||
} = createServices(log);
|
||||
|
||||
events.emit(Events.StartupSync);
|
||||
// events.emit(Events.StartupSync);
|
||||
// events.emit(Events.ListingsUpdated);
|
||||
|
||||
api.listen();
|
||||
|
||||
@@ -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<WantsMessage> {
|
||||
return [RpcMessageType.Wants, await pg.userWants(user)];
|
||||
}
|
||||
|
||||
async function offerStatusSet(params: OfferStatusSetParams): Promise<OffersMessage> {
|
||||
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);
|
||||
|
||||
|
||||
@@ -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 = () => (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user