Skip to content

Commit

Permalink
chore: separate to content card
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed Apr 24, 2024
1 parent 130e5e5 commit 943b124
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 70 deletions.
90 changes: 20 additions & 70 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
/* eslint-disable tailwindcss/no-custom-classname */
"use client";

import { ChevronDown, ChevronUp, CircleX, MessageSquareMore, PencilLine, Share2 } from "lucide-react";
import Image from "next/image";
import { useEffect, useState } from "react";
import { ContentCard } from "@/components/ContentCard";
import { PencilLine } from "lucide-react";

export default function Home() {
const [image, imageState] = useState(false);

useEffect(() => {
const handleOutsideClick = (event: MouseEvent) => {
const target = event.target;
if (image && target instanceof HTMLElement && !target.closest(".image-container")) {
imageState(false);
}
};

document.addEventListener("mousedown", e => handleOutsideClick(e));

return () => {
document.removeEventListener("mousedown", handleOutsideClick);
};
}, [image]);

return (
<>
<div className="container relative flex w-full flex-col gap-2 p-10 lg:max-w-6xl">
Expand All @@ -31,57 +13,25 @@ export default function Home() {
</a>

<div className="flex flex-col gap-4">
<div className="flex w-full cursor-pointer flex-col-reverse gap-6 rounded-md p-2 hover:bg-[#12372A40] md:p-4 lg:w-3/4">
<div className="flex h-10 flex-row items-center justify-between">
<div className="flex h-full w-fit flex-row items-center gap-1 rounded-full bg-[#1B1B1B] px-4 text-sm text-white md:text-lg">
<ChevronUp strokeWidth={3} color="green" />
<p>2.5K</p>
<ChevronDown strokeWidth={3} color="red" />
</div>

<div className="flex h-full flex-row gap-1">
<div className="flex h-full w-fit flex-row items-center gap-1 rounded-full bg-[#1B1B1B] px-4 text-white">
<MessageSquareMore size={22} color="white" />
<p>36</p>
</div>

<div className="flex h-full flex-row items-center gap-1 rounded-full bg-[#1B1B1B] p-2 text-white">
<Share2 />
</div>
</div>
</div>

<div className="flex flex-col gap-3">
<div className="flex h-12 flex-row gap-2">
<Image width={512} height={512} className="size-10 rounded-full" alt="User" src={"https://cdn.discordapp.com/avatars/597678468280614922/a39daa2dd7e9bea3c68ac80515f3c45a.png?size=1024"} />
<p className="flex flex-col text-white">
<span className="font-bold">fs/AskForesia</span>
<span className="-mt-1 text-gray-400">Posted by ArkanDash</span>
</p>
</div>
<p className="text-white">
<span className="line-clamp-1 text-lg font-bold md:text-2xl">
Why does KannaChan is a Cute characters?
</span>
<span className="line-clamp-3 text-xs text-gray-400 md:text-sm">
Kanna Kamui (神凪 カンナ, Kanna Kamui) is a young dragon girl from the world of dragons who becomes Miss Kobayashi adopted daughter.
<ContentCard
avatar="https://cdn.discordapp.com/avatars/597678468280614922/a39daa2dd7e9bea3c68ac80515f3c45a.png?size=1024"
user="ArkanDash"
community="AskForesia"
image="https://cdn.discordapp.com/attachments/1174136474250248204/1231795766776041534/th.png?ex=66384234&is=6625cd34&hm=01c577b8c91847fe94d93f8c5a3055993ba38dd9b73a4f808739341418b300a8&"
title="Why does KannaChan is a Cute characters?"
description="Kanna Kamui (神凪 カンナ, Kanna Kamui) is a young dragon girl from the world of dragons who becomes Miss Kobayashi adopted daughter.
Kanna has long, white hair with a distinctive ahoge (a single strand of hair that sticks up) and bright blue eyes.
She often wears a school uniform or a casual outfit with a tail accessory. In her dragon form, she has white scales and powerful wings.
</span>
</p>
{
image && <>
<div className="fixed inset-0 z-[90] overflow-y-auto backdrop-blur-sm">
<CircleX className="absolute right-0 top-0 m-4 cursor-pointer text-white" size={32} onClick={() => imageState(false)} />
<div className="flex min-h-screen items-center justify-center">
<Image className="image-container" height={1920} width={1280} alt="Content" src={"https://cdn.discordapp.com/attachments/1174136474250248204/1231795766776041534/th.png?ex=66384234&is=6625cd34&hm=01c577b8c91847fe94d93f8c5a3055993ba38dd9b73a4f808739341418b300a8&"} />
</div>
</div>
</>
}
<Image onClick={() => imageState(true)} height={1920} width={1280} className="h-48 rounded-lg object-cover md:h-[22rem]" alt="Content" src={"https://cdn.discordapp.com/attachments/1174136474250248204/1231795766776041534/th.png?ex=66384234&is=6625cd34&hm=01c577b8c91847fe94d93f8c5a3055993ba38dd9b73a4f808739341418b300a8&"} />
</div>
</div>
She often wears a school uniform or a casual outfit with a tail accessory. In her dragon form, she has white scales and powerful wings."
key="1" />

<ContentCard
avatar="https://cdn.discordapp.com/avatars/597678468280614922/a39daa2dd7e9bea3c68ac80515f3c45a.png?size=1024"
user="ArkanDash"
community="BlueArchive"
image="https://cdn.discordapp.com/attachments/1174136474250248204/1231799616253722757/artwork.png?ex=663845ca&is=6625d0ca&hm=4fd68774b50b025129bf4a23bfe03c7bbaad99e104aeab24af25dfc8c21056b6&&w=1920&q=75"
title="Why does Arisu is a Cute characters?"
description="Student of Millennium and member of the Game development club. She was found sleeping inside some ruins. Everything about her is unknown, including her age. Currently, she enjoys playing videogames with Momoi, Midori and Yuzu and has become a serious game maniac. Because she picks up lines from retro games, her speech tends to be hesitant and unnatural."
key="1" />
</div>
</div>
</>
Expand Down
89 changes: 89 additions & 0 deletions src/components/ContentCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* eslint-disable tailwindcss/no-custom-classname */
import { ChevronUp, ChevronDown, MessageSquareMore, Share2, CircleX } from "lucide-react";
import Image from "next/image";
import { useEffect, useState } from "react";

interface ContentCardProps {
key: string;

title: string;
description: string;
image: string;

avatar: string;
user: string;
community: string;

// href: string;
}

export const ContentCard = (props: ContentCardProps) => {
const [fullscreenState, setFullscreenState] = useState(false);

useEffect(() => {
const handleOutsideClick = (event: MouseEvent) => {
const target = event.target;
if (fullscreenState && target instanceof HTMLElement && !target.closest(`.${props.key}-image-container`)) {
setFullscreenState(false);
}
};

document.addEventListener("mousedown", e => handleOutsideClick(e));

return () => {
document.removeEventListener("mousedown", handleOutsideClick);
};
}, [fullscreenState, props.key]);

return (
<div className="flex w-full cursor-pointer flex-col-reverse gap-6 rounded-md p-2 hover:bg-[#12372A40] md:p-4 lg:w-3/4">
<div className="flex h-10 flex-row items-center justify-between">
<div className="flex h-full w-fit flex-row items-center gap-1 rounded-full bg-[#1B1B1B] px-4 text-sm text-white md:text-lg">
<ChevronUp strokeWidth={3} color="green" />
<p>2.5K</p>
<ChevronDown strokeWidth={3} color="red" />
</div>

<div className="flex h-full flex-row gap-1">
<div className="flex h-full w-fit flex-row items-center gap-1 rounded-full bg-[#1B1B1B] px-4 text-white">
<MessageSquareMore size={22} color="white" />
<p>36</p>
</div>

<div className="flex h-full flex-row items-center gap-1 rounded-full bg-[#1B1B1B] p-2 text-white">
<Share2 />
</div>
</div>
</div>

<div className="flex flex-col gap-3">
<div className="flex h-12 flex-row gap-2">
<Image width={512} height={512} className="size-10 rounded-full" alt="User" src={props.avatar} />
<p className="flex flex-col text-white">
<span className="font-bold">fs/{props.community}</span>
<span className="-mt-1 text-gray-400">Posted by {props.user}</span>
</p>
</div>
<p className="text-white">
<span className="line-clamp-1 text-lg font-bold md:text-2xl">
{props.title}
</span>
<span className="line-clamp-3 text-xs text-gray-400 md:text-sm">
{props.description}
</span>
</p>
{
fullscreenState && <>
<div className="fixed inset-0 z-[90] overflow-y-auto backdrop-blur-sm">
<CircleX className="absolute right-0 top-0 m-4 cursor-pointer text-white" size={32} onClick={() => setFullscreenState(false)} />
<div className="flex min-h-screen items-center justify-center">
<Image className={`${props.key}-image-container`} height={1920} width={1280} alt="Content" src={props.image} />
</div>
</div>
</>
}
<Image onClick={() => setFullscreenState(true)} height={1920} width={1280} className="h-48 rounded-lg object-cover md:h-[22rem]" alt="Content" src={props.image} />
</div>
</div>
);
};

0 comments on commit 943b124

Please sign in to comment.