-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various design improvements + reviews
- Loading branch information
Showing
33 changed files
with
169 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,73 @@ | ||
import { serializer } from "."; | ||
import type { Review, User } from "../db/schema"; | ||
import { inArray } from "drizzle-orm"; | ||
import { serialize, serializer } from "."; | ||
import { db } from "../db"; | ||
import { | ||
bottles, | ||
externalSites, | ||
type Bottle, | ||
type Review, | ||
type User, | ||
} from "../db/schema"; | ||
import { notEmpty } from "../lib/filter"; | ||
import { BottleSerializer } from "./bottle"; | ||
import { ExternalSiteSerializer } from "./externalSite"; | ||
|
||
type ReviewAttrs = { | ||
bottle: ReturnType<(typeof BottleSerializer)["item"]> | null; | ||
site: ReturnType<(typeof ExternalSiteSerializer)["item"]>; | ||
}; | ||
|
||
export const ReviewSerializer = serializer({ | ||
item: (item: Review, attrs: Record<string, any>, currentUser?: User) => { | ||
attrs: async ( | ||
itemList: (Review & { bottle: Bottle })[], | ||
currentUser?: User, | ||
): Promise<Record<string, ReviewAttrs>> => { | ||
const bottleIds = Array.from( | ||
new Set(itemList.map((i) => i.bottleId).filter(notEmpty)), | ||
); | ||
const bottleList = bottleIds.length | ||
? await db.select().from(bottles).where(inArray(bottles.id, bottleIds)) | ||
: []; | ||
const bottlesByRef = Object.fromEntries( | ||
(await serialize(BottleSerializer, bottleList, currentUser)).map( | ||
(data, index) => [bottleList[index].id, data], | ||
), | ||
); | ||
|
||
const siteIds = Array.from(new Set(itemList.map((i) => i.externalSiteId))); | ||
const siteList = siteIds.length | ||
? await db | ||
.select() | ||
.from(externalSites) | ||
.where(inArray(externalSites.id, siteIds)) | ||
: []; | ||
const sitesByRef = Object.fromEntries( | ||
(await serialize(ExternalSiteSerializer, siteList, currentUser)).map( | ||
(data, index) => [siteList[index].id, data], | ||
), | ||
); | ||
|
||
return Object.fromEntries( | ||
itemList.map((item) => { | ||
return [ | ||
item.id, | ||
{ | ||
bottle: item.bottleId ? bottlesByRef[item.bottleId] : null, | ||
site: sitesByRef[item.externalSiteId], | ||
}, | ||
]; | ||
}), | ||
); | ||
}, | ||
|
||
item: (item: Review, attrs: ReviewAttrs, currentUser?: User) => { | ||
return { | ||
id: item.id, | ||
name: item.name, | ||
rating: item.rating, | ||
url: item.url, | ||
bottle: attrs.bottle, | ||
site: attrs.site, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { TrophyIcon } from "@heroicons/react/24/outline"; | ||
import { trpc } from "../lib/trpc"; | ||
|
||
function RatingIcon({ rating }: { rating: number }) { | ||
if (rating > 93) return <TrophyIcon className="text-highlight h-4 w-4" />; | ||
if (rating > 87) return <TrophyIcon className="h-4 w-4 text-gray-400" />; | ||
if (rating > 83) return <TrophyIcon className="h-4 w-4 text-orange-400" />; | ||
return null; | ||
} | ||
|
||
export default function BottleReviews({ bottleId }: { bottleId: number }) { | ||
const { data } = trpc.reviewList.useQuery({ | ||
bottle: bottleId, | ||
}); | ||
|
||
if (!data) return null; | ||
|
||
const { results } = data; | ||
|
||
if (!results.length) return null; | ||
|
||
return ( | ||
<> | ||
<h3 className="text-highlight text-lg font-bold">The Critics</h3> | ||
<ul className="-mx-2 grid w-2/3 grid-cols-2 md:w-1/2"> | ||
{results.map((r) => { | ||
return ( | ||
<li | ||
key={r.id} | ||
className="relative col-span-3 grid grid-cols-subgrid items-center gap-x-2 gap-y-2 p-2 hover:bg-slate-800" | ||
> | ||
<a href={r.url} className="absolute inset-0" /> | ||
<span className="flex items-center gap-x-2">{r.site.name}</span> | ||
<span className="flex items-center justify-end gap-x-2"> | ||
<RatingIcon rating={r.rating} /> | ||
<span>{r.rating} points</span> | ||
</span> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.