diff --git a/middleware.ts b/_middleware.ts similarity index 100% rename from middleware.ts rename to _middleware.ts diff --git a/app/page.tsx b/app/page.tsx index f4340c2..f2d3694 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,7 +1,48 @@ -export default function Home() { +import { SpaceList } from '@/components/ListItem'; +import { auth } from '@/lib/auth'; +import { prisma } from '@/lib/prisma'; + +export default async function Home() { + const session = await auth(); + + if (!session) { + return ( +
+

hello

+
+ ); + } + + const lists = await prisma.list.findMany({ + where: { + favorite: true, + creatorId: session.user.id + }, + include: { + items: { + include: { + creator: { + select: { + name: true + } + } + } + } + } + }); + return (
-

hello

+
+

Favorites

+ {lists.length > 0 && ( + + )} +
); } diff --git a/app/spaces/[spaceId]/lists/[listId]/@list/components/ListCompoent.tsx b/app/spaces/[spaceId]/lists/[listId]/@list/components/ListCompoent.tsx index c4bf670..f2983e0 100644 --- a/app/spaces/[spaceId]/lists/[listId]/@list/components/ListCompoent.tsx +++ b/app/spaces/[spaceId]/lists/[listId]/@list/components/ListCompoent.tsx @@ -14,10 +14,10 @@ type ListItems = Array<{ type Props = { type: 'ONGOING' | 'COMPLETED'; - items: List; + items?: List; listId: string; spaceId: string; - title: string; + title?: string; }; export function ListComponent({ @@ -29,7 +29,7 @@ export function ListComponent({ }: Props) { return ( <> -

{title}

+ {title &&

{title}

}
    { - if (currentDate === null) return false; - - const diff = - (new Date(currentDate).getTime() - new Date().getTime()) / - 1000 / - 60 / - 60 / - 24; - - const isCompleted = diff < 1; - - return isCompleted; -}; - export default async function List({ params }: { params: ListItemParams }) { const items = await prisma.listItem.findMany({ where: { @@ -65,68 +51,6 @@ export default async function List({ params }: { params: ListItemParams }) { spaceId={params.spaceId} title="Completed" /> - - {/*
      */} - {/* {ongoingItems?.map((item) => { */} - {/* const isDaily = item.type === 'DAILY'; */} - {/**/} - {/* return ( */} - {/*
    • */} - {/*
      */} - {/* */} - {/* recurring icon */} - {/* */} - {/* */} - {/*
      */} - {/*
      */} - {/*
      { */} - {/* 'use server'; */} - {/* formData.append('listId', params.listId); */} - {/* formData.append('listItemId', item.id); */} - {/* formData.append('spaceId', params.spaceId); */} - {/**/} - {/* await markItemAsComplete(formData); */} - {/* }} */} - {/* > */} - {/* */} - {/* ✓ */} - {/* */} - {/*
      */} - {/*
      { */} - {/* 'use server'; */} - {/* formData.append('listId', params.listId); */} - {/* formData.append('listItemId', item.id); */} - {/* formData.append('spaceId', params.spaceId); */} - {/* formData.append('completedAt', Date.now().toString()); */} - {/**/} - {/* await deleteListItem(formData); */} - {/* }} */} - {/* > */} - {/* */} - {/* ⤫ */} - {/* */} - {/*
      */} - {/*
      */} - {/*
    • */} - {/* ); */} - {/* })} */} - {/*
    */} ); } diff --git a/app/spaces/[spaceId]/lists/[listId]/effective_react.jpg b/app/spaces/[spaceId]/lists/[listId]/effective_react.jpg new file mode 100644 index 0000000..6cb0059 Binary files /dev/null and b/app/spaces/[spaceId]/lists/[listId]/effective_react.jpg differ diff --git a/app/spaces/[spaceId]/lists/[listId]/page.tsx b/app/spaces/[spaceId]/lists/[listId]/page.tsx index fe07ddd..a8129c9 100644 --- a/app/spaces/[spaceId]/lists/[listId]/page.tsx +++ b/app/spaces/[spaceId]/lists/[listId]/page.tsx @@ -19,6 +19,7 @@ export default async function List({ params }: { params: ListItemParams }) { if (!id) { redirect('/'); } + const list = await prisma.list.findUnique({ where: { id: params.listId } }); diff --git a/app/spaces/[spaceId]/page.tsx b/app/spaces/[spaceId]/page.tsx index 461f070..2a745be 100644 --- a/app/spaces/[spaceId]/page.tsx +++ b/app/spaces/[spaceId]/page.tsx @@ -1,7 +1,7 @@ import Link from 'next/link'; import { notFound, redirect } from 'next/navigation'; -import { FavoriteListButton } from '@/components/FavoriteListButton'; +import { SpaceList } from '@/components/ListItem'; import { auth } from '@/lib/auth'; import { prisma } from '@/lib/prisma'; @@ -49,23 +49,7 @@ export default async function SingleSpace({ ) : (
      {space.Lists.map((list) => ( -
    • - - {list.name} - - -
    • + ))}
    )} diff --git a/components/ListItem.tsx b/components/ListItem.tsx new file mode 100644 index 0000000..5a48837 --- /dev/null +++ b/components/ListItem.tsx @@ -0,0 +1,73 @@ +import { List, ListItem } from '@prisma/client'; +import Link from 'next/link'; + +import { ListComponent } from '@/app/spaces/[spaceId]/lists/[listId]/@list/components/ListCompoent'; +import { isCompleted } from '@/utils/listItem'; + +import { FavoriteListButton } from './FavoriteListButton'; + +type Props = { + list: List & { + items?: (ListItem & { creator: { name: string | null } })[]; + }; + isListItem?: boolean; +}; + +export function SpaceList({ list, isListItem }: Props) { + const { ongoingItems } = list.items?.reduce<{ + ongoingItems: NonNullable; + completedItems: typeof list.items; + }>( + (acc, item) => { + if (isCompleted(item.completedAt)) { + acc.completedItems.push(item); + + return acc; + } + + acc.ongoingItems.push(item); + + return acc; + }, + { ongoingItems: [], completedItems: [] } + ) || { ongingItems: [], completedItems: [] }; + + return ( + +
    + + {list.name} + + +
    + +
    + ); +} + +function ItemWrapper({ + children, + asListItem = true +}: { + children: React.ReactNode; + asListItem?: boolean; + className?: string; +}) { + if (asListItem) { + return
  • {children}
  • ; + } + + return
    {children}
    ; +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 90d9a7b..55b3a86 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,9 +14,6 @@ dependencies: '@prisma/client': specifier: ^5.6.0 version: 5.6.0(prisma@5.6.0) - '@radix-ui/react-checkbox': - specifier: ^1.0.4 - version: 1.0.4(@types/react-dom@18.2.15)(@types/react@18.2.37)(react-dom@18.2.0)(react@18.2.0) '@radix-ui/react-dialog': specifier: ^1.0.5 version: 1.0.5(@types/react-dom@18.2.15)(@types/react@18.2.37)(react-dom@18.2.0)(react@18.2.0) @@ -467,34 +464,6 @@ packages: react-dom: 18.2.0(react@18.2.0) dev: false - /@radix-ui/react-checkbox@1.0.4(@types/react-dom@18.2.15)(@types/react@18.2.37)(react-dom@18.2.0)(react@18.2.0): - resolution: {integrity: sha512-CBuGQa52aAYnADZVt/KBQzXrwx6TqnlwtcIPGtVt5JkkzQwMOLJjPukimhfKEr4GQNd43C+djUh5Ikopj8pSLg==} - peerDependencies: - '@types/react': '*' - '@types/react-dom': '*' - react: ^16.8 || ^17.0 || ^18.0 - react-dom: ^16.8 || ^17.0 || ^18.0 - peerDependenciesMeta: - '@types/react': - optional: true - '@types/react-dom': - optional: true - dependencies: - '@babel/runtime': 7.23.2 - '@radix-ui/primitive': 1.0.1 - '@radix-ui/react-compose-refs': 1.0.1(@types/react@18.2.37)(react@18.2.0) - '@radix-ui/react-context': 1.0.1(@types/react@18.2.37)(react@18.2.0) - '@radix-ui/react-presence': 1.0.1(@types/react-dom@18.2.15)(@types/react@18.2.37)(react-dom@18.2.0)(react@18.2.0) - '@radix-ui/react-primitive': 1.0.3(@types/react-dom@18.2.15)(@types/react@18.2.37)(react-dom@18.2.0)(react@18.2.0) - '@radix-ui/react-use-controllable-state': 1.0.1(@types/react@18.2.37)(react@18.2.0) - '@radix-ui/react-use-previous': 1.0.1(@types/react@18.2.37)(react@18.2.0) - '@radix-ui/react-use-size': 1.0.1(@types/react@18.2.37)(react@18.2.0) - '@types/react': 18.2.37 - '@types/react-dom': 18.2.15 - react: 18.2.0 - react-dom: 18.2.0(react@18.2.0) - dev: false - /@radix-ui/react-collection@1.0.3(@types/react-dom@18.2.15)(@types/react@18.2.37)(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-3SzW+0PW7yBBoQlT8wNcGtaxaD0XSu0uLUFgrtHY08Acx05TaHaOmVLR73c0j/cqpDy53KBMO7s0dx2wmOIDIA==} peerDependencies: diff --git a/utils/listItem.ts b/utils/listItem.ts new file mode 100644 index 0000000..1aeb38e --- /dev/null +++ b/utils/listItem.ts @@ -0,0 +1,14 @@ +export const isCompleted = (currentDate: Date | null) => { + if (currentDate === null) return false; + + const diff = + (new Date(currentDate).getTime() - new Date().getTime()) / + 1000 / + 60 / + 60 / + 24; + + const isCompleted = diff < 1; + + return isCompleted; +};