Skip to content

Commit

Permalink
Merge pull request #5 from yusupovbg/master
Browse files Browse the repository at this point in the history
Apply updates from production branch
  • Loading branch information
thebkht authored Nov 28, 2023
2 parents 549ac08 + 1fb712b commit e40ee48
Show file tree
Hide file tree
Showing 36 changed files with 328 additions and 310 deletions.
6 changes: 3 additions & 3 deletions app/(Main)/[username]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ export default async function Page({ params, searchParams }: {
{sessionUserName?.id === user?.id ? (
<Tabs className="w-full" defaultValue={tab || "posts"}>
<TabsList className="bg-background w-full py-4 justify-start h-fit rounded-none gap-2 sticky top-[90px] z-10">
<TabsTrigger value="posts" className="bg-muted data-[state=active]:border data-[state=active]:border-foreground">
<TabsTrigger value="posts" className="bg-muted data-[state=active]:bg-secondary-foreground data-[state=active]:shadow-sm data-[state=active]:text-secondary">
Posts
</TabsTrigger>
<TabsTrigger value="bookmarks" className="bg-muted data-[state=active]:border data-[state=active]:border-foreground">
<TabsTrigger value="bookmarks" className="bg-muted data-[state=active]:bg-secondary-foreground data-[state=active]shadow-sm data-[state=active]:text-secondary">
Bookmarks
</TabsTrigger>
<TabsTrigger value="reading-history" className="bg-muted data-[state=active]:border data-[state=active]:border-foreground">
<TabsTrigger value="reading-history" className="bg-muted data-[state=active]:bg-secondary-foreground data-[state=active]:shadow-sm data-[state=active]:text-secondary">
Reading History
</TabsTrigger>
</TabsList>
Expand Down
18 changes: 8 additions & 10 deletions app/(Main)/explore/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SiteFooter } from "@/components/footer"
import { Metadata } from "next"

export const metadata: Metadata = {
title: 'Explore - FalseNotes',
title: 'Explore - FalseNotes',
}

export default function ExploreLayout({
Expand All @@ -12,14 +12,12 @@ export default function ExploreLayout({
children: React.ReactNode
}) {
return (
<>
<div className="md:container mx-auto px-4 pt-5">
<main className="flex flex-col items-center justify-between">
{children}
</main>

</div>
<SiteFooter className="px-3.5" />
</>
<>
<div className="md:container mx-auto px-4 pt-5">
<main className="flex flex-col items-center justify-between">
{children}
</main>
</div>
</>
)
}
5 changes: 0 additions & 5 deletions app/(Main)/tags/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { getSessionUser } from "@/components/get-session-user"
import TagsList from "@/components/tags/list"
import TagBadge from "@/components/tags/tag"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import postgres from "@/lib/postgres"
import { getPopularTags, getTags } from "@/lib/prisma/tags"
import { Hash } from "lucide-react"
import Link from "next/link"

export default async function TagsPage() {
Expand Down
21 changes: 12 additions & 9 deletions app/api/posts/[username]/opengraph-image/route.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @next/next/no-img-element */
import { Icons } from "@/components/icon";
import { ImageResponse } from "next/og";
import { NextRequest, NextResponse } from "next/server";

Expand Down Expand Up @@ -29,20 +28,23 @@ export async function GET(req: NextRequest, { params }: { params: { username: st
regularFont,
boldFont,
]);
try {
const { username } = params
const postUrl = req.nextUrl.searchParams.get("url");
if (!postUrl) {
return NextResponse.json("Missing post url", { status: 400 });
}
const { username } = params;
const postUrl = req.nextUrl.searchParams.get("url");

if (!postUrl) {
return NextResponse.json("Missing post url", { status: 400 });
}

try {
const response = await fetch(`${process.env.DOMAIN}/api/posts/${username}/${postUrl}`);

if (!response.ok) {
return NextResponse.json("Error fetching user data", { status: 500 });

}

const data = await response.json();
const post = data;

return new ImageResponse(
(
post.cover ? (
Expand Down Expand Up @@ -136,7 +138,8 @@ export async function GET(req: NextRequest, { params }: { params: { username: st
},
);
} catch (error) {
console.error(error);
console.error("Error fetching user data", error);
return NextResponse.json("Error occurred", { status: 500 });
}
}

Expand Down
82 changes: 37 additions & 45 deletions components/blog/comments/comment-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardFooter, CardHeader } from "@/components/ui/card";
import UserHoverCard from "@/components/user-hover-card";
import { Heart, MoreHorizontal, Pencil, Reply, Trash2 } from "lucide-react";
import { MoreHorizontal, Pencil, Reply, Trash2 } from "lucide-react";
import Markdown from "markdown-to-jsx";
import Link from "next/link";
import {
Expand All @@ -25,37 +25,8 @@ import { getComment } from "@/lib/prisma/get-comment";
import MarkdownCard from "@/components/markdown-card";
import { Comment } from "@prisma/client";
import { validate } from "@/lib/revalidate";

export function dateFormat(dateString: string | number | Date) {
const date = new Date(dateString);
const currentDate = new Date();

const differenceInTime = currentDate.getTime() - date.getTime();
const differenceInDays = differenceInTime / (1000 * 3600 * 24);

if (differenceInDays < 1) {
const differenceInHours = differenceInTime / (1000 * 3600);
if (differenceInHours < 1) {
const differenceInMinutes = differenceInTime / (1000 * 60);
if (differenceInMinutes < 1) {
const differenceInSeconds = differenceInTime / 1000;
return differenceInSeconds < 30 ? 'Just now': `${Math.floor(differenceInSeconds)}s`;
}
return `${Math.floor(differenceInMinutes)}m`;
}
return `${Math.floor(differenceInHours)}h`;
}

if (differenceInDays > 15) {
return `${date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
})}`;
} else {
return `${Math.floor(differenceInDays)}d`;
}
}
import { dateFormat } from "@/lib/format-date";
import LoginDialog from "@/components/login-dialog";

async function fetchComment(commentId: Comment['id']) {
return await getComment(commentId);
Expand Down Expand Up @@ -99,26 +70,27 @@ export default function CommentCard({ comment: initialComment, post, session, ..
<CardHeader className={`space-y-0 w-full text-sm flex-row items-center p-4 ${comment.parentId && 'pt-0'} px-0`}>
<div className="flex justify-between w-full">
<div className="w-full flex">
<UserHoverCard user={comment.author} className="h-6 w-6 mr-1 md:mr-1.5" >
<UserHoverCard user={comment.author} className="h-10 w-10 mr-1 md:mr-1.5" >
<Link href={`/@${comment.author?.username}`} className="inline-block">
<Avatar className="h-6 w-6 border">
<Avatar className="border">
<AvatarImage src={comment.author?.image} alt={comment.autho?.name} />
<AvatarFallback>{comment.author?.name ? comment.author?.name.charAt(0) : comment.author?.username.charAt(0)}</AvatarFallback>
</Avatar>
</Link>
</UserHoverCard>
<Link href={`/@${comment.author?.username}`} className="flex items-center">
<span className="article__comments-item-author text-sm">{comment.author?.name || comment.author?.username}</span>
{comment.author?.verified &&
<div className="flex flex-col">
<span className="article__comments-item-author text-sm">{comment.author?.name || comment.author?.username} {comment.author?.verified &&
(
<Icons.verified className="h-4 w-4 mx-1 inline fill-primary align-middle" />
)}
)}</span>

<span className="article__comments-item-date text-muted-foreground text-sm !mt-0">{dateFormat(comment.createdAt)}</span>
</div>
{comment.author?.id === post?.authorId && (
<Badge className="ml-1 text-[10px] py-0">Author</Badge>
<Badge className="ml-1 text-xs py-0">Author</Badge>
)}
</Link>
<span className="mx-1.5 !mt-0 text-sm">·</span>
<span className="article__comments-item-date text-muted-foreground text-sm !mt-0">{dateFormat(comment.createdAt)}</span>
</div>
{
session?.id === post.authorId && (
Expand Down Expand Up @@ -166,31 +138,51 @@ export default function CommentCard({ comment: initialComment, post, session, ..
</CardHeader>
<CardContent className="p-4 pt-0 px-0">

<MarkdownCard code={comment.content} />
<MarkdownCard code={comment.content} className="!my-0" />
</CardContent>
<CardFooter className="flex-row items-center justify-between p-4 px-0">
<div className="flex items-center space-x-2">
<div className="flex items-center">
<Button className="h-10 w-10 mr-0.5" size={"icon"} variant={"ghost"} disabled={session?.id == comment.authorId} onClick={() => like(comment.id)} >
<Heart className={`w-5 h-5 ${isLiked && 'fill-current'}`} strokeWidth={2} />
{
session ? (
<Button className="h-10 w-10 mr-0.5" size={"icon"} variant={"ghost"} disabled={session?.id == comment.authorId} onClick={() => like(comment.id)} >
<Icons.like className={`w-6 h-6 ${isLiked && 'fill-current'}`} />
</Button>
) : (
<LoginDialog>
<Button className="h-10 w-10 mr-0.5" size={"icon"} variant={"ghost"} >
<Icons.like className={`w-6 h-6`} />
</Button>
</LoginDialog>
)
}
<span className="text-sm">{formatNumberWithSuffix(comment?._count?.likes)}</span>
</div>
{
comment._count.replies > 0 && (
<div className="flex items-center">
<Button className="h-10 w-10 mr-0.5" size={"icon"} variant={"ghost"} onClick={() => setOpenReply(!openReply)} >
<Reply className="w-5 h-5" strokeWidth={2} />
<Icons.commentBubble className="w-6 h-6" />
</Button>
<span className="text-sm">{comment?._count.replies}</span>
</div>
)
}
</div>
<div className="flex items-center">
<Button className="mr-0.5" variant={"ghost"} onClick={() => setIsReplying(!isReplying)} >
{
session ? (
<Button className="mr-0.5" variant={"ghost"} onClick={() => setIsReplying(!isReplying)} >
Reply
</Button>
) : (
<LoginDialog>
<Button className="mr-0.5" variant={"ghost"} >
Reply
</Button>
</LoginDialog>
)
}
</div>
</CardFooter>
</Card>
Expand Down
3 changes: 2 additions & 1 deletion components/blog/comments/delete-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {

} from "@/components/ui/alert-dialog"
import { Trash2 } from "lucide-react";
import { Icons } from "@/components/icon";


export default function CommentDeleteDialog({ comment, user, ...props }: React.ComponentPropsWithoutRef<typeof AlertDialog> & { comment: any, user: any }) {
Expand All @@ -23,7 +24,7 @@ export default function CommentDeleteDialog({ comment, user, ...props }: React.C
<AlertDialog {...props}>
<AlertDialogContent className="flex flex-col justify-center !w-72 !rounded-lg">
<div className="flex h-20 w-20 items-center justify-center rounded-full bg-muted mx-auto">
<Trash2 className={"h-10 w-10"} strokeWidth={1.25} />
<Icons.trash className={"h-10 w-10"} />
</div>
<div className="flex flex-col space-y-2 text-center sm:text-left mx-auto">
<h1 className="text-lg font-semibold leading-none tracking-tight text-center">Delete Comment</h1>
Expand Down
12 changes: 6 additions & 6 deletions components/blog/feed-post-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BlurImage as Image } from "../image";
import { Button } from "../ui/button";
import Link from "next/link";
import { cn } from "@/lib/utils";
import { Bookmark, MoreHorizontal } from "lucide-react";
import { MoreHorizontal } from "lucide-react";
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar";
import UserHoverCard from "../user-hover-card";
import { Icons } from "../icon";
Expand Down Expand Up @@ -94,13 +94,13 @@ export default function FeedPostCard(
<div className="stats flex items-center justify-around gap-1">
<div className="flex items-center space-x-1 text-muted-foreground text-sm feedpost__action-btn">
<Button variant="ghost" size={"icon"} className=" text-muted-foreground">
<Bookmark className={`h-5 w-5 ${isSaved && 'fill-current'}`} strokeWidth={2} onClick={() => save(props.post.id)} />
<Icons.bookmark className={`h-5 w-5 ${isSaved && 'fill-current'}`} onClick={() => save(props.post.id)} />
<span className="sr-only">Save</span>
</Button>
</div>
<div className="flex items-center space-x-1 text-muted-foreground text-sm feedpost__action-btn">
<Button variant="ghost" size={"icon"} className=" text-muted-foreground">
<ShareList url={`${process.env.DOMAIN}/@${props.post.author.username}/${props.post.url}`} text={props.post.title}>
<ShareList post={props.post.id} url={`${process.env.DOMAIN}/@${props.post.author.username}/${props.post.url}`} text={props.post.title}>
<div>
<MoreHorizontal className="h-5 w-5" />
<span className="sr-only">Share</span>
Expand Down Expand Up @@ -154,15 +154,15 @@ export default function FeedPostCard(
<div className="stats flex items-center justify-around gap-1">
<div className="flex items-center space-x-1 text-muted-foreground text-sm feedpost__action-btn">
<Button variant="ghost" size={"icon"} className=" text-muted-foreground">
<Bookmark className={`h-5 w-5 ${isSaved && 'fill-current'}`} strokeWidth={2} onClick={() => save(props.post.id)} />
<Icons.bookmark className={`h-6 w-6 ${isSaved && 'fill-current'}`} onClick={() => save(props.post.id)} />
<span className="sr-only">Save</span>
</Button>
</div>
<div className="flex items-center space-x-1 text-muted-foreground text-sm feedpost__action-btn">
<Button variant="ghost" size={"icon"} className=" text-muted-foreground">
<ShareList url={`${process.env.DOMAIN}/@${props.post.author.username}/${props.post.url}`} text={props.post.title}>
<ShareList url={`${process.env.DOMAIN}/@${props.post.author.username}/${props.post.url}`} post={props.post.id} text={props.post.title}>
<div>
<MoreHorizontal className="h-5 w-5" />
<Icons.moreHorizontal className="h-6 w-6" />
<span className="sr-only">Share</span>
</div>
</ShareList>
Expand Down
3 changes: 1 addition & 2 deletions components/blog/landing-post-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { BlurImage as Image } from "../image";
import { Button } from "../ui/button";
import Link from "next/link";
import { cn } from "@/lib/utils";
import { Bookmark } from "lucide-react";
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar";
import UserHoverCard from "../user-hover-card";
import { Icons } from "../icon";
Expand Down Expand Up @@ -78,7 +77,7 @@ export default function LandingPostCard(
<div className="flex items-center space-x-1 text-muted-foreground text-sm feedpost__action-btn">
<LoginDialog>
<Button variant="ghost" size={"icon"} className=" text-muted-foreground">
<Bookmark className={`h-5 w-5 `} strokeWidth={2} />
<Icons.bookmark className={`h-5 w-5 `} />
<span className="sr-only">Save</span>
</Button>
</LoginDialog>
Expand Down
Loading

0 comments on commit e40ee48

Please sign in to comment.