-
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
227 additions
and
52 deletions.
There are no files selected for viewing
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,13 @@ | ||
import { SpaceItemParams } from '../../page'; | ||
|
||
type ListItemParams = SpaceItemParams & { | ||
listId: string; | ||
}; | ||
export default function ListItem({ params }: { params: ListItemParams }) { | ||
console.log(params); | ||
return ( | ||
<div> | ||
<h1>{params.spaceId}</h1> | ||
</div> | ||
); | ||
} |
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,60 @@ | ||
import { revalidateTag } from 'next/cache'; | ||
import { RedirectType, redirect } from 'next/navigation'; | ||
import { z } from 'zod'; | ||
|
||
import { FormField } from '@/components/formField'; | ||
import { Button } from '@/components/ui/button'; | ||
import { auth } from '@/lib/auth'; | ||
import { prisma } from '@/lib/prisma'; | ||
|
||
const schema = z.object({ | ||
name: z.string() | ||
}); | ||
|
||
export default function AddList({ | ||
params: { spaceId } | ||
}: { | ||
params: { spaceId: string }; | ||
}) { | ||
return ( | ||
<div> | ||
<form | ||
action={async (formData: FormData) => { | ||
'use server'; | ||
try { | ||
const parsed = schema.parse({ | ||
name: formData.get('name') | ||
}); | ||
const session = await auth(); | ||
|
||
const newList = await prisma.list.create({ | ||
data: { | ||
name: parsed.name, | ||
Space: { | ||
connect: { | ||
id: spaceId | ||
} | ||
}, | ||
creator: { | ||
connect: { | ||
id: session?.user.id | ||
} | ||
} | ||
} | ||
}); | ||
|
||
revalidateTag(`/spaces/${spaceId}`); | ||
|
||
redirect(`/spaces/${spaceId}/lists/${newList.id}`); | ||
} catch (err) { | ||
console.log(err); | ||
console.error('OOOPS'); | ||
} | ||
}} | ||
> | ||
<FormField type="text" label="Name" name="name" /> | ||
<Button className="w-full mt-4">Submit</Button> | ||
</form> | ||
</div> | ||
); | ||
} |
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,58 @@ | ||
import Link from 'next/link'; | ||
import { notFound } from 'next/navigation'; | ||
|
||
import { prisma } from '@/lib/prisma'; | ||
|
||
export type SpaceItemParams = { spaceId: string }; | ||
|
||
export default async function SingleSpace({ | ||
params: { spaceId: paramsSpaceId } | ||
}: { | ||
params: SpaceItemParams; | ||
}) { | ||
const space = await prisma.space.findUnique({ | ||
where: { id: paramsSpaceId }, | ||
include: { Lists: true } | ||
}); | ||
|
||
if (!space) { | ||
notFound(); | ||
} | ||
|
||
return ( | ||
<section> | ||
<div className="flex gap-4 mb-4 mx-4 items-center justify-start"> | ||
<h2 className="text-3xl border max-w-fit px-4 py-2 rounded-2xl bg-primary text-primary-foreground"> | ||
<Link href={`/spaces/${space.id}`}>☀︎ {space.name}</Link> | ||
</h2> | ||
<Link | ||
href={`/spaces/${space.id}/lists/add`} | ||
className="text-3xl border px-4 py-2 rounded-2xl" | ||
> | ||
+ | ||
</Link> | ||
</div> | ||
{!space.Lists.length ? ( | ||
<div> | ||
<h2 className="text-2xl">No List was Found</h2> | ||
</div> | ||
) : ( | ||
<ul className="flex flex-wrap gap-2"> | ||
{space.Lists.map((list) => ( | ||
<li | ||
key={list.id} | ||
className="text-xl text-center min-w-[200px] p-2 rounded-lg border" | ||
> | ||
<Link | ||
href={`/spaces/${space.id}/lists/${list.id}`} | ||
className="block" | ||
> | ||
{list.name} | ||
</Link> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</section> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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,17 @@ | ||
-- CreateTable | ||
CREATE TABLE "List" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"spaceId" TEXT NOT NULL, | ||
"creatorId" TEXT NOT NULL, | ||
|
||
CONSTRAINT "List_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "List" ADD CONSTRAINT "List_spaceId_fkey" FOREIGN KEY ("spaceId") REFERENCES "Space"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "List" ADD CONSTRAINT "List_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
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,8 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `favorite` to the `List` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "List" ADD COLUMN "favorite" BOOLEAN NOT NULL; |
12 changes: 12 additions & 0 deletions
12
prisma/migrations/20231203163928_make_favorite_optional/migration.sql
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,12 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[creatorId,name,spaceId]` on the table `List` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "List" ALTER COLUMN "favorite" DROP NOT NULL, | ||
ALTER COLUMN "favorite" SET DEFAULT false; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "List_creatorId_name_spaceId_key" ON "List"("creatorId", "name", "spaceId"); |
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