nearly
This commit is contained in:
1 parent
cf01670ee6
commit
0bf75d7faa
7 files changed
+30
-28
No files matched your search
@@ -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;
|
||||||
@@ -2,7 +2,7 @@ import { h } from 'preact';
|
|||||||
import { ExternalLink, Check } from 'react-feather';
|
import { ExternalLink, Check } from 'react-feather';
|
||||||
import { useState } from 'preact/hooks';
|
import { useState } from 'preact/hooks';
|
||||||
|
|
||||||
import actions from '../actions';
|
import http from '../http';
|
||||||
|
|
||||||
export default function Offer(offer) {
|
export default function Offer(offer) {
|
||||||
const { want: { data: details } } = offer;
|
const { want: { data: details } } = offer;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { h } from 'preact';
|
|||||||
import { Square, CheckSquare } from 'react-feather';
|
import { Square, CheckSquare } from 'react-feather';
|
||||||
import { useState, useReducer } from 'preact/hooks';
|
import { useState, useReducer } from 'preact/hooks';
|
||||||
|
|
||||||
import actions from '../actions';
|
import http from '../http';
|
||||||
|
|
||||||
function Item(item, state, dispatch) {
|
function Item(item, state, dispatch) {
|
||||||
const icon = state.checkedIds.includes(item.id)
|
const icon = state.checkedIds.includes(item.id)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { route } from 'preact-router';
|
|||||||
import { connect } from 'unistore/preact'
|
import { connect } from 'unistore/preact'
|
||||||
|
|
||||||
import http from './../http';
|
import http from './../http';
|
||||||
import { actions } from './../store';
|
import { actions } from './../actions';
|
||||||
|
|
||||||
const Header = ({ user, logout }) => {
|
const Header = ({ user, logout }) => {
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { route } from 'preact-router';
|
|||||||
import { connect } from 'unistore/preact'
|
import { connect } from 'unistore/preact'
|
||||||
|
|
||||||
import http from './../http';
|
import http from './../http';
|
||||||
import { actions } from './../store';
|
import { actions } from './../actions';
|
||||||
|
|
||||||
import Offer from './../components/offer';
|
import Offer from './../components/offer';
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useState, useEffect, useRef } from 'preact/hooks';
|
|||||||
import { connect } from 'unistore/preact'
|
import { connect } from 'unistore/preact'
|
||||||
|
|
||||||
import http from './../http';
|
import http from './../http';
|
||||||
import { actions } from './../store';
|
import { actions } from './../actions';
|
||||||
|
|
||||||
const Login = ({ setUser, mode }) => {
|
const Login = ({ setUser, mode }) => {
|
||||||
const [email, setEmail] = useState('')
|
const [email, setEmail] = useState('')
|
||||||
@@ -15,13 +15,15 @@ const Login = ({ setUser, mode }) => {
|
|||||||
async function postLogin() {
|
async function postLogin() {
|
||||||
const [error, user] = await http.postLogin(email, password);
|
const [error, user] = await http.postLogin(email, password);
|
||||||
if (error) return setError(error);
|
if (error) return setError(error);
|
||||||
setUser(user, '/offers');
|
route('/');
|
||||||
|
setUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function postRegister() {
|
async function postRegister() {
|
||||||
const [error, user] = await http.postRegister(email, password);
|
const [error, user] = await http.postRegister(email, password);
|
||||||
if (error) return setError(error);
|
if (error) return setError(error);
|
||||||
setUser(user, '/search');
|
route('/search');
|
||||||
|
setUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSubmit(e) {
|
function handleSubmit(e) {
|
||||||
@@ -50,11 +52,11 @@ const Login = ({ setUser, mode }) => {
|
|||||||
</div>
|
</div>
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<label for="password">password</label>
|
<label for="password">password</label>
|
||||||
<input type="password" name="password" id="password" value={password} required onInput={(e) => setConfirmPassword((e.target as HTMLInputElement).value)} />
|
<input type="password" name="password" id="password" value={password} required onInput={(e) => setPassword((e.target as HTMLInputElement).value)} />
|
||||||
</div>
|
</div>
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<label for="password">confirm password</label>
|
<label for="password">confirm password</label>
|
||||||
<input type="password" name="password" id="password" value={password} required onInput={(e) => setConfirmPassword((e.target as HTMLInputElement).value)} />
|
<input type="password" name="password" id="password" value={confirmPassword} required onInput={(e) => setConfirmPassword((e.target as HTMLInputElement).value)} />
|
||||||
</div>
|
</div>
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<input type="submit" value="register" onClick={handleSubmit} />
|
<input type="submit" value="register" onClick={handleSubmit} />
|
||||||
|
|||||||
+2
-19
@@ -3,27 +3,10 @@ import unistore from 'unistore'
|
|||||||
|
|
||||||
import http from './http';
|
import http from './http';
|
||||||
|
|
||||||
export function createStore() {
|
export default function createStore() {
|
||||||
return unistore({
|
return unistore({
|
||||||
bundles: [],
|
bundles: [],
|
||||||
offers: [],
|
offers: [],
|
||||||
user: null,
|
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 };
|
|
||||||
},
|
|
||||||
});
|
|
||||||
Reference in new issue
Block a user