-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
137 additions
and
131 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<main> | ||
<h1>hello</h1> | ||
</main> | ||
); | ||
} | ||
|
||
const lists = await prisma.list.findMany({ | ||
where: { | ||
favorite: true, | ||
creatorId: session.user.id | ||
}, | ||
include: { | ||
items: { | ||
include: { | ||
creator: { | ||
select: { | ||
name: true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
return ( | ||
<main> | ||
<h1>hello</h1> | ||
<section className="px-2"> | ||
<h2 className="text-4xl">Favorites</h2> | ||
{lists.length > 0 && ( | ||
<ul className="flex flex-col gap-4 mt-4 max-w-[450px]"> | ||
{lists.map((list) => ( | ||
<SpaceList list={list} key={list.id} /> | ||
))} | ||
</ul> | ||
)} | ||
</section> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<typeof list.items>; | ||
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 ( | ||
<ItemWrapper key={list.id} asListItem={isListItem}> | ||
<div className="text-xl text-center min-w-[200px] p-2 rounded-lg border flex justify-between"> | ||
<Link | ||
href={`/spaces/${list.spaceId}/lists/${list.id}`} | ||
className="block flex-grow" | ||
> | ||
{list.name} | ||
</Link> | ||
<FavoriteListButton | ||
spaceId={list.spaceId} | ||
listId={list.id} | ||
isFave={list.favorite} | ||
/> | ||
</div> | ||
<ListComponent | ||
type="ONGOING" | ||
spaceId={list.spaceId} | ||
listId={list.id} | ||
items={ongoingItems} | ||
/> | ||
</ItemWrapper> | ||
); | ||
} | ||
|
||
function ItemWrapper({ | ||
children, | ||
asListItem = true | ||
}: { | ||
children: React.ReactNode; | ||
asListItem?: boolean; | ||
className?: string; | ||
}) { | ||
if (asListItem) { | ||
return <li>{children}</li>; | ||
} | ||
|
||
return <div>{children}</div>; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |