Skip to content

Commit

Permalink
love you corban
Browse files Browse the repository at this point in the history
  • Loading branch information
irem-naz authored and corbanvilla committed Sep 22, 2024
1 parent 436346f commit 967af3a
Show file tree
Hide file tree
Showing 3 changed files with 2,132 additions and 647 deletions.
13 changes: 13 additions & 0 deletions app/archives/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const runtime = 'nodejs';
export const preferredRegion = 'fra1';
export const dynamic = 'error';

import Image from "next/image";
import Link from "next/link";
import { format, parse } from "date-fns";
import { Metadata } from "next";
Expand All @@ -15,6 +16,7 @@ import {
DATABASE_DATE_FORMAT,
ARTICLE_DATE_FORMAT,
DEFAULT_ISSUE_DATE,
ARTICLE_DEFAULT_IMAGE,
} from '../../env';

export const metadata: Metadata = {
Expand All @@ -30,6 +32,16 @@ const IssueCard = ({ issue }: { issue: IssueArchive }) => {
return (
<div className="flex flex-col justify-center w-[300px] m-4 text-center group hover:text-sky-600">
<Link href={`/issue/${issue.issueNumber}`}>
<Image
priority={true}
src={issue.imageUrl || ARTICLE_DEFAULT_IMAGE}
// fill
width={300}
height={300}
alt={issue.imageUrl}
className="aspect-[16/9] object-cover"
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
/>
<h1 className="font-normal text-2xl mt-1">
{issue.issueName}
</h1>
Expand All @@ -46,6 +58,7 @@ const IssueCard = ({ issue }: { issue: IssueArchive }) => {

export default async function Page() {
const issues = await getIssueArchive();


return (
<div className="flex flex-col items-center justify-center">
Expand Down
16 changes: 14 additions & 2 deletions db/queries/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@ import {
Issues,
Categories,
IssuesCategoriesOrder,
IssuesArticlesOrder,
wrapCache,
Articles,
} from '../common';

import { eq, isNotNull, desc } from 'drizzle-orm/expressions';
import { eq, isNotNull, and, desc } from 'drizzle-orm/expressions';

type Issue = {
id: number;
issueNumber: number;
issueName: string;
publishedAt: string | null;
imageUrl: string;
}

export type IssueArchive = {
issueNumber: number;
issueName: string;
publishedAt: string | null;
imageUrl: string;
}
// NOTE - Caching is per request
export const getLatestPublishedIssue = wrapCache(async () => {
Expand Down Expand Up @@ -89,9 +93,17 @@ export const getIssueArchive = wrapCache(async () => {
issueNumber: Issues.issueNumber,
issueName: Issues.name,
publishedAt: Issues.published_at,
imageUrl: Articles.imageUrl
})
.from(Issues)
.where(isNotNull(Issues.published_at))
.innerJoin(IssuesArticlesOrder, eq(IssuesArticlesOrder.issueId, Issues.id) )
.innerJoin(Articles, eq(Articles.id, IssuesArticlesOrder.articleId))
.where(
and(
eq(IssuesArticlesOrder.type, 1),
isNotNull(Issues.published_at)
)
)
.orderBy(desc(Issues.id));

return issues;
Expand Down
Loading

0 comments on commit 967af3a

Please sign in to comment.