remove unused api methods
This commit is contained in:
1 parent
73248f7d9f
commit
acf7e54be9
10 files changed
+23
-201
No files matched your search
+4
-7
@@ -5,13 +5,11 @@ import { Route, Router, route } from 'preact-router';
|
||||
import { Provider } from 'react-redux'
|
||||
|
||||
import createWs from './ws';
|
||||
import http from './http';
|
||||
|
||||
import Header from './components/header';
|
||||
|
||||
import Home from './routes/home';
|
||||
import Bundles from './routes/bundles';
|
||||
import Admin from './routes/acp';
|
||||
import Offers from './routes/offers';
|
||||
import Acp from './routes/acp';
|
||||
import Login from './routes/login';
|
||||
import Search from './routes/search';
|
||||
import List from './routes/list';
|
||||
@@ -33,15 +31,14 @@ const Main = () => {
|
||||
<main id="app">
|
||||
<Header />
|
||||
<Router>
|
||||
<Route path="/" component={Home} />
|
||||
<Route path="/" component={Offers} />
|
||||
<Route path="/login" component={Login} mode="login" />
|
||||
<Route path="/register" component={Login} mode="register" />
|
||||
<Route path="/search" component={Search} />
|
||||
<Route path="/list" component={List} />
|
||||
|
||||
{/* ACP */}
|
||||
<Route path="/bundles" component={Bundles} />
|
||||
<Route path="/offers/acp" component={Admin} />
|
||||
<Route path="/offers/acp" component={Acp} />
|
||||
</Router>
|
||||
</main>
|
||||
);
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
import { h } from 'preact';
|
||||
import { Square, CheckSquare } from 'react-feather';
|
||||
import { useState, useReducer } from 'preact/hooks';
|
||||
|
||||
import http from '../http';
|
||||
|
||||
function Item(item, state, dispatch) {
|
||||
const icon = state.checkedIds.includes(item.id)
|
||||
? <CheckSquare onClick={() => dispatch({ id: item.id})} />
|
||||
: <Square onClick={() => dispatch({ id: item.id})} />;
|
||||
|
||||
return (
|
||||
<div key={item.id}>
|
||||
<a href={item.uri} target="_blank" >
|
||||
<h4>{item.description}</h4>
|
||||
</a>
|
||||
<h5 class='alt-text'>{item.price.toFixed(2)} {item.currency}</h5>
|
||||
{icon}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const reducer = (state, action) => {
|
||||
if (state.checkedIds.includes(action.id)) {
|
||||
return {
|
||||
...state,
|
||||
checkedIds: state.checkedIds.filter(id => id !== action.id)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
checkedIds: [
|
||||
...state.checkedIds,
|
||||
action.id
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
export default function Bundle(bundle) {
|
||||
const initialState = { checkedIds: bundle.items.map(i => i.id) }
|
||||
const [state, dispatch] = useReducer(reducer, initialState)
|
||||
|
||||
const items = bundle.items.map(item => Item(item, state, dispatch));
|
||||
|
||||
return (
|
||||
<div class="bundle">
|
||||
<section>
|
||||
<h2>{bundle.username} - {bundle.seller}</h2>
|
||||
<h3>{bundle.items.length} items - {bundle.total.toFixed(2)} {bundle.currency}</h3>
|
||||
<h4>Ships: {bundle.mentionsAustralia && 'AU'} {bundle.mentionsWorldwide && 'WORLD'}</h4>
|
||||
</section>
|
||||
<div class='items'>
|
||||
{items}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -37,7 +37,6 @@ const Header = () => {
|
||||
|
||||
const adminNav = () => (
|
||||
<nav>
|
||||
<a href="/bundles">Bundles</a>
|
||||
<a href='/offers/acp'>Offers ACP</a>
|
||||
</nav>
|
||||
)
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import { h } from 'preact';
|
||||
import { useState, useEffect } from 'preact/hooks';
|
||||
|
||||
import http from './../http';
|
||||
import Bundle from './../components/bundle';
|
||||
|
||||
function Bundles() {
|
||||
const [bundles, setBundles] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
async function getBundles() {
|
||||
const [error, bundles] = await http.getBundles();
|
||||
if (error) return console.error(error);
|
||||
setBundles(bundles);
|
||||
}
|
||||
getBundles();
|
||||
}, []);
|
||||
|
||||
if (!bundles.length) {
|
||||
return (
|
||||
<div class={'bundles'}>
|
||||
loading...
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div class={'bundles'}>
|
||||
{bundles.map(Bundle)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Bundles;
|
||||
@@ -1,41 +0,0 @@
|
||||
import { h } from 'preact';
|
||||
import { useState, useEffect } from 'preact/hooks';
|
||||
import { route } from 'preact-router';
|
||||
import { useSelector, useDispatch } from 'react-redux'
|
||||
|
||||
import http from './../http';
|
||||
import { State, offersState } from './../store';
|
||||
|
||||
import Offer from './../components/offer';
|
||||
|
||||
function Home() {
|
||||
const dispatch = useDispatch()
|
||||
const offers = useSelector((state: State) => state.offers);
|
||||
|
||||
useEffect(() => {
|
||||
async function getOffers() {
|
||||
const [error, offers] = await http.getOffers();
|
||||
if (error) return console.error(error);
|
||||
dispatch(offersState.actions.set(offers));
|
||||
if (offers.length === 0) route('/search');
|
||||
}
|
||||
getOffers();
|
||||
}, []);
|
||||
|
||||
if (!offers.length) {
|
||||
return (
|
||||
<div class={'offers'}>
|
||||
loading...
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div class={'offers'}>
|
||||
{offers.map(Offer)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Home;
|
||||
@@ -1,11 +1,8 @@
|
||||
import { h } from 'preact';
|
||||
import { useState, useEffect } from 'preact/hooks';
|
||||
|
||||
import { useSelector } from 'react-redux'
|
||||
import { State } from './../store'
|
||||
|
||||
// import style from './style.less';
|
||||
import http from './../http';
|
||||
import Want from './../components/want';
|
||||
|
||||
interface Props {
|
||||
|
||||
@@ -34,6 +34,10 @@ export default function createSocket(dispatch) {
|
||||
send(['WantRm', { id }]);
|
||||
}
|
||||
|
||||
function sendOffers() {
|
||||
send(['Offers', {}]);
|
||||
}
|
||||
|
||||
function sendAcpOffers() {
|
||||
send(['AcpOffers', {}]);
|
||||
}
|
||||
@@ -104,6 +108,7 @@ export default function createSocket(dispatch) {
|
||||
console.log('websocket connected', SOCKET_URL)
|
||||
sendPing();
|
||||
sendAcpOffers();
|
||||
sendOffers();
|
||||
}
|
||||
|
||||
function onError(event) {
|
||||
@@ -143,6 +148,8 @@ export default function createSocket(dispatch) {
|
||||
sendOfferStatusSet,
|
||||
sendWantRm,
|
||||
|
||||
sendOffers,
|
||||
|
||||
sendAcpOffers,
|
||||
sendAcpOfferStatusSet,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user