Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement resource card #57

Merged
merged 4 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/layouts/SharingCard/SharingCardBody.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PropsWithChildren } from "react";

export const SharingCardBody = ({ children }: PropsWithChildren) => {
return <div className="space-y-2 rounded-sm bg-overlay p-3">{children}</div>;
return <div className="space-y-2">{children}</div>;
};
9 changes: 9 additions & 0 deletions src/components/layouts/SharingCard/SharingCardFooter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { PropsWithChildren } from "react";

export const SharingCardFooter = ({ children }: PropsWithChildren) => {
return (
<div className="flex justify-between space-x-4 pt-2 text-xs text-icon">
{children}
</div>
);
};
2 changes: 1 addition & 1 deletion src/components/layouts/SharingCard/SharingCardHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { PropsWithChildren } from "react";
import type { PropsWithChildren } from "react";

export const SharingCardHeader = ({ children }: PropsWithChildren) => {
return <header className="flex justify-between">{children}</header>;
Expand Down
4 changes: 3 additions & 1 deletion src/components/layouts/SharingCard/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from "react";
import { SharingCardLayout } from "./_layout";
import { SharingCardHeader } from "./SharingCardHeader";
import { SharingCardBody } from "./SharingCardBody";

import { SharingCardFooter } from "./SharingCardFooter";

type Props = {
header: React.ReactNode;
content: React.ReactNode;
Expand All @@ -13,6 +14,7 @@ export const SharingCard = ({ header, content }: Props) => {
<SharingCardLayout>
<SharingCardHeader>{header}</SharingCardHeader>
<SharingCardBody>{content}</SharingCardBody>
<SharingCardFooter>{footer}</SharingCardFooter>
</SharingCardLayout>
);
};
15 changes: 12 additions & 3 deletions src/components/layouts/SharingCard/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import type { PropsWithChildren } from "react";
import { cn } from "@/lib/utils";
type Props = {
className?: string;
children: React.ReactNode;
};

export const SharingCardLayout = ({ children }: PropsWithChildren) => {
export const SharingCardLayout = ({ className, children }: Props) => {
return (
<article className="flex w-full max-w-[450px] flex-col justify-between space-y-4 overflow-hidden rounded-md border border-card bg-[#0D1117] p-2 shadow md:max-w-none">
<article
className={cn(
"flex w-full max-w-[450px] flex-col justify-between space-y-4 overflow-hidden rounded-md border border-card bg-[#0D1117] p-2 shadow md:max-w-none",
className,
)}
>
{children}
</article>
);
Expand Down
4 changes: 4 additions & 0 deletions src/config/types/prisma.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export type Repository = Prisma.RepositoryGetPayload<{
include: { createdBy: true; language: true; comments: true; topics: true };
}>;

export type Resource = Prisma.ResourceGetPayload<{
include: { createdBy: true };
}>;

export type User = Prisma.UserGetPayload<{
include: { likes: true };
}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const RepositoryCardFooter = ({
const { user, likes } = useRepositoriesContext();

return (
<div className="flex justify-between space-x-4 pt-2 text-xs text-icon">
<>
<div className="flex space-x-4">
<RepositoryCardLanguage repository={repository} />
<RepositoryCardStars
Expand All @@ -33,6 +33,6 @@ export const RepositoryCardFooter = ({
<RepositoryCardComment repository={repository} />
<RepositoryCardLike user={user} repository={repository} likes={likes} />
</div>
</div>
</>
);
};
12 changes: 7 additions & 5 deletions src/modules/repositories/components/RepositoryCard/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ export const RepositoryCard = ({
return (
<SharingCard
header={<RepositoryCardHeader repository={repository} />}
content={
body={
<>
<RepositoryCardDescription repository={repository} />
<RepositoryCardTopics repository={repository} />
<RepositoryCardFooter
repository={repository}
repositoriesAlreadyStarred={repositoriesAlreadyStarred}
/>
</>
}
footer={
<RepositoryCardFooter
repository={repository}
repositoriesAlreadyStarred={repositoriesAlreadyStarred}
/>
}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { LogIcon } from "@primer/octicons-react";

type Props = {
description: string | null;
};

export const ResourceCardDescription = ({ description }: Props) => {
if (!description) return null;

return (
<div className="flex items-center gap-2">
<LogIcon className="h-4 w-4" />
<p className="text-sm">{description}</p>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ResourceCardType } from "./ResourceCardType";
import type { Resource } from "@/config/types/prisma.type";

type Props = {
resource: Resource;
};

export const ResourceCardFooter = ({ resource }: Props) => {
return (
<>
<ResourceCardType type={resource.type} />
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Link from "next/link";
import { ProfileAvatar } from "@/components/layouts/ProfileAvatar";
import { URL } from "@/config/constants";
import type { Resource } from "@/config/types/prisma.type";

type Props = {
resource: Resource;
};

export const ResourceCardHeader = ({ resource }: Props) => {
console.log("ResourceCardHeader", resource.createdBy);
return (
<>
<div className="flex items-center gap-2">
<ProfileAvatar
pictureUrl={`${resource.createdBy.image!}?size=40`}
alt={resource.createdBy.username! ?? resource.createdBy.name!}
/>
<span className="text-xs">
Published by{" "}
<Link
href={`${URL.PROFILE}/${resource.createdBy.id}?username=${resource.createdBy.username}`}
className="text-blue underline"
>
{resource.createdBy.username ?? resource.createdBy.name}
</Link>
</span>
</div>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Props = {
type: string;
};

export const ResourceCardType = ({ type }: Props) => {
return <span className=" font-semibold uppercase">{type}</span>;
};
18 changes: 18 additions & 0 deletions src/modules/resources/components/ResourceCard/ResourceCardUrl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Link from "next/link";
import React from "react";
import { LinkIcon } from "@primer/octicons-react";

type Props = {
url: string;
};

export const ResourceCardUrl = ({ url }: Props) => {
return (
<div className="flex items-center gap-2 hover:text-blue hover:underline">
<LinkIcon className="h-4 w-4" />
<Link className="truncate text-sm " href={url} target="_blank">
{url}
</Link>
</div>
);
};
22 changes: 20 additions & 2 deletions src/modules/resources/components/ResourceCard/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import { SharingCard } from "@/components/layouts/SharingCard/_index";
import type { Resource } from "@prisma/client";
import { ResourceCardHeader } from "./ResourceCardHeader";
import { ResourceCardUrl } from "./ResourceCardUrl";
import { ResourceCardDescription } from "./ResourceCardDescription";
import type { Resource } from "@/config/types/prisma.type";
import { ResourceCardFooter } from "./ResourceCardFooter";

type Props = {
resource: Resource;
};

export const ResourceCard = ({ resource }: Props) => {
return <SharingCard header={resource.url} content={resource.description} />;
const { url, description } = resource;

return (
<SharingCard
className="w-full max-w-md"
header={<ResourceCardHeader resource={resource} />}
body={
<>
<ResourceCardUrl url={url} />
<ResourceCardDescription description={description} />
</>
}
footer={<ResourceCardFooter resource={resource} />}
/>
);
};
4 changes: 3 additions & 1 deletion src/services/resource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export class RessourceService {
const resources = await db.resource.findMany({
where,
orderBy,

include: {
createdBy: true,
},
take: limit,
skip: offset,
cursor: cursor ? { id: cursor } : undefined,
Expand Down
Loading