offer groups with status
This commit is contained in:
1 parent
b199ce94c1
commit
15a84d6eea
6 files changed
+28
-43
No files matched your search
+1
-1
@@ -28,7 +28,7 @@ async function start() {
|
|||||||
events,
|
events,
|
||||||
} = createServices(log);
|
} = createServices(log);
|
||||||
|
|
||||||
events.emit(Events.StartupSync);
|
// events.emit(Events.StartupSync);
|
||||||
// events.emit(Events.ListingsUpdated);
|
// events.emit(Events.ListingsUpdated);
|
||||||
|
|
||||||
api.listen();
|
api.listen();
|
||||||
|
|||||||
+14
-1
@@ -149,7 +149,20 @@ export default function createOffers(log: Log, pg: Pg) {
|
|||||||
|
|
||||||
async function userOffers(user: User) {
|
async function userOffers(user: User) {
|
||||||
const offers = await pg.userOffers(user);
|
const offers = await pg.userOffers(user);
|
||||||
return groupBy(offers, (o) => o.wantId);
|
const groups = Object.values(groupBy(offers, (o) => o.wantId))
|
||||||
|
.map(g => {
|
||||||
|
const offers = sortBy(g, sortOffers);
|
||||||
|
const status = offers[0].status;
|
||||||
|
const details = offers[0].want.data;
|
||||||
|
|
||||||
|
return {
|
||||||
|
details,
|
||||||
|
offers,
|
||||||
|
status,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
+3
-27
@@ -11,33 +11,7 @@ export interface UserCreateParams {
|
|||||||
password: string,
|
password: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Pg {
|
export default function createPg(log: Log, prisma: PrismaClient) {
|
||||||
userFindId: (id: UUID) => Promise<User>,
|
|
||||||
userFindEmail: (email: Email) => Promise<User>,
|
|
||||||
userCreate: (params: UserCreateParams) => Promise<User>,
|
|
||||||
userWants: (user: User) => Promise<Want[]>,
|
|
||||||
userOffers: (user: User) => Promise<Offer[]>,
|
|
||||||
userOfferFind: (user: User, id: UUID) => Promise<Offer>,
|
|
||||||
|
|
||||||
listingUpsert: (listing: Listing, want: Want) => Promise<Listing>,
|
|
||||||
listingFind: (id: DiscogsListing) => Promise<Listing>,
|
|
||||||
listingByIds: (ids: DiscogsListing[]) => Promise<Listing[]>,
|
|
||||||
listingRmUnlisted: (want: Want, ids: DiscogsListing[]) => Promise<number>,
|
|
||||||
|
|
||||||
wantCreate: (discogsWant: any, user: User) => Promise<Want>,
|
|
||||||
wantList: (user: User) => Promise<Want[]>,
|
|
||||||
wantsToSync: () => Promise<Want[]>,
|
|
||||||
wantRm: (id: UUID) => Promise<void>,
|
|
||||||
|
|
||||||
bundleCandidates: () => Promise<Listing[][]>,
|
|
||||||
|
|
||||||
offersCreate: (offers: Offer[]) => Promise<Offer[]>,
|
|
||||||
offerStatusSet: (id: UUID, status: Status) => Promise<Offer>,
|
|
||||||
offersAdmin: () => Promise<Offer[]>,
|
|
||||||
offerFindId: (id: UUID) => Promise<Offer>,
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function createPg(log: Log, prisma: PrismaClient): Pg {
|
|
||||||
async function userFindId(id: UUID) {
|
async function userFindId(id: UUID) {
|
||||||
return prisma.user.findUnique({ where: { id }});
|
return prisma.user.findUnique({ where: { id }});
|
||||||
}
|
}
|
||||||
@@ -325,3 +299,5 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
|
|||||||
offerFindId,
|
offerFindId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Pg = ReturnType<typeof createPg>;
|
||||||
@@ -55,23 +55,21 @@ function OfferPriceBtn(offer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default function WantOffers(wantOffers, i) {
|
export default function OfferGroup(group, i) {
|
||||||
const ws = useSelector((state: State) => state.ws);
|
const ws = useSelector((state: State) => state.ws);
|
||||||
|
|
||||||
const details = wantOffers[0].want.data;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="offer" key={i}>
|
<div class="offer" key={i}>
|
||||||
<section>
|
<section>
|
||||||
<h3>{details.artists_sort} - {details.title} <a href={details.uri} target="_blank"><ExternalLink /></a></h3>
|
<h3>{group.details.artists_sort} - {group.details.title} <a href={group.details.uri} target="_blank"><ExternalLink /></a></h3>
|
||||||
<div class='alt-text details'>
|
<div class='alt-text details'>
|
||||||
{details.year} - {details.formats.map(f => f.descriptions.join(' ')).join(' ')}
|
{group.details.year} - {group.details.formats.map(f => f.descriptions.join(' ')).join(' ')}
|
||||||
</div>
|
</div>
|
||||||
<div class='alt-text details'>Status: {wantOffers[0].status}</div>
|
<div class='alt-text details'>Status: {group.status}</div>
|
||||||
</section>
|
</section>
|
||||||
<img src={details.thumb} />
|
<img src={group.details.thumb} />
|
||||||
<div class="lines">
|
<div class="lines">
|
||||||
{wantOffers.map(o => OfferPriceBtn(o))}
|
{group.offers.map(o => OfferPriceBtn(o))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -6,21 +6,19 @@ import { useSelector, useDispatch } from 'react-redux'
|
|||||||
import http from './../http';
|
import http from './../http';
|
||||||
import { State, offersState } from './../store';
|
import { State, offersState } from './../store';
|
||||||
|
|
||||||
import WantOffers from './../components/want.offers';
|
import OfferGroup from './../components/offer.group';
|
||||||
|
|
||||||
function Home() {
|
function Home() {
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const offers = useSelector((state: State) => state.offers);
|
const offers = useSelector((state: State) => state.offers);
|
||||||
|
|
||||||
const groups = Object.values(offers);
|
if (offers && offers.length === 0) {
|
||||||
|
|
||||||
if (offers && !groups.length) {
|
|
||||||
route('/search');
|
route('/search');
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={'offers'}>
|
<div class={'offers'}>
|
||||||
{groups.map(WantOffers)}
|
{offers.map(OfferGroup)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export const userState = createSlice({
|
|||||||
|
|
||||||
export const offersState = createSlice({
|
export const offersState = createSlice({
|
||||||
name: 'offers',
|
name: 'offers',
|
||||||
initialState: {},
|
initialState: [],
|
||||||
reducers: {
|
reducers: {
|
||||||
set: (state, action) => action.payload
|
set: (state, action) => action.payload
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user