- Copy
+
Download
diff --git a/src/app/(default)/community/page.tsx b/src/app/(default)/community/page.tsx
index f4e4013..02cd60a 100644
--- a/src/app/(default)/community/page.tsx
+++ b/src/app/(default)/community/page.tsx
@@ -1,49 +1,29 @@
-import { auth } from '@/auth';
+import { prisma } from '@/client';
+import { ArtCards, SkeletonCards } from '@/components/art-cards';
import type { Metadata } from 'next';
import { Suspense } from 'react';
-const SessionData = async () => {
- const session = await auth();
- if (session?.user) {
- return (
-
-
Current Session Data
- {Object.keys(session.user).length > 3 ? (
-
- In this example, the whole session object is passed to the page,
- including the raw user object. Our recommendation is to{' '}
- only pass the necessary fields to the page, as the raw user
- object may contain sensitive information.
-
- ) : (
-
- In this example, only some fields in the user object is passed to
- the page to avoid exposing sensitive information.
-
- )}
-
-
Session
-
- {JSON.stringify(session, null, 2)}
-
-
-
- );
- }
-
- return (
-
- No session data, please Sign In first.
-
- );
+const ArtsList = async () => {
+ const arts = await prisma.art.findMany({
+ orderBy: {
+ createdAt: 'desc',
+ },
+ });
+ return
;
};
const Page = () => {
return (
-
-
-
-
+
);
};
diff --git a/src/components/art-cards.tsx b/src/components/art-cards.tsx
index daaa32a..c381bce 100644
--- a/src/components/art-cards.tsx
+++ b/src/components/art-cards.tsx
@@ -1,3 +1,8 @@
+import { cn } from '@/lib/utils';
+import { formatDate, unflattenArray } from '@/utils';
+import { Art } from '@prisma/client';
+import { CopyButton } from './copy-button';
+import { PreviewCanvas } from './preview-canvas';
import {
Card,
CardContent,
@@ -8,23 +13,53 @@ import {
} from './ui/card';
import { Skeleton } from './ui/skeleton';
-const ArtCard = () => {
+const ArtCard = ({ art }: { art: Art }) => {
+ const asciiData = unflattenArray(art.body, art.width);
+ const date = formatDate(art.createdAt);
+
return (
-
-
- Create project
- Deploy your new project in one-click.
+
+
+ {art.title}
+
+ {art.description}
+ {date}
+
-
-
+
+
+
+
+
+ {/* favorite button */}
+
);
};
-export const ArtCards = () => {
- return artcards
;
+export const ArtCards = ({ arts }: { arts: Art[] }) => {
+ return (
+
+ {arts.map((art) => (
+
+ ))}
+
+ );
};
export const SkeletonCards = () => {
- return ;
+ return ;
};
diff --git a/src/components/copy-button.tsx b/src/components/copy-button.tsx
new file mode 100644
index 0000000..1a98d7a
--- /dev/null
+++ b/src/components/copy-button.tsx
@@ -0,0 +1,23 @@
+'use client';
+
+import { AsciiData } from '@/types';
+import { createAscii } from '@/utils';
+import { Button } from './ui/button';
+import { useToast } from './ui/use-toast';
+
+export const CopyButton = ({
+ asciiData,
+ width,
+ height,
+}: { asciiData: AsciiData; width: number; height: number }) => {
+ const { toast } = useToast();
+ const handleCopy = () => {
+ const asciiString = createAscii(asciiData, width, height);
+ navigator.clipboard.writeText(asciiString);
+ toast({
+ title: 'Copied to clipboard!',
+ });
+ };
+
+ return Copy ;
+};
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 52fbe60..9a72f3f 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -20,8 +20,8 @@ export const flattenArray = (array: boolean[][]): boolean[] => array.flat();
export const unflattenArray = (
array: boolean[],
- rows = 13,
cols = 27,
+ rows = 13,
): boolean[][] => {
const result: boolean[][] = [];
for (let i = 0; i < rows; i++) {
@@ -29,3 +29,20 @@ export const unflattenArray = (
}
return result;
};
+
+const getUserLocale = (): string => {
+ return navigator.language ?? 'en-US';
+};
+
+const getUserTimeZone = (): string => {
+ return Intl.DateTimeFormat().resolvedOptions().timeZone ?? 'UTC';
+};
+
+export const formatDate = (date: Date): string => {
+ const locale = getUserLocale();
+ const timeZone = getUserTimeZone();
+
+ return date.toLocaleDateString(locale, {
+ timeZone: timeZone,
+ });
+};