From 0bf75d7faa05c064f9f511e573c2bf50236cbbf3 Mon Sep 17 00:00:00 2001 From: ntr Date: Sat, 3 Sep 2022 15:03:16 +1000 Subject: [PATCH] nearly --- client/src/actions.tsx | 17 +++++++++++++++++ client/src/components/acp.offer.tsx | 2 +- client/src/components/bundle.tsx | 2 +- client/src/components/header.tsx | 2 +- client/src/routes/home.tsx | 2 +- client/src/routes/login.tsx | 12 +++++++----- client/src/store.tsx | 21 ++------------------- 7 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 client/src/actions.tsx diff --git a/client/src/actions.tsx b/client/src/actions.tsx new file mode 100644 index 0000000..0b52797 --- /dev/null +++ b/client/src/actions.tsx @@ -0,0 +1,17 @@ +const actions = store => ({ + setUser: function setUser(state, user) { + return { user }; + }, + + setOffers: function setOffers(state, offers) { + return { offers }; + }, + + logout: async function logout(store, e) { + await http.postLogout(); + route('/login'); + return { user: null }; + }, +}); + +export default actions; diff --git a/client/src/components/acp.offer.tsx b/client/src/components/acp.offer.tsx index 3cfcacc..125f677 100644 --- a/client/src/components/acp.offer.tsx +++ b/client/src/components/acp.offer.tsx @@ -2,7 +2,7 @@ import { h } from 'preact'; import { ExternalLink, Check } from 'react-feather'; import { useState } from 'preact/hooks'; -import actions from '../actions'; +import http from '../http'; export default function Offer(offer) { const { want: { data: details } } = offer; diff --git a/client/src/components/bundle.tsx b/client/src/components/bundle.tsx index 1d2ad6d..4fc8a96 100644 --- a/client/src/components/bundle.tsx +++ b/client/src/components/bundle.tsx @@ -2,7 +2,7 @@ import { h } from 'preact'; import { Square, CheckSquare } from 'react-feather'; import { useState, useReducer } from 'preact/hooks'; -import actions from '../actions'; +import http from '../http'; function Item(item, state, dispatch) { const icon = state.checkedIds.includes(item.id) diff --git a/client/src/components/header.tsx b/client/src/components/header.tsx index 1ec63fb..8d02e61 100644 --- a/client/src/components/header.tsx +++ b/client/src/components/header.tsx @@ -3,7 +3,7 @@ import { route } from 'preact-router'; import { connect } from 'unistore/preact' import http from './../http'; -import { actions } from './../store'; +import { actions } from './../actions'; const Header = ({ user, logout }) => { diff --git a/client/src/routes/home.tsx b/client/src/routes/home.tsx index d512666..198e1e4 100644 --- a/client/src/routes/home.tsx +++ b/client/src/routes/home.tsx @@ -4,7 +4,7 @@ import { route } from 'preact-router'; import { connect } from 'unistore/preact' import http from './../http'; -import { actions } from './../store'; +import { actions } from './../actions'; import Offer from './../components/offer'; diff --git a/client/src/routes/login.tsx b/client/src/routes/login.tsx index 864c406..47e28f6 100644 --- a/client/src/routes/login.tsx +++ b/client/src/routes/login.tsx @@ -4,7 +4,7 @@ import { useState, useEffect, useRef } from 'preact/hooks'; import { connect } from 'unistore/preact' import http from './../http'; -import { actions } from './../store'; +import { actions } from './../actions'; const Login = ({ setUser, mode }) => { const [email, setEmail] = useState('') @@ -15,13 +15,15 @@ const Login = ({ setUser, mode }) => { async function postLogin() { const [error, user] = await http.postLogin(email, password); if (error) return setError(error); - setUser(user, '/offers'); + route('/'); + setUser(user); } async function postRegister() { const [error, user] = await http.postRegister(email, password); if (error) return setError(error); - setUser(user, '/search'); + route('/search'); + setUser(user); } function handleSubmit(e) { @@ -50,11 +52,11 @@ const Login = ({ setUser, mode }) => {
- setConfirmPassword((e.target as HTMLInputElement).value)} /> + setPassword((e.target as HTMLInputElement).value)} />
- setConfirmPassword((e.target as HTMLInputElement).value)} /> + setConfirmPassword((e.target as HTMLInputElement).value)} />
diff --git a/client/src/store.tsx b/client/src/store.tsx index ef0da81..51546d6 100644 --- a/client/src/store.tsx +++ b/client/src/store.tsx @@ -3,27 +3,10 @@ import unistore from 'unistore' import http from './http'; -export function createStore() { +export default function createStore() { return unistore({ bundles: [], offers: [], user: null, }); -} - -export const actions = store => ({ - setUser: async function setUser(state, user, dest) { - route(dest); - return { user }; - }, - - setOffers: async function setOffers(state, offers) { - return { offers }; - }, - - logout: async function logout(store, e) { - await http.postLogout(); - route('/login'); - return { user: null }; - }, -}); +};