move to koa and add user pages

This commit is contained in:
ntr committed 2022-08-07 14:27:13 +10:00
1 parent b4114a2440
commit bd32044427
11 files changed
+1079 -107

No files matched your search

+1 -23
View File
@@ -2,35 +2,13 @@ import { h } from 'preact';
import { connect } from 'unistore/preact'
import actions from './../actions';
// import Bundle from './../components/bundle';
import Bundle from './../components/bundle';
interface Props {
bundles: any[];
getBundles: () => void,
}
function Bundle(bundle) {
return (
<div class="bundle">
<h2>{bundle.username} - {bundle.seller}</h2>
<h3>{bundle.items.length} items - {bundle.total} {bundle.currency}</h3>
<h4>Ships: {bundle.mentionsAustralia && 'AU'} {bundle.mentionsWorldwide && 'WORLD'}</h4>
{bundle.items.map(i => (
<div key={i.id}>
<a href={i.uri}>
<h4>{i.description}</h4>
</a>
<h5>{i.user}</h5>
<h5>{i.price} {i.currency}</h5>
<hr />
</div>
))}
</div>
)
}
function Home({ bundles, getBundles }: Props) {
if (!bundles.length) {
getBundles();
-35
View File
@@ -1,35 +0,0 @@
import { h } from 'preact';
import { useEffect, useState } from 'preact/hooks';
import style from './style.less';
interface Props {
user: string;
}
const Profile = ({ user }: Props) => {
const [time, setTime] = useState<number>(Date.now());
const [count, setCount] = useState<number>(0);
useEffect(() => {
let timer = setInterval(() => setTime(Date.now()), 1000);
return () => clearInterval(timer);
}, []);
return (
<div class={'profile'}>
<h1>Profile: {user}</h1>
<p>This is the user profile for a user named { user }.</p>
<div>Current time: {new Date(time).toLocaleString()}</div>
<p>
<button onClick={() => setCount((count) => count + 1)}>Click Me</button>
{' '}
Clicked {count} times.
</p>
</div>
);
};
export default Profile;
+44
View File
@@ -0,0 +1,44 @@
import { h } from 'preact';
import { useState, useEffect } from 'preact/hooks';
import { connect } from 'unistore/preact';
import axios from 'axios';
import style from './style.less';
import actions from './../actions';
import Bundle from './../components/bundle';
interface Props {
userId: string,
offers: any[],
getUserOffers: (userId: string) => void,
}
const User = ({ userId }: Props) => {
const [offers, setOffers] = useState([]);
useEffect(() => {
async function fetchOffers() {
const { data } = await axios.get(`http://localhost:41337/user/${userId}/offers`);
setOffers(data);
}
fetchOffers();
}, [userId]);
if (!offers.length) {
return (
<div class={'home'}>
loading...
</div>
);
}
return (
<div class={'home'}>
{offers.map(Bundle)}
</div>
);
};
export default connect(['offers'], actions)(User);