Spaces:
Running
Running
Add OIDC auth, developer profiles, work votes, and solution workflow
Browse files- .env.example +10 -0
- Dockerfile +9 -0
- README.md +31 -18
- app/api/auth/[...nextauth]/route.ts +3 -0
- app/api/ideas/[id]/comments/route.ts +39 -6
- app/api/ideas/[id]/route.ts +48 -4
- app/api/ideas/[id]/solutions/route.ts +101 -0
- app/api/ideas/[id]/upvote/route.ts +32 -10
- app/api/ideas/[id]/work-vote/route.ts +36 -0
- app/api/ideas/route.ts +42 -11
- app/api/me/profile/route.ts +58 -0
- app/api/solutions/[solutionId]/approve/route.ts +38 -0
- app/api/solutions/[solutionId]/comments/route.ts +62 -0
- app/api/solutions/[solutionId]/vote/route.ts +67 -0
- app/api/task-links/[linkId]/route.ts +8 -2
- app/api/tasks/[taskId]/claim/route.ts +18 -7
- app/api/tasks/[taskId]/links/route.ts +8 -3
- app/api/tasks/[taskId]/status/route.ts +24 -7
- app/api/tasks/[taskId]/unclaim/route.ts +10 -3
- app/api/tasks/[taskId]/work-vote/route.ts +36 -0
- app/ideas/[id]/page.tsx +86 -10
- app/layout.tsx +28 -2
- app/login/page.tsx +46 -0
- app/me/profile/page.tsx +94 -0
- app/submit/page.tsx +5 -2
- auth.ts +63 -0
- components/HomeList.tsx +2 -0
- components/IdeaDetailClient.tsx +345 -22
- components/SubmitForm.tsx +23 -1
- lib/actor.ts +13 -0
- next.config.ts +1 -3
- package-lock.json +145 -0
- package.json +2 -0
- prisma/schema.prisma +243 -44
- types/next-auth.d.ts +9 -0
.env.example
CHANGED
|
@@ -1,3 +1,13 @@
|
|
| 1 |
DATABASE_URL="file:./dev.db"
|
| 2 |
OPENAI_API_KEY=""
|
| 3 |
OPENAI_MODEL="gpt-4.1-mini"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
DATABASE_URL="file:./dev.db"
|
| 2 |
OPENAI_API_KEY=""
|
| 3 |
OPENAI_MODEL="gpt-4.1-mini"
|
| 4 |
+
|
| 5 |
+
AUTH_SECRET="replace-with-long-random-secret"
|
| 6 |
+
AUTH_GOOGLE_ID=""
|
| 7 |
+
AUTH_GOOGLE_SECRET=""
|
| 8 |
+
AUTH_GITHUB_ID=""
|
| 9 |
+
AUTH_GITHUB_SECRET=""
|
| 10 |
+
AUTH_APPLE_ID=""
|
| 11 |
+
AUTH_APPLE_SECRET=""
|
| 12 |
+
AUTH_FACEBOOK_ID=""
|
| 13 |
+
AUTH_FACEBOOK_SECRET=""
|
Dockerfile
CHANGED
|
@@ -14,6 +14,15 @@ COPY . .
|
|
| 14 |
ENV DATABASE_URL="file:./dev.db"
|
| 15 |
ENV OPENAI_API_KEY=""
|
| 16 |
ENV OPENAI_MODEL="gpt-4.1-mini"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
ENV NODE_ENV=production
|
| 18 |
ENV PORT=7860
|
| 19 |
|
|
|
|
| 14 |
ENV DATABASE_URL="file:./dev.db"
|
| 15 |
ENV OPENAI_API_KEY=""
|
| 16 |
ENV OPENAI_MODEL="gpt-4.1-mini"
|
| 17 |
+
ENV AUTH_SECRET="change-me-in-production"
|
| 18 |
+
ENV AUTH_GOOGLE_ID=""
|
| 19 |
+
ENV AUTH_GOOGLE_SECRET=""
|
| 20 |
+
ENV AUTH_GITHUB_ID=""
|
| 21 |
+
ENV AUTH_GITHUB_SECRET=""
|
| 22 |
+
ENV AUTH_APPLE_ID=""
|
| 23 |
+
ENV AUTH_APPLE_SECRET=""
|
| 24 |
+
ENV AUTH_FACEBOOK_ID=""
|
| 25 |
+
ENV AUTH_FACEBOOK_SECRET=""
|
| 26 |
ENV NODE_ENV=production
|
| 27 |
ENV PORT=7860
|
| 28 |
|
README.md
CHANGED
|
@@ -7,28 +7,31 @@ sdk: docker
|
|
| 7 |
app_port: 7860
|
| 8 |
---
|
| 9 |
|
| 10 |
-
# Demand Solution Board
|
| 11 |
|
| 12 |
Community Demand -> Requirements Board.
|
| 13 |
|
| 14 |
-
Users submit
|
| 15 |
|
| 16 |
## Stack
|
| 17 |
|
| 18 |
- Next.js (App Router) + TypeScript
|
| 19 |
- Tailwind CSS
|
| 20 |
- Prisma + SQLite
|
| 21 |
-
-
|
|
|
|
| 22 |
|
| 23 |
-
##
|
| 24 |
|
| 25 |
-
-
|
| 26 |
-
-
|
| 27 |
-
-
|
| 28 |
-
-
|
| 29 |
-
- Task claim/unclaim, status updates,
|
| 30 |
-
-
|
| 31 |
-
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
## Run Locally
|
| 34 |
|
|
@@ -45,15 +48,25 @@ Open [http://localhost:3000](http://localhost:3000).
|
|
| 45 |
|
| 46 |
Copy `.env.example` to `.env`.
|
| 47 |
|
| 48 |
-
|
| 49 |
-
- `OPENAI_API_KEY` (optional)
|
| 50 |
-
- `OPENAI_MODEL` (optional, default `gpt-4.1-mini`)
|
| 51 |
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
- `OPENAI_API_KEY`
|
| 57 |
-
- `OPENAI_MODEL` (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
|
|
|
| 7 |
app_port: 7860
|
| 8 |
---
|
| 9 |
|
| 10 |
+
# Demand Solution Board
|
| 11 |
|
| 12 |
Community Demand -> Requirements Board.
|
| 13 |
|
| 14 |
+
Users submit product ideas and the app generates structured specs (features + tasks). Community members validate demand, developers coordinate implementation, and submitters approve solutions.
|
| 15 |
|
| 16 |
## Stack
|
| 17 |
|
| 18 |
- Next.js (App Router) + TypeScript
|
| 19 |
- Tailwind CSS
|
| 20 |
- Prisma + SQLite
|
| 21 |
+
- NextAuth (OIDC) + Prisma Adapter
|
| 22 |
+
- OpenAI API (optional; fallback generation if key is missing)
|
| 23 |
|
| 24 |
+
## Features
|
| 25 |
|
| 26 |
+
- OIDC login support (Google, GitHub, Apple, optional Facebook)
|
| 27 |
+
- Anonymous posting by default; logged-in submitters can show visible name
|
| 28 |
+
- Developer profiles (display name, headline, bio, links)
|
| 29 |
+
- Idea/task work votes: developers signal they are working on specific scope
|
| 30 |
+
- Task claim/unclaim, status updates, implementation links
|
| 31 |
+
- Solution submissions (app URL / GitHub repo / other)
|
| 32 |
+
- Idea submitter can approve a solution
|
| 33 |
+
- Solution like/unlike voting and threaded solution comments
|
| 34 |
+
- Cookie-based anonymous identity still supported for non-auth usage
|
| 35 |
|
| 36 |
## Run Locally
|
| 37 |
|
|
|
|
| 48 |
|
| 49 |
Copy `.env.example` to `.env`.
|
| 50 |
|
| 51 |
+
Required baseline:
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
- `DATABASE_URL` (default: `file:./dev.db`)
|
| 54 |
+
- `AUTH_SECRET` (required for auth sessions)
|
| 55 |
|
| 56 |
+
Optional LLM:
|
| 57 |
|
| 58 |
- `OPENAI_API_KEY`
|
| 59 |
+
- `OPENAI_MODEL` (default: `gpt-4.1-mini`)
|
| 60 |
+
|
| 61 |
+
OIDC providers (set whichever you want to enable):
|
| 62 |
+
|
| 63 |
+
- `AUTH_GOOGLE_ID`, `AUTH_GOOGLE_SECRET`
|
| 64 |
+
- `AUTH_GITHUB_ID`, `AUTH_GITHUB_SECRET`
|
| 65 |
+
- `AUTH_APPLE_ID`, `AUTH_APPLE_SECRET`
|
| 66 |
+
- `AUTH_FACEBOOK_ID`, `AUTH_FACEBOOK_SECRET` (optional)
|
| 67 |
+
|
| 68 |
+
## Deploy to Hugging Face Spaces (Docker)
|
| 69 |
+
|
| 70 |
+
This repo includes a `Dockerfile` for Spaces. The container initializes the SQLite schema at startup using `prisma db push` and sets a default `DATABASE_URL` internally (`file:./dev.db`).
|
| 71 |
|
| 72 |
+
For OIDC in Spaces, configure provider callback URLs to your Space domain and set provider secrets in Space Settings -> Variables and secrets.
|
app/api/auth/[...nextauth]/route.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { handlers } from "@/auth";
|
| 2 |
+
|
| 3 |
+
export const { GET, POST } = handlers;
|
app/api/ideas/[id]/comments/route.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
|
| 2 |
import { z } from "zod";
|
| 3 |
import { prisma } from "@/lib/prisma";
|
| 4 |
import { getAnonId } from "@/lib/identity";
|
|
|
|
| 5 |
|
| 6 |
const commentSchema = z.object({
|
| 7 |
body: z.string().min(1).max(2000),
|
|
@@ -9,16 +10,33 @@ const commentSchema = z.object({
|
|
| 9 |
|
| 10 |
export async function GET(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
| 11 |
const { id } = await params;
|
| 12 |
-
const comments = await prisma.comment.findMany({
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
}
|
| 15 |
|
| 16 |
export async function POST(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
|
|
|
|
|
| 17 |
const anonId = await getAnonId();
|
| 18 |
const { id } = await params;
|
| 19 |
|
| 20 |
-
if (!anonId) {
|
| 21 |
-
return NextResponse.json({ error: "Missing
|
| 22 |
}
|
| 23 |
|
| 24 |
const json = await request.json();
|
|
@@ -32,10 +50,25 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
|
| 32 |
data: {
|
| 33 |
ideaId: id,
|
| 34 |
body: parsed.data.body,
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
},
|
| 37 |
});
|
| 38 |
|
| 39 |
await prisma.idea.update({ where: { id }, data: { commentsCount: { increment: 1 } } });
|
| 40 |
-
return NextResponse.json(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
}
|
|
|
|
| 2 |
import { z } from "zod";
|
| 3 |
import { prisma } from "@/lib/prisma";
|
| 4 |
import { getAnonId } from "@/lib/identity";
|
| 5 |
+
import { auth } from "@/auth";
|
| 6 |
|
| 7 |
const commentSchema = z.object({
|
| 8 |
body: z.string().min(1).max(2000),
|
|
|
|
| 10 |
|
| 11 |
export async function GET(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
| 12 |
const { id } = await params;
|
| 13 |
+
const comments = await prisma.comment.findMany({
|
| 14 |
+
where: { ideaId: id },
|
| 15 |
+
include: {
|
| 16 |
+
createdByUser: {
|
| 17 |
+
include: { developerProfile: { select: { displayName: true } } },
|
| 18 |
+
},
|
| 19 |
+
},
|
| 20 |
+
orderBy: { createdAt: "desc" },
|
| 21 |
+
});
|
| 22 |
+
|
| 23 |
+
return NextResponse.json({
|
| 24 |
+
items: comments.map((comment) => ({
|
| 25 |
+
...comment,
|
| 26 |
+
author_label:
|
| 27 |
+
comment.createdByUser?.developerProfile?.displayName || comment.createdByUser?.name || (comment.createdByUserId ? "Member" : "Anon"),
|
| 28 |
+
})),
|
| 29 |
+
});
|
| 30 |
}
|
| 31 |
|
| 32 |
export async function POST(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
| 33 |
+
const session = await auth();
|
| 34 |
+
const userId = session?.user?.id ?? null;
|
| 35 |
const anonId = await getAnonId();
|
| 36 |
const { id } = await params;
|
| 37 |
|
| 38 |
+
if (!userId && !anonId) {
|
| 39 |
+
return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 40 |
}
|
| 41 |
|
| 42 |
const json = await request.json();
|
|
|
|
| 50 |
data: {
|
| 51 |
ideaId: id,
|
| 52 |
body: parsed.data.body,
|
| 53 |
+
createdByUserId: userId,
|
| 54 |
+
createdByAnonId: userId ? null : anonId,
|
| 55 |
+
},
|
| 56 |
+
include: {
|
| 57 |
+
createdByUser: {
|
| 58 |
+
include: { developerProfile: { select: { displayName: true } } },
|
| 59 |
+
},
|
| 60 |
},
|
| 61 |
});
|
| 62 |
|
| 63 |
await prisma.idea.update({ where: { id }, data: { commentsCount: { increment: 1 } } });
|
| 64 |
+
return NextResponse.json(
|
| 65 |
+
{
|
| 66 |
+
comment: {
|
| 67 |
+
...comment,
|
| 68 |
+
author_label:
|
| 69 |
+
comment.createdByUser?.developerProfile?.displayName || comment.createdByUser?.name || (comment.createdByUserId ? "Member" : "Anon"),
|
| 70 |
+
},
|
| 71 |
+
},
|
| 72 |
+
{ status: 201 }
|
| 73 |
+
);
|
| 74 |
}
|
app/api/ideas/[id]/route.ts
CHANGED
|
@@ -2,16 +2,35 @@ import { NextRequest, NextResponse } from "next/server";
|
|
| 2 |
import { prisma } from "@/lib/prisma";
|
| 3 |
import { mapIdea, mapTask } from "@/lib/db-mappers";
|
| 4 |
import { getAnonId } from "@/lib/identity";
|
|
|
|
| 5 |
|
| 6 |
export async function GET(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
|
|
|
|
|
| 7 |
const anonId = await getAnonId();
|
| 8 |
const { id } = await params;
|
| 9 |
|
| 10 |
const idea = await prisma.idea.findUnique({
|
| 11 |
where: { id },
|
| 12 |
include: {
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
},
|
| 16 |
});
|
| 17 |
|
|
@@ -27,18 +46,43 @@ export async function GET(_: NextRequest, { params }: { params: Promise<{ id: st
|
|
| 27 |
: [];
|
| 28 |
const nicknameByAnonId = new Map(claimantNicknames.map((row) => [row.anonId, row.nickname]));
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
return NextResponse.json({
|
| 31 |
idea: {
|
| 32 |
...mapIdea(idea),
|
|
|
|
|
|
|
|
|
|
| 33 |
viewerAnonId: anonId,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
tasks: idea.tasks.map((task) => {
|
| 35 |
const mapped = mapTask(task);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
return {
|
| 37 |
...mapped,
|
| 38 |
-
claimantNickname:
|
|
|
|
|
|
|
|
|
|
| 39 |
};
|
| 40 |
}),
|
| 41 |
-
comments: idea.comments
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
},
|
| 43 |
});
|
| 44 |
}
|
|
|
|
| 2 |
import { prisma } from "@/lib/prisma";
|
| 3 |
import { mapIdea, mapTask } from "@/lib/db-mappers";
|
| 4 |
import { getAnonId } from "@/lib/identity";
|
| 5 |
+
import { auth } from "@/auth";
|
| 6 |
|
| 7 |
export async function GET(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
| 8 |
+
const session = await auth();
|
| 9 |
+
const userId = session?.user?.id ?? null;
|
| 10 |
const anonId = await getAnonId();
|
| 11 |
const { id } = await params;
|
| 12 |
|
| 13 |
const idea = await prisma.idea.findUnique({
|
| 14 |
where: { id },
|
| 15 |
include: {
|
| 16 |
+
createdByUser: { include: { developerProfile: true } },
|
| 17 |
+
workVotes: true,
|
| 18 |
+
userVotes: true,
|
| 19 |
+
votes: true,
|
| 20 |
+
tasks: {
|
| 21 |
+
include: {
|
| 22 |
+
links: true,
|
| 23 |
+
claimedByUser: { include: { developerProfile: true } },
|
| 24 |
+
workVotes: true,
|
| 25 |
+
},
|
| 26 |
+
orderBy: { createdAt: "asc" },
|
| 27 |
+
},
|
| 28 |
+
comments: {
|
| 29 |
+
include: {
|
| 30 |
+
createdByUser: { include: { developerProfile: true } },
|
| 31 |
+
},
|
| 32 |
+
orderBy: { createdAt: "desc" },
|
| 33 |
+
},
|
| 34 |
},
|
| 35 |
});
|
| 36 |
|
|
|
|
| 46 |
: [];
|
| 47 |
const nicknameByAnonId = new Map(claimantNicknames.map((row) => [row.anonId, row.nickname]));
|
| 48 |
|
| 49 |
+
const isVoted = userId
|
| 50 |
+
? idea.userVotes.some((vote) => vote.userId === userId)
|
| 51 |
+
: idea.votes.some((vote) => vote.anonId === anonId);
|
| 52 |
+
|
| 53 |
return NextResponse.json({
|
| 54 |
idea: {
|
| 55 |
...mapIdea(idea),
|
| 56 |
+
submitter_label: idea.isAnonymous
|
| 57 |
+
? "Anonymous"
|
| 58 |
+
: idea.submitterVisibleName || idea.createdByUser?.developerProfile?.displayName || idea.createdByUser?.name || "Member",
|
| 59 |
viewerAnonId: anonId,
|
| 60 |
+
viewerUserId: userId,
|
| 61 |
+
canApproveSolutions: Boolean(userId ? idea.createdByUserId === userId : !idea.createdByUserId && idea.createdByAnonId === anonId),
|
| 62 |
+
isVoted,
|
| 63 |
+
idea_working_count: idea.workVotes.length,
|
| 64 |
+
idea_working: userId ? idea.workVotes.some((vote) => vote.userId === userId) : false,
|
| 65 |
tasks: idea.tasks.map((task) => {
|
| 66 |
const mapped = mapTask(task);
|
| 67 |
+
const claimantDisplayName = task.claimedByUserId
|
| 68 |
+
? task.claimedByUser?.developerProfile?.displayName || task.claimedByUser?.name || "Member"
|
| 69 |
+
: mapped.claimedByAnonId
|
| 70 |
+
? nicknameByAnonId.get(mapped.claimedByAnonId) ?? "anon"
|
| 71 |
+
: null;
|
| 72 |
+
|
| 73 |
return {
|
| 74 |
...mapped,
|
| 75 |
+
claimantNickname: claimantDisplayName,
|
| 76 |
+
claimantDisplayName,
|
| 77 |
+
working_count: task.workVotes.length,
|
| 78 |
+
working: userId ? task.workVotes.some((vote) => vote.userId === userId) : false,
|
| 79 |
};
|
| 80 |
}),
|
| 81 |
+
comments: idea.comments.map((comment) => ({
|
| 82 |
+
...comment,
|
| 83 |
+
author_label:
|
| 84 |
+
comment.createdByUser?.developerProfile?.displayName || comment.createdByUser?.name || (comment.createdByUserId ? "Member" : "Anon"),
|
| 85 |
+
})),
|
| 86 |
},
|
| 87 |
});
|
| 88 |
}
|
app/api/ideas/[id]/solutions/route.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
+
import { z } from "zod";
|
| 3 |
+
import { auth } from "@/auth";
|
| 4 |
+
import { prisma } from "@/lib/prisma";
|
| 5 |
+
import { getAnonId } from "@/lib/identity";
|
| 6 |
+
|
| 7 |
+
const schema = z.object({
|
| 8 |
+
taskId: z.string().uuid().optional().or(z.literal("")),
|
| 9 |
+
url: z.string().url().max(500),
|
| 10 |
+
label: z.string().max(120).optional(),
|
| 11 |
+
description: z.string().max(1000).optional(),
|
| 12 |
+
type: z.enum(["APP_URL", "GITHUB_REPO", "OTHER"]).optional(),
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
async function mapSolutions(ideaId: string, userId: string | null, anonId: string | null) {
|
| 16 |
+
const solutions = await prisma.solution.findMany({
|
| 17 |
+
where: { ideaId },
|
| 18 |
+
include: {
|
| 19 |
+
createdByUser: { include: { developerProfile: true } },
|
| 20 |
+
userVotes: true,
|
| 21 |
+
anonVotes: true,
|
| 22 |
+
comments: true,
|
| 23 |
+
task: { select: { id: true, title: true } },
|
| 24 |
+
},
|
| 25 |
+
orderBy: { createdAt: "desc" },
|
| 26 |
+
});
|
| 27 |
+
|
| 28 |
+
return solutions.map((solution) => {
|
| 29 |
+
const userScore = solution.userVotes.reduce((sum, vote) => sum + vote.value, 0);
|
| 30 |
+
const anonScore = solution.anonVotes.reduce((sum, vote) => sum + vote.value, 0);
|
| 31 |
+
const myVote = userId
|
| 32 |
+
? solution.userVotes.find((vote) => vote.userId === userId)?.value ?? 0
|
| 33 |
+
: solution.anonVotes.find((vote) => vote.anonId === anonId)?.value ?? 0;
|
| 34 |
+
|
| 35 |
+
return {
|
| 36 |
+
id: solution.id,
|
| 37 |
+
ideaId: solution.ideaId,
|
| 38 |
+
taskId: solution.taskId,
|
| 39 |
+
taskTitle: solution.task?.title || null,
|
| 40 |
+
url: solution.url,
|
| 41 |
+
label: solution.label,
|
| 42 |
+
description: solution.description,
|
| 43 |
+
type: solution.type,
|
| 44 |
+
createdAt: solution.createdAt,
|
| 45 |
+
approvedAt: solution.approvedAt,
|
| 46 |
+
createdByDisplayName:
|
| 47 |
+
solution.createdByUser.developerProfile?.displayName || solution.createdByUser.name || solution.createdByUser.email || "Developer",
|
| 48 |
+
voteScore: userScore + anonScore,
|
| 49 |
+
myVote,
|
| 50 |
+
commentsCount: solution.comments.length,
|
| 51 |
+
};
|
| 52 |
+
});
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
export async function GET(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
| 56 |
+
const session = await auth();
|
| 57 |
+
const userId = session?.user?.id ?? null;
|
| 58 |
+
const anonId = await getAnonId();
|
| 59 |
+
const { id } = await params;
|
| 60 |
+
|
| 61 |
+
return NextResponse.json({ items: await mapSolutions(id, userId, anonId || null) });
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
export async function POST(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
| 65 |
+
const session = await auth();
|
| 66 |
+
const userId = session?.user?.id;
|
| 67 |
+
const { id } = await params;
|
| 68 |
+
|
| 69 |
+
if (!userId) {
|
| 70 |
+
return NextResponse.json({ error: "Developer login required" }, { status: 401 });
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
const body = await request.json();
|
| 74 |
+
const parsed = schema.safeParse(body);
|
| 75 |
+
if (!parsed.success) {
|
| 76 |
+
return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
const taskId = parsed.data.taskId || undefined;
|
| 80 |
+
if (taskId) {
|
| 81 |
+
const task = await prisma.task.findUnique({ where: { id: taskId } });
|
| 82 |
+
if (!task || task.ideaId !== id) {
|
| 83 |
+
return NextResponse.json({ error: "Task does not belong to this idea" }, { status: 400 });
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
await prisma.solution.create({
|
| 88 |
+
data: {
|
| 89 |
+
ideaId: id,
|
| 90 |
+
taskId: taskId || null,
|
| 91 |
+
createdByUserId: userId,
|
| 92 |
+
url: parsed.data.url,
|
| 93 |
+
label: parsed.data.label,
|
| 94 |
+
description: parsed.data.description,
|
| 95 |
+
type: parsed.data.type || "OTHER",
|
| 96 |
+
},
|
| 97 |
+
});
|
| 98 |
+
|
| 99 |
+
const anonId = await getAnonId();
|
| 100 |
+
return NextResponse.json({ items: await mapSolutions(id, userId, anonId || null) }, { status: 201 });
|
| 101 |
+
}
|
app/api/ideas/[id]/upvote/route.ts
CHANGED
|
@@ -1,36 +1,58 @@
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
import { prisma } from "@/lib/prisma";
|
| 3 |
import { getAnonId } from "@/lib/identity";
|
|
|
|
| 4 |
|
| 5 |
export async function POST(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
|
|
|
|
|
| 6 |
const anonId = await getAnonId();
|
| 7 |
const { id } = await params;
|
| 8 |
|
| 9 |
-
if (!anonId)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
await prisma.
|
| 13 |
-
data: { ideaId: id, anonId },
|
| 14 |
-
});
|
| 15 |
-
} catch {
|
| 16 |
return NextResponse.json({ ok: true });
|
| 17 |
}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
await prisma.idea.update({ where: { id }, data: { upvotesCount: { increment: 1 } } });
|
| 20 |
return NextResponse.json({ ok: true });
|
| 21 |
}
|
| 22 |
|
| 23 |
export async function DELETE(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
|
|
|
|
|
| 24 |
const anonId = await getAnonId();
|
| 25 |
const { id } = await params;
|
| 26 |
|
| 27 |
-
if (!anonId)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
if (!existing) return NextResponse.json({ ok: true });
|
| 31 |
|
| 32 |
-
await prisma.vote.delete({ where: { ideaId_anonId: { ideaId: id, anonId } } });
|
| 33 |
await prisma.idea.update({ where: { id }, data: { upvotesCount: { decrement: 1 } } });
|
| 34 |
-
|
| 35 |
return NextResponse.json({ ok: true });
|
| 36 |
}
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
import { prisma } from "@/lib/prisma";
|
| 3 |
import { getAnonId } from "@/lib/identity";
|
| 4 |
+
import { auth } from "@/auth";
|
| 5 |
|
| 6 |
export async function POST(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
| 7 |
+
const session = await auth();
|
| 8 |
+
const userId = session?.user?.id ?? null;
|
| 9 |
const anonId = await getAnonId();
|
| 10 |
const { id } = await params;
|
| 11 |
|
| 12 |
+
if (!userId && !anonId) {
|
| 13 |
+
return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
if (userId) {
|
| 17 |
+
const existing = await prisma.ideaUserVote.findUnique({ where: { ideaId_userId: { ideaId: id, userId } } });
|
| 18 |
+
if (existing) return NextResponse.json({ ok: true });
|
| 19 |
|
| 20 |
+
await prisma.ideaUserVote.create({ data: { ideaId: id, userId } });
|
| 21 |
+
await prisma.idea.update({ where: { id }, data: { upvotesCount: { increment: 1 } } });
|
|
|
|
|
|
|
|
|
|
| 22 |
return NextResponse.json({ ok: true });
|
| 23 |
}
|
| 24 |
|
| 25 |
+
const existing = await prisma.vote.findUnique({ where: { ideaId_anonId: { ideaId: id, anonId: anonId! } } });
|
| 26 |
+
if (existing) return NextResponse.json({ ok: true });
|
| 27 |
+
|
| 28 |
+
await prisma.vote.create({ data: { ideaId: id, anonId: anonId! } });
|
| 29 |
await prisma.idea.update({ where: { id }, data: { upvotesCount: { increment: 1 } } });
|
| 30 |
return NextResponse.json({ ok: true });
|
| 31 |
}
|
| 32 |
|
| 33 |
export async function DELETE(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
| 34 |
+
const session = await auth();
|
| 35 |
+
const userId = session?.user?.id ?? null;
|
| 36 |
const anonId = await getAnonId();
|
| 37 |
const { id } = await params;
|
| 38 |
|
| 39 |
+
if (!userId && !anonId) {
|
| 40 |
+
return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
if (userId) {
|
| 44 |
+
const existing = await prisma.ideaUserVote.findUnique({ where: { ideaId_userId: { ideaId: id, userId } } });
|
| 45 |
+
if (!existing) return NextResponse.json({ ok: true });
|
| 46 |
|
| 47 |
+
await prisma.ideaUserVote.delete({ where: { ideaId_userId: { ideaId: id, userId } } });
|
| 48 |
+
await prisma.idea.update({ where: { id }, data: { upvotesCount: { decrement: 1 } } });
|
| 49 |
+
return NextResponse.json({ ok: true });
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
const existing = await prisma.vote.findUnique({ where: { ideaId_anonId: { ideaId: id, anonId: anonId! } } });
|
| 53 |
if (!existing) return NextResponse.json({ ok: true });
|
| 54 |
|
| 55 |
+
await prisma.vote.delete({ where: { ideaId_anonId: { ideaId: id, anonId: anonId! } } });
|
| 56 |
await prisma.idea.update({ where: { id }, data: { upvotesCount: { decrement: 1 } } });
|
|
|
|
| 57 |
return NextResponse.json({ ok: true });
|
| 58 |
}
|
app/api/ideas/[id]/work-vote/route.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
+
import { auth } from "@/auth";
|
| 3 |
+
import { prisma } from "@/lib/prisma";
|
| 4 |
+
|
| 5 |
+
async function responseFor(ideaId: string, userId: string) {
|
| 6 |
+
const count = await prisma.ideaWorkVote.count({ where: { ideaId } });
|
| 7 |
+
const mine = await prisma.ideaWorkVote.findUnique({ where: { ideaId_userId: { ideaId, userId } } });
|
| 8 |
+
return { working_count: count, working: Boolean(mine) };
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
export async function POST(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
| 12 |
+
const session = await auth();
|
| 13 |
+
const userId = session?.user?.id;
|
| 14 |
+
const { id } = await params;
|
| 15 |
+
|
| 16 |
+
if (!userId) return NextResponse.json({ error: "Developer login required" }, { status: 401 });
|
| 17 |
+
|
| 18 |
+
await prisma.ideaWorkVote.upsert({
|
| 19 |
+
where: { ideaId_userId: { ideaId: id, userId } },
|
| 20 |
+
create: { ideaId: id, userId },
|
| 21 |
+
update: {},
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
return NextResponse.json(await responseFor(id, userId));
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
export async function DELETE(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
| 28 |
+
const session = await auth();
|
| 29 |
+
const userId = session?.user?.id;
|
| 30 |
+
const { id } = await params;
|
| 31 |
+
|
| 32 |
+
if (!userId) return NextResponse.json({ error: "Developer login required" }, { status: 401 });
|
| 33 |
+
|
| 34 |
+
await prisma.ideaWorkVote.deleteMany({ where: { ideaId: id, userId } });
|
| 35 |
+
return NextResponse.json(await responseFor(id, userId));
|
| 36 |
+
}
|
app/api/ideas/route.ts
CHANGED
|
@@ -5,29 +5,31 @@ import { generateSpec } from "@/lib/llm";
|
|
| 5 |
import { getAnonId, getClientIp } from "@/lib/identity";
|
| 6 |
import { mapIdea, mapTask } from "@/lib/db-mappers";
|
| 7 |
import { scoreHot } from "@/lib/hot-score";
|
|
|
|
| 8 |
|
| 9 |
const createIdeaSchema = z.object({
|
| 10 |
raw_input_text: z.string().min(20).max(3000),
|
| 11 |
target_users: z.string().max(300).optional(),
|
| 12 |
platform: z.enum(["Web", "Mobile", "Desktop", "Any"]).optional(),
|
| 13 |
constraints: z.string().max(500).optional(),
|
|
|
|
| 14 |
});
|
| 15 |
|
| 16 |
const RATE_LIMIT_PER_HOUR = 5;
|
| 17 |
|
| 18 |
-
async function checkRateLimit(
|
| 19 |
const now = new Date();
|
| 20 |
const windowStart = `${now.getUTCFullYear()}-${now.getUTCMonth() + 1}-${now.getUTCDate()}-${now.getUTCHours()}`;
|
| 21 |
|
| 22 |
const existing = await prisma.submissionRateLimit.findUnique({
|
| 23 |
where: {
|
| 24 |
-
anonId_ipAddress_windowStart: { anonId, ipAddress, windowStart },
|
| 25 |
},
|
| 26 |
});
|
| 27 |
|
| 28 |
if (!existing) {
|
| 29 |
await prisma.submissionRateLimit.create({
|
| 30 |
-
data: { anonId, ipAddress, windowStart, count: 1 },
|
| 31 |
});
|
| 32 |
return true;
|
| 33 |
}
|
|
@@ -55,16 +57,28 @@ export async function GET(request: NextRequest) {
|
|
| 55 |
const ideas = await prisma.idea.findMany({
|
| 56 |
take: limit + 1,
|
| 57 |
where: cursorDate && !Number.isNaN(cursorDate.getTime()) ? { createdAt: { lt: cursorDate } } : undefined,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
orderBy: { createdAt: "desc" },
|
| 59 |
});
|
| 60 |
|
| 61 |
const hasMore = ideas.length > limit;
|
| 62 |
const page = hasMore ? ideas.slice(0, limit) : ideas;
|
| 63 |
|
| 64 |
-
const mapped = page.map((idea) =>
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
const items =
|
| 70 |
sort === "new"
|
|
@@ -78,12 +92,15 @@ export async function GET(request: NextRequest) {
|
|
| 78 |
export async function POST(request: NextRequest) {
|
| 79 |
const anonId = await getAnonId();
|
| 80 |
const ipAddress = await getClientIp();
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
|
|
|
| 84 |
}
|
| 85 |
|
| 86 |
-
const allowed = await checkRateLimit(
|
| 87 |
if (!allowed) {
|
| 88 |
return NextResponse.json({ error: "Rate limit exceeded. Try again later." }, { status: 429 });
|
| 89 |
}
|
|
@@ -98,9 +115,21 @@ export async function POST(request: NextRequest) {
|
|
| 98 |
try {
|
| 99 |
const spec = await generateSpec(parsed.data);
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
const idea = await prisma.idea.create({
|
| 102 |
data: {
|
| 103 |
-
createdByAnonId: anonId,
|
|
|
|
|
|
|
|
|
|
| 104 |
rawInputText: parsed.data.raw_input_text,
|
| 105 |
targetUsers: parsed.data.target_users,
|
| 106 |
platform: parsed.data.platform,
|
|
@@ -127,9 +156,11 @@ export async function POST(request: NextRequest) {
|
|
| 127 |
{
|
| 128 |
idea: {
|
| 129 |
...mapIdea(idea),
|
|
|
|
| 130 |
tasks: idea.tasks.map((task) => ({
|
| 131 |
...mapTask(task),
|
| 132 |
claimantNickname: null,
|
|
|
|
| 133 |
})),
|
| 134 |
},
|
| 135 |
},
|
|
|
|
| 5 |
import { getAnonId, getClientIp } from "@/lib/identity";
|
| 6 |
import { mapIdea, mapTask } from "@/lib/db-mappers";
|
| 7 |
import { scoreHot } from "@/lib/hot-score";
|
| 8 |
+
import { auth } from "@/auth";
|
| 9 |
|
| 10 |
const createIdeaSchema = z.object({
|
| 11 |
raw_input_text: z.string().min(20).max(3000),
|
| 12 |
target_users: z.string().max(300).optional(),
|
| 13 |
platform: z.enum(["Web", "Mobile", "Desktop", "Any"]).optional(),
|
| 14 |
constraints: z.string().max(500).optional(),
|
| 15 |
+
show_name: z.boolean().optional().default(false),
|
| 16 |
});
|
| 17 |
|
| 18 |
const RATE_LIMIT_PER_HOUR = 5;
|
| 19 |
|
| 20 |
+
async function checkRateLimit(rateKey: string, ipAddress: string): Promise<boolean> {
|
| 21 |
const now = new Date();
|
| 22 |
const windowStart = `${now.getUTCFullYear()}-${now.getUTCMonth() + 1}-${now.getUTCDate()}-${now.getUTCHours()}`;
|
| 23 |
|
| 24 |
const existing = await prisma.submissionRateLimit.findUnique({
|
| 25 |
where: {
|
| 26 |
+
anonId_ipAddress_windowStart: { anonId: rateKey, ipAddress, windowStart },
|
| 27 |
},
|
| 28 |
});
|
| 29 |
|
| 30 |
if (!existing) {
|
| 31 |
await prisma.submissionRateLimit.create({
|
| 32 |
+
data: { anonId: rateKey, ipAddress, windowStart, count: 1 },
|
| 33 |
});
|
| 34 |
return true;
|
| 35 |
}
|
|
|
|
| 57 |
const ideas = await prisma.idea.findMany({
|
| 58 |
take: limit + 1,
|
| 59 |
where: cursorDate && !Number.isNaN(cursorDate.getTime()) ? { createdAt: { lt: cursorDate } } : undefined,
|
| 60 |
+
include: {
|
| 61 |
+
createdByUser: {
|
| 62 |
+
select: { name: true, developerProfile: { select: { displayName: true } } },
|
| 63 |
+
},
|
| 64 |
+
},
|
| 65 |
orderBy: { createdAt: "desc" },
|
| 66 |
});
|
| 67 |
|
| 68 |
const hasMore = ideas.length > limit;
|
| 69 |
const page = hasMore ? ideas.slice(0, limit) : ideas;
|
| 70 |
|
| 71 |
+
const mapped = page.map((idea) => {
|
| 72 |
+
const visibleName =
|
| 73 |
+
idea.submitterVisibleName || idea.createdByUser?.developerProfile?.displayName || idea.createdByUser?.name || null;
|
| 74 |
+
|
| 75 |
+
return {
|
| 76 |
+
...mapIdea(idea),
|
| 77 |
+
comment_count: idea.commentsCount,
|
| 78 |
+
submitter_label: idea.isAnonymous ? "Anonymous" : visibleName || "Member",
|
| 79 |
+
is_anonymous: idea.isAnonymous,
|
| 80 |
+
};
|
| 81 |
+
});
|
| 82 |
|
| 83 |
const items =
|
| 84 |
sort === "new"
|
|
|
|
| 92 |
export async function POST(request: NextRequest) {
|
| 93 |
const anonId = await getAnonId();
|
| 94 |
const ipAddress = await getClientIp();
|
| 95 |
+
const session = await auth();
|
| 96 |
+
const userId = session?.user?.id ?? null;
|
| 97 |
|
| 98 |
+
const rateKey = anonId || (userId ? `user:${userId}` : "");
|
| 99 |
+
if (!rateKey) {
|
| 100 |
+
return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 101 |
}
|
| 102 |
|
| 103 |
+
const allowed = await checkRateLimit(rateKey, ipAddress);
|
| 104 |
if (!allowed) {
|
| 105 |
return NextResponse.json({ error: "Rate limit exceeded. Try again later." }, { status: 429 });
|
| 106 |
}
|
|
|
|
| 115 |
try {
|
| 116 |
const spec = await generateSpec(parsed.data);
|
| 117 |
|
| 118 |
+
let submitterVisibleName: string | null = null;
|
| 119 |
+
const isAnonymous = !(parsed.data.show_name && userId);
|
| 120 |
+
|
| 121 |
+
if (!isAnonymous && userId) {
|
| 122 |
+
const profile = await prisma.developerProfile.findUnique({ where: { userId } });
|
| 123 |
+
submitterVisibleName =
|
| 124 |
+
profile?.displayName || session?.user?.name || session?.user?.email || "Member";
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
const idea = await prisma.idea.create({
|
| 128 |
data: {
|
| 129 |
+
createdByAnonId: anonId || null,
|
| 130 |
+
createdByUserId: userId,
|
| 131 |
+
isAnonymous,
|
| 132 |
+
submitterVisibleName,
|
| 133 |
rawInputText: parsed.data.raw_input_text,
|
| 134 |
targetUsers: parsed.data.target_users,
|
| 135 |
platform: parsed.data.platform,
|
|
|
|
| 156 |
{
|
| 157 |
idea: {
|
| 158 |
...mapIdea(idea),
|
| 159 |
+
submitter_label: idea.isAnonymous ? "Anonymous" : submitterVisibleName || "Member",
|
| 160 |
tasks: idea.tasks.map((task) => ({
|
| 161 |
...mapTask(task),
|
| 162 |
claimantNickname: null,
|
| 163 |
+
claimantDisplayName: null,
|
| 164 |
})),
|
| 165 |
},
|
| 166 |
},
|
app/api/me/profile/route.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
+
import { z } from "zod";
|
| 3 |
+
import { prisma } from "@/lib/prisma";
|
| 4 |
+
import { auth } from "@/auth";
|
| 5 |
+
|
| 6 |
+
const schema = z.object({
|
| 7 |
+
displayName: z.string().min(2).max(50),
|
| 8 |
+
headline: z.string().max(120).optional(),
|
| 9 |
+
bio: z.string().max(500).optional(),
|
| 10 |
+
githubUrl: z.string().url().max(200).optional().or(z.literal("")),
|
| 11 |
+
websiteUrl: z.string().url().max(200).optional().or(z.literal("")),
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
export async function GET() {
|
| 15 |
+
const session = await auth();
|
| 16 |
+
const userId = session?.user?.id;
|
| 17 |
+
if (!userId) {
|
| 18 |
+
return NextResponse.json({ error: "Authentication required" }, { status: 401 });
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
const profile = await prisma.developerProfile.findUnique({ where: { userId } });
|
| 22 |
+
return NextResponse.json({ profile });
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
export async function POST(request: NextRequest) {
|
| 26 |
+
const session = await auth();
|
| 27 |
+
const userId = session?.user?.id;
|
| 28 |
+
if (!userId) {
|
| 29 |
+
return NextResponse.json({ error: "Authentication required" }, { status: 401 });
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
const body = await request.json();
|
| 33 |
+
const parsed = schema.safeParse(body);
|
| 34 |
+
if (!parsed.success) {
|
| 35 |
+
return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
const profile = await prisma.developerProfile.upsert({
|
| 39 |
+
where: { userId },
|
| 40 |
+
create: {
|
| 41 |
+
userId,
|
| 42 |
+
displayName: parsed.data.displayName.trim(),
|
| 43 |
+
headline: parsed.data.headline?.trim() || null,
|
| 44 |
+
bio: parsed.data.bio?.trim() || null,
|
| 45 |
+
githubUrl: parsed.data.githubUrl?.trim() || null,
|
| 46 |
+
websiteUrl: parsed.data.websiteUrl?.trim() || null,
|
| 47 |
+
},
|
| 48 |
+
update: {
|
| 49 |
+
displayName: parsed.data.displayName.trim(),
|
| 50 |
+
headline: parsed.data.headline?.trim() || null,
|
| 51 |
+
bio: parsed.data.bio?.trim() || null,
|
| 52 |
+
githubUrl: parsed.data.githubUrl?.trim() || null,
|
| 53 |
+
websiteUrl: parsed.data.websiteUrl?.trim() || null,
|
| 54 |
+
},
|
| 55 |
+
});
|
| 56 |
+
|
| 57 |
+
return NextResponse.json({ profile });
|
| 58 |
+
}
|
app/api/solutions/[solutionId]/approve/route.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
+
import { auth } from "@/auth";
|
| 3 |
+
import { prisma } from "@/lib/prisma";
|
| 4 |
+
import { getAnonId } from "@/lib/identity";
|
| 5 |
+
|
| 6 |
+
export async function POST(_: NextRequest, { params }: { params: Promise<{ solutionId: string }> }) {
|
| 7 |
+
const session = await auth();
|
| 8 |
+
const userId = session?.user?.id ?? null;
|
| 9 |
+
const anonId = await getAnonId();
|
| 10 |
+
const { solutionId } = await params;
|
| 11 |
+
|
| 12 |
+
const solution = await prisma.solution.findUnique({
|
| 13 |
+
where: { id: solutionId },
|
| 14 |
+
include: { idea: true },
|
| 15 |
+
});
|
| 16 |
+
|
| 17 |
+
if (!solution) {
|
| 18 |
+
return NextResponse.json({ error: "Solution not found" }, { status: 404 });
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
const canApproveByUser = Boolean(userId) && solution.idea.createdByUserId === userId;
|
| 22 |
+
const canApproveByAnon = Boolean(anonId) && !solution.idea.createdByUserId && solution.idea.createdByAnonId === anonId;
|
| 23 |
+
|
| 24 |
+
if (!canApproveByUser && !canApproveByAnon) {
|
| 25 |
+
return NextResponse.json({ error: "Only idea submitter can approve" }, { status: 403 });
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
const updated = await prisma.solution.update({
|
| 29 |
+
where: { id: solutionId },
|
| 30 |
+
data: {
|
| 31 |
+
approvedAt: new Date(),
|
| 32 |
+
approvedBySubmitterUserId: userId,
|
| 33 |
+
approvedBySubmitterAnonId: userId ? null : anonId,
|
| 34 |
+
},
|
| 35 |
+
});
|
| 36 |
+
|
| 37 |
+
return NextResponse.json({ solution: updated });
|
| 38 |
+
}
|
app/api/solutions/[solutionId]/comments/route.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
+
import { z } from "zod";
|
| 3 |
+
import { auth } from "@/auth";
|
| 4 |
+
import { prisma } from "@/lib/prisma";
|
| 5 |
+
import { getAnonId } from "@/lib/identity";
|
| 6 |
+
|
| 7 |
+
const schema = z.object({
|
| 8 |
+
body: z.string().min(1).max(1000),
|
| 9 |
+
});
|
| 10 |
+
|
| 11 |
+
async function listComments(solutionId: string) {
|
| 12 |
+
const comments = await prisma.solutionComment.findMany({
|
| 13 |
+
where: { solutionId },
|
| 14 |
+
include: {
|
| 15 |
+
createdByUser: {
|
| 16 |
+
include: {
|
| 17 |
+
developerProfile: { select: { displayName: true } },
|
| 18 |
+
},
|
| 19 |
+
},
|
| 20 |
+
},
|
| 21 |
+
orderBy: { createdAt: "desc" },
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
return comments.map((comment) => ({
|
| 25 |
+
...comment,
|
| 26 |
+
author_label:
|
| 27 |
+
comment.createdByUser?.developerProfile?.displayName || comment.createdByUser?.name || (comment.createdByUserId ? "Member" : "Anon"),
|
| 28 |
+
}));
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
export async function GET(_: NextRequest, { params }: { params: Promise<{ solutionId: string }> }) {
|
| 32 |
+
const { solutionId } = await params;
|
| 33 |
+
return NextResponse.json({ items: await listComments(solutionId) });
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
export async function POST(request: NextRequest, { params }: { params: Promise<{ solutionId: string }> }) {
|
| 37 |
+
const session = await auth();
|
| 38 |
+
const userId = session?.user?.id ?? null;
|
| 39 |
+
const anonId = await getAnonId();
|
| 40 |
+
const { solutionId } = await params;
|
| 41 |
+
|
| 42 |
+
if (!userId && !anonId) {
|
| 43 |
+
return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
const body = await request.json();
|
| 47 |
+
const parsed = schema.safeParse(body);
|
| 48 |
+
if (!parsed.success) {
|
| 49 |
+
return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
await prisma.solutionComment.create({
|
| 53 |
+
data: {
|
| 54 |
+
solutionId,
|
| 55 |
+
body: parsed.data.body,
|
| 56 |
+
createdByUserId: userId,
|
| 57 |
+
createdByAnonId: userId ? null : anonId,
|
| 58 |
+
},
|
| 59 |
+
});
|
| 60 |
+
|
| 61 |
+
return NextResponse.json({ items: await listComments(solutionId) }, { status: 201 });
|
| 62 |
+
}
|
app/api/solutions/[solutionId]/vote/route.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
+
import { z } from "zod";
|
| 3 |
+
import { auth } from "@/auth";
|
| 4 |
+
import { prisma } from "@/lib/prisma";
|
| 5 |
+
import { getAnonId } from "@/lib/identity";
|
| 6 |
+
|
| 7 |
+
const schema = z.object({
|
| 8 |
+
value: z.union([z.literal(1), z.literal(-1)]),
|
| 9 |
+
});
|
| 10 |
+
|
| 11 |
+
async function score(solutionId: string) {
|
| 12 |
+
const userVotes = await prisma.solutionUserVote.findMany({ where: { solutionId }, select: { value: true } });
|
| 13 |
+
const anonVotes = await prisma.solutionAnonVote.findMany({ where: { solutionId }, select: { value: true } });
|
| 14 |
+
return userVotes.reduce((sum, vote) => sum + vote.value, 0) + anonVotes.reduce((sum, vote) => sum + vote.value, 0);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export async function POST(request: NextRequest, { params }: { params: Promise<{ solutionId: string }> }) {
|
| 18 |
+
const session = await auth();
|
| 19 |
+
const userId = session?.user?.id ?? null;
|
| 20 |
+
const anonId = await getAnonId();
|
| 21 |
+
const { solutionId } = await params;
|
| 22 |
+
|
| 23 |
+
if (!userId && !anonId) {
|
| 24 |
+
return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
const json = await request.json();
|
| 28 |
+
const parsed = schema.safeParse(json);
|
| 29 |
+
if (!parsed.success) {
|
| 30 |
+
return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
if (userId) {
|
| 34 |
+
await prisma.solutionUserVote.upsert({
|
| 35 |
+
where: { solutionId_userId: { solutionId, userId } },
|
| 36 |
+
create: { solutionId, userId, value: parsed.data.value },
|
| 37 |
+
update: { value: parsed.data.value },
|
| 38 |
+
});
|
| 39 |
+
} else {
|
| 40 |
+
await prisma.solutionAnonVote.upsert({
|
| 41 |
+
where: { solutionId_anonId: { solutionId, anonId: anonId! } },
|
| 42 |
+
create: { solutionId, anonId: anonId!, value: parsed.data.value },
|
| 43 |
+
update: { value: parsed.data.value },
|
| 44 |
+
});
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
return NextResponse.json({ score: await score(solutionId), myVote: parsed.data.value });
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
export async function DELETE(_: NextRequest, { params }: { params: Promise<{ solutionId: string }> }) {
|
| 51 |
+
const session = await auth();
|
| 52 |
+
const userId = session?.user?.id ?? null;
|
| 53 |
+
const anonId = await getAnonId();
|
| 54 |
+
const { solutionId } = await params;
|
| 55 |
+
|
| 56 |
+
if (!userId && !anonId) {
|
| 57 |
+
return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
if (userId) {
|
| 61 |
+
await prisma.solutionUserVote.deleteMany({ where: { solutionId, userId } });
|
| 62 |
+
} else {
|
| 63 |
+
await prisma.solutionAnonVote.deleteMany({ where: { solutionId, anonId: anonId! } });
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
return NextResponse.json({ score: await score(solutionId), myVote: 0 });
|
| 67 |
+
}
|
app/api/task-links/[linkId]/route.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
import { prisma } from "@/lib/prisma";
|
|
|
|
| 3 |
import { getAnonId } from "@/lib/identity";
|
| 4 |
|
| 5 |
export async function DELETE(_: NextRequest, { params }: { params: Promise<{ linkId: string }> }) {
|
|
|
|
|
|
|
| 6 |
const anonId = await getAnonId();
|
| 7 |
const { linkId } = await params;
|
| 8 |
|
| 9 |
-
if (!anonId) return NextResponse.json({ error: "Missing
|
| 10 |
|
| 11 |
const link = await prisma.taskLink.findUnique({ where: { id: linkId }, include: { task: true } });
|
| 12 |
if (!link) return NextResponse.json({ error: "Not found" }, { status: 404 });
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
return NextResponse.json({ error: "Not allowed" }, { status: 403 });
|
| 16 |
}
|
| 17 |
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
import { prisma } from "@/lib/prisma";
|
| 3 |
+
import { auth } from "@/auth";
|
| 4 |
import { getAnonId } from "@/lib/identity";
|
| 5 |
|
| 6 |
export async function DELETE(_: NextRequest, { params }: { params: Promise<{ linkId: string }> }) {
|
| 7 |
+
const session = await auth();
|
| 8 |
+
const userId = session?.user?.id ?? null;
|
| 9 |
const anonId = await getAnonId();
|
| 10 |
const { linkId } = await params;
|
| 11 |
|
| 12 |
+
if (!userId && !anonId) return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 13 |
|
| 14 |
const link = await prisma.taskLink.findUnique({ where: { id: linkId }, include: { task: true } });
|
| 15 |
if (!link) return NextResponse.json({ error: "Not found" }, { status: 404 });
|
| 16 |
|
| 17 |
+
const canDeleteAsUser = Boolean(userId) && (link.createdByUserId === userId || link.task.claimedByUserId === userId);
|
| 18 |
+
const canDeleteAsAnon = Boolean(anonId) && !link.task.claimedByUserId && (link.createdByAnonId === anonId || link.task.claimedByAnonId === anonId);
|
| 19 |
+
|
| 20 |
+
if (!canDeleteAsUser && !canDeleteAsAnon) {
|
| 21 |
return NextResponse.json({ error: "Not allowed" }, { status: 403 });
|
| 22 |
}
|
| 23 |
|
app/api/tasks/[taskId]/claim/route.ts
CHANGED
|
@@ -2,36 +2,47 @@ import { NextRequest, NextResponse } from "next/server";
|
|
| 2 |
import { prisma } from "@/lib/prisma";
|
| 3 |
import { getAnonId } from "@/lib/identity";
|
| 4 |
import { mapTask } from "@/lib/db-mappers";
|
|
|
|
| 5 |
|
| 6 |
export async function POST(_: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
|
|
|
|
|
|
|
| 7 |
const anonId = await getAnonId();
|
| 8 |
const { taskId } = await params;
|
| 9 |
|
| 10 |
-
if (!anonId) return NextResponse.json({ error: "Missing
|
| 11 |
|
| 12 |
const task = await prisma.task.findUnique({ where: { id: taskId } });
|
| 13 |
if (!task) return NextResponse.json({ error: "Task not found" }, { status: 404 });
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
return NextResponse.json({ error: "Task already claimed" }, { status: 409 });
|
| 16 |
}
|
| 17 |
|
| 18 |
const updated = await prisma.task.update({
|
| 19 |
where: { id: taskId },
|
| 20 |
data: {
|
| 21 |
-
|
|
|
|
| 22 |
claimedAt: new Date(),
|
| 23 |
status: task.status === "OPEN" ? "IN_PROGRESS" : task.status,
|
| 24 |
},
|
| 25 |
include: { links: true },
|
| 26 |
});
|
| 27 |
|
| 28 |
-
const
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
return NextResponse.json({
|
| 32 |
task: {
|
| 33 |
-
...
|
| 34 |
-
claimantNickname
|
|
|
|
| 35 |
},
|
| 36 |
});
|
| 37 |
}
|
|
|
|
| 2 |
import { prisma } from "@/lib/prisma";
|
| 3 |
import { getAnonId } from "@/lib/identity";
|
| 4 |
import { mapTask } from "@/lib/db-mappers";
|
| 5 |
+
import { auth } from "@/auth";
|
| 6 |
|
| 7 |
export async function POST(_: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
|
| 8 |
+
const session = await auth();
|
| 9 |
+
const userId = session?.user?.id ?? null;
|
| 10 |
const anonId = await getAnonId();
|
| 11 |
const { taskId } = await params;
|
| 12 |
|
| 13 |
+
if (!userId && !anonId) return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 14 |
|
| 15 |
const task = await prisma.task.findUnique({ where: { id: taskId } });
|
| 16 |
if (!task) return NextResponse.json({ error: "Task not found" }, { status: 404 });
|
| 17 |
+
|
| 18 |
+
const claimedByOtherUser = task.claimedByUserId && task.claimedByUserId !== userId;
|
| 19 |
+
const claimedByOtherAnon = !task.claimedByUserId && task.claimedByAnonId && task.claimedByAnonId !== anonId;
|
| 20 |
+
if (claimedByOtherUser || claimedByOtherAnon) {
|
| 21 |
return NextResponse.json({ error: "Task already claimed" }, { status: 409 });
|
| 22 |
}
|
| 23 |
|
| 24 |
const updated = await prisma.task.update({
|
| 25 |
where: { id: taskId },
|
| 26 |
data: {
|
| 27 |
+
claimedByUserId: userId,
|
| 28 |
+
claimedByAnonId: userId ? null : anonId,
|
| 29 |
claimedAt: new Date(),
|
| 30 |
status: task.status === "OPEN" ? "IN_PROGRESS" : task.status,
|
| 31 |
},
|
| 32 |
include: { links: true },
|
| 33 |
});
|
| 34 |
|
| 35 |
+
const claimantNickname = userId
|
| 36 |
+
? (
|
| 37 |
+
await prisma.developerProfile.findUnique({ where: { userId }, include: { user: true } })
|
| 38 |
+
)?.displayName || session?.user?.name || "Member"
|
| 39 |
+
: (await prisma.nickname.findUnique({ where: { anonId: anonId! } }))?.nickname || "anon";
|
| 40 |
|
| 41 |
return NextResponse.json({
|
| 42 |
task: {
|
| 43 |
+
...mapTask(updated),
|
| 44 |
+
claimantNickname,
|
| 45 |
+
claimantDisplayName: claimantNickname,
|
| 46 |
},
|
| 47 |
});
|
| 48 |
}
|
app/api/tasks/[taskId]/links/route.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
import { z } from "zod";
|
| 3 |
import { prisma } from "@/lib/prisma";
|
|
|
|
| 4 |
import { getAnonId } from "@/lib/identity";
|
| 5 |
|
| 6 |
const schema = z.object({
|
|
@@ -9,10 +10,12 @@ const schema = z.object({
|
|
| 9 |
});
|
| 10 |
|
| 11 |
export async function POST(request: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
|
|
|
|
|
|
|
| 12 |
const anonId = await getAnonId();
|
| 13 |
const { taskId } = await params;
|
| 14 |
|
| 15 |
-
if (!anonId) return NextResponse.json({ error: "Missing
|
| 16 |
|
| 17 |
const json = await request.json();
|
| 18 |
const parsed = schema.safeParse(json);
|
|
@@ -24,7 +27,8 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
|
| 24 |
const task = await prisma.task.findUnique({ where: { id: taskId } });
|
| 25 |
if (!task) return NextResponse.json({ error: "Task not found" }, { status: 404 });
|
| 26 |
|
| 27 |
-
|
|
|
|
| 28 |
return NextResponse.json({ error: "Only claimant can add links" }, { status: 403 });
|
| 29 |
}
|
| 30 |
|
|
@@ -33,7 +37,8 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
|
| 33 |
taskId,
|
| 34 |
url: parsed.data.url,
|
| 35 |
label: parsed.data.label,
|
| 36 |
-
|
|
|
|
| 37 |
},
|
| 38 |
});
|
| 39 |
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
import { z } from "zod";
|
| 3 |
import { prisma } from "@/lib/prisma";
|
| 4 |
+
import { auth } from "@/auth";
|
| 5 |
import { getAnonId } from "@/lib/identity";
|
| 6 |
|
| 7 |
const schema = z.object({
|
|
|
|
| 10 |
});
|
| 11 |
|
| 12 |
export async function POST(request: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
|
| 13 |
+
const session = await auth();
|
| 14 |
+
const userId = session?.user?.id ?? null;
|
| 15 |
const anonId = await getAnonId();
|
| 16 |
const { taskId } = await params;
|
| 17 |
|
| 18 |
+
if (!userId && !anonId) return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 19 |
|
| 20 |
const json = await request.json();
|
| 21 |
const parsed = schema.safeParse(json);
|
|
|
|
| 27 |
const task = await prisma.task.findUnique({ where: { id: taskId } });
|
| 28 |
if (!task) return NextResponse.json({ error: "Task not found" }, { status: 404 });
|
| 29 |
|
| 30 |
+
const allowed = userId ? task.claimedByUserId === userId : !task.claimedByUserId && task.claimedByAnonId === anonId;
|
| 31 |
+
if (!allowed) {
|
| 32 |
return NextResponse.json({ error: "Only claimant can add links" }, { status: 403 });
|
| 33 |
}
|
| 34 |
|
|
|
|
| 37 |
taskId,
|
| 38 |
url: parsed.data.url,
|
| 39 |
label: parsed.data.label,
|
| 40 |
+
createdByUserId: userId,
|
| 41 |
+
createdByAnonId: userId ? null : anonId,
|
| 42 |
},
|
| 43 |
});
|
| 44 |
|
app/api/tasks/[taskId]/status/route.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
import { z } from "zod";
|
| 3 |
import { prisma } from "@/lib/prisma";
|
| 4 |
-
import { getAnonId } from "@/lib/identity";
|
| 5 |
import { mapTask } from "@/lib/db-mappers";
|
|
|
|
|
|
|
| 6 |
|
| 7 |
const schema = z.object({
|
| 8 |
status: z.enum(["OPEN", "IN_PROGRESS", "DONE"]),
|
| 9 |
});
|
| 10 |
|
| 11 |
export async function POST(request: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
|
|
|
|
|
|
|
| 12 |
const anonId = await getAnonId();
|
| 13 |
const { taskId } = await params;
|
| 14 |
|
| 15 |
-
if (!anonId) return NextResponse.json({ error: "Missing
|
| 16 |
|
| 17 |
const json = await request.json();
|
| 18 |
const parsed = schema.safeParse(json);
|
|
@@ -23,27 +26,41 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
|
| 23 |
const task = await prisma.task.findUnique({ where: { id: taskId } });
|
| 24 |
if (!task) return NextResponse.json({ error: "Task not found" }, { status: 404 });
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
return NextResponse.json({ error: "Only claimant can change status" }, { status: 403 });
|
| 28 |
}
|
| 29 |
|
| 30 |
-
const nextClaimedBy = task.claimedByAnonId ?? anonId;
|
| 31 |
const updated = await prisma.task.update({
|
| 32 |
where: { id: taskId },
|
| 33 |
data: {
|
| 34 |
status: parsed.data.status,
|
| 35 |
-
|
|
|
|
| 36 |
claimedAt: task.claimedAt ?? new Date(),
|
| 37 |
},
|
| 38 |
include: { links: true },
|
| 39 |
});
|
| 40 |
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
return NextResponse.json({
|
| 44 |
task: {
|
| 45 |
...mapTask(updated),
|
| 46 |
-
claimantNickname:
|
|
|
|
| 47 |
},
|
| 48 |
});
|
| 49 |
}
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
import { z } from "zod";
|
| 3 |
import { prisma } from "@/lib/prisma";
|
|
|
|
| 4 |
import { mapTask } from "@/lib/db-mappers";
|
| 5 |
+
import { auth } from "@/auth";
|
| 6 |
+
import { getAnonId } from "@/lib/identity";
|
| 7 |
|
| 8 |
const schema = z.object({
|
| 9 |
status: z.enum(["OPEN", "IN_PROGRESS", "DONE"]),
|
| 10 |
});
|
| 11 |
|
| 12 |
export async function POST(request: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
|
| 13 |
+
const session = await auth();
|
| 14 |
+
const userId = session?.user?.id ?? null;
|
| 15 |
const anonId = await getAnonId();
|
| 16 |
const { taskId } = await params;
|
| 17 |
|
| 18 |
+
if (!userId && !anonId) return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 19 |
|
| 20 |
const json = await request.json();
|
| 21 |
const parsed = schema.safeParse(json);
|
|
|
|
| 26 |
const task = await prisma.task.findUnique({ where: { id: taskId } });
|
| 27 |
if (!task) return NextResponse.json({ error: "Task not found" }, { status: 404 });
|
| 28 |
|
| 29 |
+
const allowed = userId
|
| 30 |
+
? !task.claimedByUserId || task.claimedByUserId === userId
|
| 31 |
+
: !task.claimedByUserId && (!task.claimedByAnonId || task.claimedByAnonId === anonId);
|
| 32 |
+
|
| 33 |
+
if (!allowed) {
|
| 34 |
return NextResponse.json({ error: "Only claimant can change status" }, { status: 403 });
|
| 35 |
}
|
| 36 |
|
|
|
|
| 37 |
const updated = await prisma.task.update({
|
| 38 |
where: { id: taskId },
|
| 39 |
data: {
|
| 40 |
status: parsed.data.status,
|
| 41 |
+
claimedByUserId: task.claimedByUserId ?? userId,
|
| 42 |
+
claimedByAnonId: task.claimedByUserId ? null : task.claimedByAnonId ?? (userId ? null : anonId),
|
| 43 |
claimedAt: task.claimedAt ?? new Date(),
|
| 44 |
},
|
| 45 |
include: { links: true },
|
| 46 |
});
|
| 47 |
|
| 48 |
+
let claimantDisplayName: string | null = null;
|
| 49 |
+
if (updated.claimedByUserId) {
|
| 50 |
+
const profile = await prisma.developerProfile.findUnique({
|
| 51 |
+
where: { userId: updated.claimedByUserId },
|
| 52 |
+
include: { user: true },
|
| 53 |
+
});
|
| 54 |
+
claimantDisplayName = profile?.displayName || profile?.user.name || "Member";
|
| 55 |
+
} else if (updated.claimedByAnonId) {
|
| 56 |
+
claimantDisplayName = (await prisma.nickname.findUnique({ where: { anonId: updated.claimedByAnonId } }))?.nickname || "anon";
|
| 57 |
+
}
|
| 58 |
|
| 59 |
return NextResponse.json({
|
| 60 |
task: {
|
| 61 |
...mapTask(updated),
|
| 62 |
+
claimantNickname: claimantDisplayName,
|
| 63 |
+
claimantDisplayName,
|
| 64 |
},
|
| 65 |
});
|
| 66 |
}
|
app/api/tasks/[taskId]/unclaim/route.ts
CHANGED
|
@@ -1,23 +1,29 @@
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
import { prisma } from "@/lib/prisma";
|
| 3 |
-
import { getAnonId } from "@/lib/identity";
|
| 4 |
import { mapTask } from "@/lib/db-mappers";
|
|
|
|
|
|
|
| 5 |
|
| 6 |
export async function POST(_: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
|
|
|
|
|
|
|
| 7 |
const anonId = await getAnonId();
|
| 8 |
const { taskId } = await params;
|
| 9 |
|
| 10 |
-
if (!anonId) return NextResponse.json({ error: "Missing
|
| 11 |
|
| 12 |
const task = await prisma.task.findUnique({ where: { id: taskId } });
|
| 13 |
if (!task) return NextResponse.json({ error: "Task not found" }, { status: 404 });
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
return NextResponse.json({ error: "Only claimant can unclaim" }, { status: 403 });
|
| 16 |
}
|
| 17 |
|
| 18 |
const updated = await prisma.task.update({
|
| 19 |
where: { id: taskId },
|
| 20 |
data: {
|
|
|
|
| 21 |
claimedByAnonId: null,
|
| 22 |
claimedAt: null,
|
| 23 |
status: "OPEN",
|
|
@@ -29,6 +35,7 @@ export async function POST(_: NextRequest, { params }: { params: Promise<{ taskI
|
|
| 29 |
task: {
|
| 30 |
...mapTask(updated),
|
| 31 |
claimantNickname: null,
|
|
|
|
| 32 |
},
|
| 33 |
});
|
| 34 |
}
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
import { prisma } from "@/lib/prisma";
|
|
|
|
| 3 |
import { mapTask } from "@/lib/db-mappers";
|
| 4 |
+
import { auth } from "@/auth";
|
| 5 |
+
import { getAnonId } from "@/lib/identity";
|
| 6 |
|
| 7 |
export async function POST(_: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
|
| 8 |
+
const session = await auth();
|
| 9 |
+
const userId = session?.user?.id ?? null;
|
| 10 |
const anonId = await getAnonId();
|
| 11 |
const { taskId } = await params;
|
| 12 |
|
| 13 |
+
if (!userId && !anonId) return NextResponse.json({ error: "Missing identity" }, { status: 400 });
|
| 14 |
|
| 15 |
const task = await prisma.task.findUnique({ where: { id: taskId } });
|
| 16 |
if (!task) return NextResponse.json({ error: "Task not found" }, { status: 404 });
|
| 17 |
+
|
| 18 |
+
const allowed = userId ? task.claimedByUserId === userId : !task.claimedByUserId && task.claimedByAnonId === anonId;
|
| 19 |
+
if (!allowed) {
|
| 20 |
return NextResponse.json({ error: "Only claimant can unclaim" }, { status: 403 });
|
| 21 |
}
|
| 22 |
|
| 23 |
const updated = await prisma.task.update({
|
| 24 |
where: { id: taskId },
|
| 25 |
data: {
|
| 26 |
+
claimedByUserId: null,
|
| 27 |
claimedByAnonId: null,
|
| 28 |
claimedAt: null,
|
| 29 |
status: "OPEN",
|
|
|
|
| 35 |
task: {
|
| 36 |
...mapTask(updated),
|
| 37 |
claimantNickname: null,
|
| 38 |
+
claimantDisplayName: null,
|
| 39 |
},
|
| 40 |
});
|
| 41 |
}
|
app/api/tasks/[taskId]/work-vote/route.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
+
import { auth } from "@/auth";
|
| 3 |
+
import { prisma } from "@/lib/prisma";
|
| 4 |
+
|
| 5 |
+
async function responseFor(taskId: string, userId: string) {
|
| 6 |
+
const count = await prisma.taskWorkVote.count({ where: { taskId } });
|
| 7 |
+
const mine = await prisma.taskWorkVote.findUnique({ where: { taskId_userId: { taskId, userId } } });
|
| 8 |
+
return { working_count: count, working: Boolean(mine) };
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
export async function POST(_: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
|
| 12 |
+
const session = await auth();
|
| 13 |
+
const userId = session?.user?.id;
|
| 14 |
+
const { taskId } = await params;
|
| 15 |
+
|
| 16 |
+
if (!userId) return NextResponse.json({ error: "Developer login required" }, { status: 401 });
|
| 17 |
+
|
| 18 |
+
await prisma.taskWorkVote.upsert({
|
| 19 |
+
where: { taskId_userId: { taskId, userId } },
|
| 20 |
+
create: { taskId, userId },
|
| 21 |
+
update: {},
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
return NextResponse.json(await responseFor(taskId, userId));
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
export async function DELETE(_: NextRequest, { params }: { params: Promise<{ taskId: string }> }) {
|
| 28 |
+
const session = await auth();
|
| 29 |
+
const userId = session?.user?.id;
|
| 30 |
+
const { taskId } = await params;
|
| 31 |
+
|
| 32 |
+
if (!userId) return NextResponse.json({ error: "Developer login required" }, { status: 401 });
|
| 33 |
+
|
| 34 |
+
await prisma.taskWorkVote.deleteMany({ where: { taskId, userId } });
|
| 35 |
+
return NextResponse.json(await responseFor(taskId, userId));
|
| 36 |
+
}
|
app/ideas/[id]/page.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { prisma } from "@/lib/prisma";
|
|
| 3 |
import { mapIdea, mapTask } from "@/lib/db-mappers";
|
| 4 |
import { getAnonId, getNickname } from "@/lib/identity";
|
| 5 |
import { IdeaDetailClient } from "@/components/IdeaDetailClient";
|
|
|
|
| 6 |
|
| 7 |
const ALLOWED_STATUS = new Set(["OPEN", "IN_PROGRESS", "DONE"] as const);
|
| 8 |
|
|
@@ -10,12 +11,40 @@ export default async function IdeaPage({ params }: { params: Promise<{ id: strin
|
|
| 10 |
const { id } = await params;
|
| 11 |
const anonId = await getAnonId();
|
| 12 |
const nickname = await getNickname();
|
|
|
|
|
|
|
| 13 |
|
| 14 |
const idea = await prisma.idea.findUnique({
|
| 15 |
where: { id },
|
| 16 |
include: {
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
},
|
| 20 |
});
|
| 21 |
|
|
@@ -23,9 +52,9 @@ export default async function IdeaPage({ params }: { params: Promise<{ id: strin
|
|
| 23 |
notFound();
|
| 24 |
}
|
| 25 |
|
| 26 |
-
const
|
| 27 |
-
?
|
| 28 |
-
:
|
| 29 |
|
| 30 |
const claimedAnonIds = Array.from(
|
| 31 |
new Set(idea.tasks.map((task) => task.claimedByAnonId).filter((value): value is string => Boolean(value)))
|
|
@@ -39,19 +68,66 @@ export default async function IdeaPage({ params }: { params: Promise<{ id: strin
|
|
| 39 |
|
| 40 |
const payload = {
|
| 41 |
...mapIdea(idea),
|
|
|
|
|
|
|
|
|
|
| 42 |
viewerAnonId: anonId,
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
return {
|
| 46 |
...mapped,
|
| 47 |
-
claimantNickname:
|
|
|
|
|
|
|
|
|
|
| 48 |
status: ALLOWED_STATUS.has(mapped.status as "OPEN" | "IN_PROGRESS" | "DONE")
|
| 49 |
? (mapped.status as "OPEN" | "IN_PROGRESS" | "DONE")
|
| 50 |
: "OPEN",
|
| 51 |
};
|
| 52 |
}),
|
| 53 |
-
comments: idea.comments.map((
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
};
|
| 55 |
|
| 56 |
-
return <IdeaDetailClient initialIdea={payload} isVoted={
|
| 57 |
}
|
|
|
|
| 3 |
import { mapIdea, mapTask } from "@/lib/db-mappers";
|
| 4 |
import { getAnonId, getNickname } from "@/lib/identity";
|
| 5 |
import { IdeaDetailClient } from "@/components/IdeaDetailClient";
|
| 6 |
+
import { auth } from "@/auth";
|
| 7 |
|
| 8 |
const ALLOWED_STATUS = new Set(["OPEN", "IN_PROGRESS", "DONE"] as const);
|
| 9 |
|
|
|
|
| 11 |
const { id } = await params;
|
| 12 |
const anonId = await getAnonId();
|
| 13 |
const nickname = await getNickname();
|
| 14 |
+
const session = await auth();
|
| 15 |
+
const userId = session?.user?.id ?? null;
|
| 16 |
|
| 17 |
const idea = await prisma.idea.findUnique({
|
| 18 |
where: { id },
|
| 19 |
include: {
|
| 20 |
+
createdByUser: { include: { developerProfile: true } },
|
| 21 |
+
workVotes: true,
|
| 22 |
+
userVotes: true,
|
| 23 |
+
votes: true,
|
| 24 |
+
tasks: {
|
| 25 |
+
include: {
|
| 26 |
+
links: true,
|
| 27 |
+
claimedByUser: { include: { developerProfile: true } },
|
| 28 |
+
workVotes: true,
|
| 29 |
+
},
|
| 30 |
+
orderBy: { createdAt: "asc" },
|
| 31 |
+
},
|
| 32 |
+
comments: {
|
| 33 |
+
include: {
|
| 34 |
+
createdByUser: { include: { developerProfile: true } },
|
| 35 |
+
},
|
| 36 |
+
orderBy: { createdAt: "desc" },
|
| 37 |
+
},
|
| 38 |
+
solutions: {
|
| 39 |
+
include: {
|
| 40 |
+
createdByUser: { include: { developerProfile: true } },
|
| 41 |
+
userVotes: true,
|
| 42 |
+
anonVotes: true,
|
| 43 |
+
comments: true,
|
| 44 |
+
task: { select: { id: true, title: true } },
|
| 45 |
+
},
|
| 46 |
+
orderBy: { createdAt: "desc" },
|
| 47 |
+
},
|
| 48 |
},
|
| 49 |
});
|
| 50 |
|
|
|
|
| 52 |
notFound();
|
| 53 |
}
|
| 54 |
|
| 55 |
+
const isVoted = userId
|
| 56 |
+
? idea.userVotes.some((vote) => vote.userId === userId)
|
| 57 |
+
: idea.votes.some((vote) => vote.anonId === anonId);
|
| 58 |
|
| 59 |
const claimedAnonIds = Array.from(
|
| 60 |
new Set(idea.tasks.map((task) => task.claimedByAnonId).filter((value): value is string => Boolean(value)))
|
|
|
|
| 68 |
|
| 69 |
const payload = {
|
| 70 |
...mapIdea(idea),
|
| 71 |
+
submitter_label: idea.isAnonymous
|
| 72 |
+
? "Anonymous"
|
| 73 |
+
: idea.submitterVisibleName || idea.createdByUser?.developerProfile?.displayName || idea.createdByUser?.name || "Member",
|
| 74 |
viewerAnonId: anonId,
|
| 75 |
+
viewerUserId: userId,
|
| 76 |
+
isAuthenticated: Boolean(userId),
|
| 77 |
+
canApproveSolutions: Boolean(userId ? idea.createdByUserId === userId : !idea.createdByUserId && idea.createdByAnonId === anonId),
|
| 78 |
+
idea_working_count: idea.workVotes.length,
|
| 79 |
+
idea_working: userId ? idea.workVotes.some((vote) => vote.userId === userId) : false,
|
| 80 |
+
tasks: idea.tasks.map((task) => {
|
| 81 |
+
const mapped = mapTask(task);
|
| 82 |
+
const claimantDisplayName = task.claimedByUserId
|
| 83 |
+
? task.claimedByUser?.developerProfile?.displayName || task.claimedByUser?.name || "Member"
|
| 84 |
+
: mapped.claimedByAnonId
|
| 85 |
+
? nicknameByAnonId.get(mapped.claimedByAnonId) ?? "anon"
|
| 86 |
+
: null;
|
| 87 |
+
|
| 88 |
return {
|
| 89 |
...mapped,
|
| 90 |
+
claimantNickname: claimantDisplayName,
|
| 91 |
+
claimantDisplayName,
|
| 92 |
+
working_count: task.workVotes.length,
|
| 93 |
+
working: userId ? task.workVotes.some((vote) => vote.userId === userId) : false,
|
| 94 |
status: ALLOWED_STATUS.has(mapped.status as "OPEN" | "IN_PROGRESS" | "DONE")
|
| 95 |
? (mapped.status as "OPEN" | "IN_PROGRESS" | "DONE")
|
| 96 |
: "OPEN",
|
| 97 |
};
|
| 98 |
}),
|
| 99 |
+
comments: idea.comments.map((comment) => ({
|
| 100 |
+
...comment,
|
| 101 |
+
createdAt: comment.createdAt.toISOString(),
|
| 102 |
+
author_label:
|
| 103 |
+
comment.createdByUser?.developerProfile?.displayName || comment.createdByUser?.name || (comment.createdByUserId ? "Member" : "Anon"),
|
| 104 |
+
})),
|
| 105 |
+
solutions: idea.solutions.map((solution) => {
|
| 106 |
+
const userScore = solution.userVotes.reduce((sum, vote) => sum + vote.value, 0);
|
| 107 |
+
const anonScore = solution.anonVotes.reduce((sum, vote) => sum + vote.value, 0);
|
| 108 |
+
const myVote = userId
|
| 109 |
+
? solution.userVotes.find((vote) => vote.userId === userId)?.value ?? 0
|
| 110 |
+
: solution.anonVotes.find((vote) => vote.anonId === anonId)?.value ?? 0;
|
| 111 |
+
|
| 112 |
+
return {
|
| 113 |
+
id: solution.id,
|
| 114 |
+
ideaId: solution.ideaId,
|
| 115 |
+
taskId: solution.taskId,
|
| 116 |
+
taskTitle: solution.task?.title ?? null,
|
| 117 |
+
url: solution.url,
|
| 118 |
+
label: solution.label,
|
| 119 |
+
description: solution.description,
|
| 120 |
+
type: solution.type,
|
| 121 |
+
createdAt: solution.createdAt.toISOString(),
|
| 122 |
+
approvedAt: solution.approvedAt ? solution.approvedAt.toISOString() : null,
|
| 123 |
+
createdByDisplayName:
|
| 124 |
+
solution.createdByUser.developerProfile?.displayName || solution.createdByUser.name || solution.createdByUser.email || "Developer",
|
| 125 |
+
voteScore: userScore + anonScore,
|
| 126 |
+
myVote,
|
| 127 |
+
commentsCount: solution.comments.length,
|
| 128 |
+
};
|
| 129 |
+
}),
|
| 130 |
};
|
| 131 |
|
| 132 |
+
return <IdeaDetailClient initialIdea={payload} isVoted={isVoted} initialNickname={nickname} />;
|
| 133 |
}
|
app/layout.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import type { Metadata } from "next";
|
| 2 |
import Link from "next/link";
|
| 3 |
import { Fraunces, Space_Grotesk } from "next/font/google";
|
|
|
|
| 4 |
import "./globals.css";
|
| 5 |
|
| 6 |
export const metadata: Metadata = {
|
|
@@ -18,7 +19,9 @@ const display = Fraunces({
|
|
| 18 |
variable: "--font-display",
|
| 19 |
});
|
| 20 |
|
| 21 |
-
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
|
|
|
|
|
|
|
| 22 |
return (
|
| 23 |
<html lang="en">
|
| 24 |
<body className={`${sans.variable} ${display.variable}`}>
|
|
@@ -28,13 +31,36 @@ export default function RootLayout({ children }: Readonly<{ children: React.Reac
|
|
| 28 |
<Link href="/" className="brand-mark text-lg font-semibold tracking-tight">
|
| 29 |
Demand Solution Board
|
| 30 |
</Link>
|
| 31 |
-
<div className="flex items-center gap-2">
|
| 32 |
<Link href="/" className="btn">
|
| 33 |
Browse
|
| 34 |
</Link>
|
| 35 |
<Link href="/submit" className="btn btn-primary">
|
| 36 |
Submit Idea
|
| 37 |
</Link>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
</div>
|
| 39 |
</div>
|
| 40 |
</header>
|
|
|
|
| 1 |
import type { Metadata } from "next";
|
| 2 |
import Link from "next/link";
|
| 3 |
import { Fraunces, Space_Grotesk } from "next/font/google";
|
| 4 |
+
import { auth, signOut } from "@/auth";
|
| 5 |
import "./globals.css";
|
| 6 |
|
| 7 |
export const metadata: Metadata = {
|
|
|
|
| 19 |
variable: "--font-display",
|
| 20 |
});
|
| 21 |
|
| 22 |
+
export default async function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
|
| 23 |
+
const session = await auth();
|
| 24 |
+
|
| 25 |
return (
|
| 26 |
<html lang="en">
|
| 27 |
<body className={`${sans.variable} ${display.variable}`}>
|
|
|
|
| 31 |
<Link href="/" className="brand-mark text-lg font-semibold tracking-tight">
|
| 32 |
Demand Solution Board
|
| 33 |
</Link>
|
| 34 |
+
<div className="flex flex-wrap items-center gap-2">
|
| 35 |
<Link href="/" className="btn">
|
| 36 |
Browse
|
| 37 |
</Link>
|
| 38 |
<Link href="/submit" className="btn btn-primary">
|
| 39 |
Submit Idea
|
| 40 |
</Link>
|
| 41 |
+
|
| 42 |
+
{session?.user ? (
|
| 43 |
+
<>
|
| 44 |
+
<Link href="/me/profile" className="btn">
|
| 45 |
+
Profile
|
| 46 |
+
</Link>
|
| 47 |
+
<span className="pill">{session.user.name || session.user.email || "Signed in"}</span>
|
| 48 |
+
<form
|
| 49 |
+
action={async () => {
|
| 50 |
+
"use server";
|
| 51 |
+
await signOut({ redirectTo: "/" });
|
| 52 |
+
}}
|
| 53 |
+
>
|
| 54 |
+
<button type="submit" className="btn">
|
| 55 |
+
Sign out
|
| 56 |
+
</button>
|
| 57 |
+
</form>
|
| 58 |
+
</>
|
| 59 |
+
) : (
|
| 60 |
+
<Link href="/login" className="btn">
|
| 61 |
+
Login
|
| 62 |
+
</Link>
|
| 63 |
+
)}
|
| 64 |
</div>
|
| 65 |
</div>
|
| 66 |
</header>
|
app/login/page.tsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { signIn } from "@/auth";
|
| 2 |
+
|
| 3 |
+
const providerConfig = [
|
| 4 |
+
{ id: "google", label: "Continue with Google", enabled: Boolean(process.env.AUTH_GOOGLE_ID && process.env.AUTH_GOOGLE_SECRET) },
|
| 5 |
+
{ id: "github", label: "Continue with GitHub", enabled: Boolean(process.env.AUTH_GITHUB_ID && process.env.AUTH_GITHUB_SECRET) },
|
| 6 |
+
{ id: "apple", label: "Continue with Apple", enabled: Boolean(process.env.AUTH_APPLE_ID && process.env.AUTH_APPLE_SECRET) },
|
| 7 |
+
{ id: "facebook", label: "Continue with Facebook", enabled: Boolean(process.env.AUTH_FACEBOOK_ID && process.env.AUTH_FACEBOOK_SECRET) },
|
| 8 |
+
];
|
| 9 |
+
|
| 10 |
+
export default function LoginPage() {
|
| 11 |
+
const enabled = providerConfig.filter((provider) => provider.enabled);
|
| 12 |
+
|
| 13 |
+
return (
|
| 14 |
+
<div className="mx-auto max-w-xl space-y-5">
|
| 15 |
+
<section className="hero-panel reveal-up">
|
| 16 |
+
<p className="kicker">OIDC Login</p>
|
| 17 |
+
<h1 className="section-title mt-2 text-3xl">Sign in as idea submitter or developer</h1>
|
| 18 |
+
<p className="subtle mt-3 text-sm">
|
| 19 |
+
Supported providers: Google, GitHub, Apple, and optionally Facebook.
|
| 20 |
+
</p>
|
| 21 |
+
</section>
|
| 22 |
+
|
| 23 |
+
<section className="card space-y-3">
|
| 24 |
+
{enabled.length === 0 ? (
|
| 25 |
+
<p className="text-sm text-red-700">
|
| 26 |
+
No auth providers are configured yet. Add provider env vars to enable login.
|
| 27 |
+
</p>
|
| 28 |
+
) : (
|
| 29 |
+
enabled.map((provider) => (
|
| 30 |
+
<form
|
| 31 |
+
key={provider.id}
|
| 32 |
+
action={async () => {
|
| 33 |
+
"use server";
|
| 34 |
+
await signIn(provider.id, { redirectTo: "/" });
|
| 35 |
+
}}
|
| 36 |
+
>
|
| 37 |
+
<button className="btn w-full" type="submit">
|
| 38 |
+
{provider.label}
|
| 39 |
+
</button>
|
| 40 |
+
</form>
|
| 41 |
+
))
|
| 42 |
+
)}
|
| 43 |
+
</section>
|
| 44 |
+
</div>
|
| 45 |
+
);
|
| 46 |
+
}
|
app/me/profile/page.tsx
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { redirect } from "next/navigation";
|
| 2 |
+
import { auth } from "@/auth";
|
| 3 |
+
import { prisma } from "@/lib/prisma";
|
| 4 |
+
|
| 5 |
+
export default async function ProfilePage() {
|
| 6 |
+
const session = await auth();
|
| 7 |
+
const userId = session?.user?.id;
|
| 8 |
+
|
| 9 |
+
if (!userId) {
|
| 10 |
+
redirect("/login");
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
const profile = await prisma.developerProfile.findUnique({ where: { userId } });
|
| 14 |
+
|
| 15 |
+
async function saveProfile(formData: FormData) {
|
| 16 |
+
"use server";
|
| 17 |
+
|
| 18 |
+
const current = await auth();
|
| 19 |
+
const currentUserId = current?.user?.id;
|
| 20 |
+
if (!currentUserId) {
|
| 21 |
+
redirect("/login");
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
const displayName = String(formData.get("displayName") || "").trim();
|
| 25 |
+
if (displayName.length < 2 || displayName.length > 50) {
|
| 26 |
+
redirect("/me/profile?error=display_name");
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
const headline = String(formData.get("headline") || "").trim();
|
| 30 |
+
const bio = String(formData.get("bio") || "").trim();
|
| 31 |
+
const githubUrl = String(formData.get("githubUrl") || "").trim();
|
| 32 |
+
const websiteUrl = String(formData.get("websiteUrl") || "").trim();
|
| 33 |
+
|
| 34 |
+
await prisma.developerProfile.upsert({
|
| 35 |
+
where: { userId: currentUserId },
|
| 36 |
+
create: {
|
| 37 |
+
userId: currentUserId,
|
| 38 |
+
displayName,
|
| 39 |
+
headline: headline || null,
|
| 40 |
+
bio: bio || null,
|
| 41 |
+
githubUrl: githubUrl || null,
|
| 42 |
+
websiteUrl: websiteUrl || null,
|
| 43 |
+
},
|
| 44 |
+
update: {
|
| 45 |
+
displayName,
|
| 46 |
+
headline: headline || null,
|
| 47 |
+
bio: bio || null,
|
| 48 |
+
githubUrl: githubUrl || null,
|
| 49 |
+
websiteUrl: websiteUrl || null,
|
| 50 |
+
},
|
| 51 |
+
});
|
| 52 |
+
|
| 53 |
+
redirect("/me/profile?saved=1");
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
return (
|
| 57 |
+
<div className="mx-auto max-w-2xl space-y-5">
|
| 58 |
+
<section className="hero-panel reveal-up">
|
| 59 |
+
<p className="kicker">Developer Profile</p>
|
| 60 |
+
<h1 className="section-title mt-2 text-3xl">Create your contributor profile</h1>
|
| 61 |
+
<p className="subtle mt-2 text-sm">Your profile name is used for task claims, work votes, and submitted solutions.</p>
|
| 62 |
+
</section>
|
| 63 |
+
|
| 64 |
+
<form action={saveProfile} className="card space-y-4">
|
| 65 |
+
<div>
|
| 66 |
+
<label className="mb-1 block text-sm font-medium">Display name</label>
|
| 67 |
+
<input name="displayName" required minLength={2} maxLength={50} className="input" defaultValue={profile?.displayName || session?.user?.name || ""} />
|
| 68 |
+
</div>
|
| 69 |
+
|
| 70 |
+
<div>
|
| 71 |
+
<label className="mb-1 block text-sm font-medium">Headline</label>
|
| 72 |
+
<input name="headline" maxLength={120} className="input" defaultValue={profile?.headline || ""} />
|
| 73 |
+
</div>
|
| 74 |
+
|
| 75 |
+
<div>
|
| 76 |
+
<label className="mb-1 block text-sm font-medium">Bio</label>
|
| 77 |
+
<textarea name="bio" maxLength={500} className="input min-h-28" defaultValue={profile?.bio || ""} />
|
| 78 |
+
</div>
|
| 79 |
+
|
| 80 |
+
<div>
|
| 81 |
+
<label className="mb-1 block text-sm font-medium">GitHub URL</label>
|
| 82 |
+
<input name="githubUrl" type="url" className="input" defaultValue={profile?.githubUrl || ""} />
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<div>
|
| 86 |
+
<label className="mb-1 block text-sm font-medium">Website URL</label>
|
| 87 |
+
<input name="websiteUrl" type="url" className="input" defaultValue={profile?.websiteUrl || ""} />
|
| 88 |
+
</div>
|
| 89 |
+
|
| 90 |
+
<button type="submit" className="btn btn-primary">Save Profile</button>
|
| 91 |
+
</form>
|
| 92 |
+
</div>
|
| 93 |
+
);
|
| 94 |
+
}
|
app/submit/page.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
|
|
| 1 |
import { SubmitForm } from "@/components/SubmitForm";
|
| 2 |
|
| 3 |
-
export default function SubmitPage() {
|
|
|
|
|
|
|
| 4 |
return (
|
| 5 |
<div className="space-y-5 md:space-y-6">
|
| 6 |
<section className="hero-panel reveal-up">
|
|
@@ -11,7 +14,7 @@ export default function SubmitPage() {
|
|
| 11 |
tasks, and open questions.
|
| 12 |
</p>
|
| 13 |
</section>
|
| 14 |
-
<SubmitForm />
|
| 15 |
</div>
|
| 16 |
);
|
| 17 |
}
|
|
|
|
| 1 |
+
import { auth } from "@/auth";
|
| 2 |
import { SubmitForm } from "@/components/SubmitForm";
|
| 3 |
|
| 4 |
+
export default async function SubmitPage() {
|
| 5 |
+
const session = await auth();
|
| 6 |
+
|
| 7 |
return (
|
| 8 |
<div className="space-y-5 md:space-y-6">
|
| 9 |
<section className="hero-panel reveal-up">
|
|
|
|
| 14 |
tasks, and open questions.
|
| 15 |
</p>
|
| 16 |
</section>
|
| 17 |
+
<SubmitForm canShowIdentity={Boolean(session?.user?.id)} />
|
| 18 |
</div>
|
| 19 |
);
|
| 20 |
}
|
auth.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import NextAuth from "next-auth";
|
| 2 |
+
import Google from "next-auth/providers/google";
|
| 3 |
+
import GitHub from "next-auth/providers/github";
|
| 4 |
+
import Apple from "next-auth/providers/apple";
|
| 5 |
+
import Facebook from "next-auth/providers/facebook";
|
| 6 |
+
import { PrismaAdapter } from "@auth/prisma-adapter";
|
| 7 |
+
import { prisma } from "@/lib/prisma";
|
| 8 |
+
|
| 9 |
+
const providers = [];
|
| 10 |
+
|
| 11 |
+
if (process.env.AUTH_GOOGLE_ID && process.env.AUTH_GOOGLE_SECRET) {
|
| 12 |
+
providers.push(
|
| 13 |
+
Google({
|
| 14 |
+
clientId: process.env.AUTH_GOOGLE_ID,
|
| 15 |
+
clientSecret: process.env.AUTH_GOOGLE_SECRET,
|
| 16 |
+
})
|
| 17 |
+
);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
if (process.env.AUTH_GITHUB_ID && process.env.AUTH_GITHUB_SECRET) {
|
| 21 |
+
providers.push(
|
| 22 |
+
GitHub({
|
| 23 |
+
clientId: process.env.AUTH_GITHUB_ID,
|
| 24 |
+
clientSecret: process.env.AUTH_GITHUB_SECRET,
|
| 25 |
+
})
|
| 26 |
+
);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
if (process.env.AUTH_APPLE_ID && process.env.AUTH_APPLE_SECRET) {
|
| 30 |
+
providers.push(
|
| 31 |
+
Apple({
|
| 32 |
+
clientId: process.env.AUTH_APPLE_ID,
|
| 33 |
+
clientSecret: process.env.AUTH_APPLE_SECRET,
|
| 34 |
+
})
|
| 35 |
+
);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
if (process.env.AUTH_FACEBOOK_ID && process.env.AUTH_FACEBOOK_SECRET) {
|
| 39 |
+
providers.push(
|
| 40 |
+
Facebook({
|
| 41 |
+
clientId: process.env.AUTH_FACEBOOK_ID,
|
| 42 |
+
clientSecret: process.env.AUTH_FACEBOOK_SECRET,
|
| 43 |
+
})
|
| 44 |
+
);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
export const { handlers, auth, signIn, signOut } = NextAuth({
|
| 48 |
+
adapter: PrismaAdapter(prisma),
|
| 49 |
+
providers,
|
| 50 |
+
session: { strategy: "database" },
|
| 51 |
+
trustHost: true,
|
| 52 |
+
pages: {
|
| 53 |
+
signIn: "/login",
|
| 54 |
+
},
|
| 55 |
+
callbacks: {
|
| 56 |
+
async session({ session, user }) {
|
| 57 |
+
if (session.user) {
|
| 58 |
+
session.user.id = user.id;
|
| 59 |
+
}
|
| 60 |
+
return session;
|
| 61 |
+
},
|
| 62 |
+
},
|
| 63 |
+
});
|
components/HomeList.tsx
CHANGED
|
@@ -11,6 +11,7 @@ type IdeaCard = {
|
|
| 11 |
upvotesCount: number;
|
| 12 |
comment_count: number;
|
| 13 |
createdAt: string;
|
|
|
|
| 14 |
};
|
| 15 |
|
| 16 |
export function HomeList() {
|
|
@@ -84,6 +85,7 @@ export function HomeList() {
|
|
| 84 |
</div>
|
| 85 |
|
| 86 |
<p className="subtle mt-2 text-sm">{idea.problemStatement}</p>
|
|
|
|
| 87 |
|
| 88 |
{idea.tags.length ? (
|
| 89 |
<div className="mt-4 flex flex-wrap gap-1.5">
|
|
|
|
| 11 |
upvotesCount: number;
|
| 12 |
comment_count: number;
|
| 13 |
createdAt: string;
|
| 14 |
+
submitter_label?: string;
|
| 15 |
};
|
| 16 |
|
| 17 |
export function HomeList() {
|
|
|
|
| 85 |
</div>
|
| 86 |
|
| 87 |
<p className="subtle mt-2 text-sm">{idea.problemStatement}</p>
|
| 88 |
+
<p className="subtle mt-2 text-xs">Submitter: {idea.submitter_label || "Anonymous"}</p>
|
| 89 |
|
| 90 |
{idea.tags.length ? (
|
| 91 |
<div className="mt-4 flex flex-wrap gap-1.5">
|
components/IdeaDetailClient.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
"use client";
|
| 2 |
|
|
|
|
| 3 |
import { useMemo, useState } from "react";
|
| 4 |
import { fetchWithAnon } from "@/lib/client-anon";
|
| 5 |
|
|
@@ -7,7 +8,8 @@ type LinkItem = {
|
|
| 7 |
id: string;
|
| 8 |
url: string;
|
| 9 |
label: string | null;
|
| 10 |
-
createdByAnonId: string;
|
|
|
|
| 11 |
};
|
| 12 |
|
| 13 |
type TaskItem = {
|
|
@@ -18,14 +20,36 @@ type TaskItem = {
|
|
| 18 |
effort: string | null;
|
| 19 |
status: "OPEN" | "IN_PROGRESS" | "DONE";
|
| 20 |
claimedByAnonId: string | null;
|
|
|
|
| 21 |
claimantNickname: string | null;
|
|
|
|
| 22 |
links: LinkItem[];
|
|
|
|
|
|
|
| 23 |
};
|
| 24 |
|
| 25 |
type CommentItem = {
|
| 26 |
id: string;
|
| 27 |
body: string;
|
| 28 |
createdAt: string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
};
|
| 30 |
|
| 31 |
type IdeaPayload = {
|
|
@@ -37,19 +61,35 @@ type IdeaPayload = {
|
|
| 37 |
open_questions: string[];
|
| 38 |
upvotesCount: number;
|
| 39 |
commentsCount: number;
|
|
|
|
| 40 |
viewerAnonId: string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
tasks: TaskItem[];
|
| 42 |
comments: CommentItem[];
|
|
|
|
| 43 |
};
|
| 44 |
|
| 45 |
type TaskUpdate = {
|
| 46 |
id: string;
|
| 47 |
status: "OPEN" | "IN_PROGRESS" | "DONE";
|
| 48 |
claimedByAnonId: string | null;
|
|
|
|
| 49 |
claimantNickname?: string | null;
|
|
|
|
| 50 |
links?: LinkItem[];
|
| 51 |
};
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
function formatStatus(status: TaskItem["status"]): string {
|
| 54 |
if (status === "IN_PROGRESS") return "In Progress";
|
| 55 |
if (status === "DONE") return "Done";
|
|
@@ -71,25 +111,36 @@ export function IdeaDetailClient({
|
|
| 71 |
const [nickInput, setNickInput] = useState(initialNickname);
|
| 72 |
const [commentInput, setCommentInput] = useState("");
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
function applyTaskUpdate(taskId: string, taskUpdate: TaskUpdate) {
|
| 75 |
setIdea((prev) => ({
|
| 76 |
...prev,
|
| 77 |
tasks: prev.tasks.map((task) => {
|
| 78 |
if (task.id !== taskId) return task;
|
| 79 |
|
| 80 |
-
const
|
| 81 |
-
const
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
: task.claimantNickname;
|
| 87 |
|
| 88 |
return {
|
| 89 |
...task,
|
| 90 |
status: taskUpdate.status,
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
| 93 |
links: taskUpdate.links ?? task.links,
|
| 94 |
};
|
| 95 |
}),
|
|
@@ -109,6 +160,43 @@ export function IdeaDetailClient({
|
|
| 109 |
}
|
| 110 |
}
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
async function saveNickname() {
|
| 113 |
const response = await fetchWithAnon("/api/me/nickname", {
|
| 114 |
method: "POST",
|
|
@@ -121,7 +209,7 @@ export function IdeaDetailClient({
|
|
| 121 |
setIdea((prev) => ({
|
| 122 |
...prev,
|
| 123 |
tasks: prev.tasks.map((task) =>
|
| 124 |
-
task.claimedByAnonId === prev.viewerAnonId ? { ...task, claimantNickname: nickInput || "anon" } : task
|
| 125 |
),
|
| 126 |
}));
|
| 127 |
}
|
|
@@ -213,6 +301,95 @@ export function IdeaDetailClient({
|
|
| 213 |
}));
|
| 214 |
}
|
| 215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
const grouped = useMemo(() => {
|
| 217 |
return {
|
| 218 |
open: idea.tasks.filter((task) => task.status === "OPEN"),
|
|
@@ -234,15 +411,25 @@ export function IdeaDetailClient({
|
|
| 234 |
{tag}
|
| 235 |
</span>
|
| 236 |
))}
|
|
|
|
| 237 |
</div>
|
| 238 |
|
| 239 |
<div className="mt-5 flex flex-wrap items-center gap-2 md:gap-3">
|
| 240 |
<button className={`btn ${voted ? "btn-primary" : ""}`} onClick={toggleVote}>
|
| 241 |
{voted ? "Upvoted" : "Upvote"} ({idea.upvotesCount})
|
| 242 |
</button>
|
|
|
|
|
|
|
|
|
|
| 243 |
<span className="pill">{idea.commentsCount} comments</span>
|
| 244 |
<span className="pill">{idea.tasks.length} tasks</span>
|
| 245 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
</section>
|
| 247 |
|
| 248 |
<section className="grid gap-4 md:grid-cols-2 reveal-up" style={{ animationDelay: "80ms" }}>
|
|
@@ -266,8 +453,8 @@ export function IdeaDetailClient({
|
|
| 266 |
<section className="card reveal-up space-y-4" style={{ animationDelay: "140ms" }}>
|
| 267 |
<div className="flex flex-wrap items-end justify-between gap-3">
|
| 268 |
<div>
|
| 269 |
-
<h2 className="section-title">
|
| 270 |
-
<p className="subtle mt-1 text-sm">
|
| 271 |
</div>
|
| 272 |
<span className="pill">Current: {nickname || "anon"}</span>
|
| 273 |
</div>
|
|
@@ -287,7 +474,7 @@ export function IdeaDetailClient({
|
|
| 287 |
<div className="flex items-end justify-between gap-2">
|
| 288 |
<div>
|
| 289 |
<h2 className="section-title">Tasks</h2>
|
| 290 |
-
<p className="subtle mt-1 text-sm">Claim tasks, attach implementation links, and
|
| 291 |
</div>
|
| 292 |
</div>
|
| 293 |
|
|
@@ -295,34 +482,153 @@ export function IdeaDetailClient({
|
|
| 295 |
title="Open"
|
| 296 |
items={grouped.open}
|
| 297 |
viewerAnonId={idea.viewerAnonId}
|
|
|
|
|
|
|
| 298 |
onClaim={claim}
|
| 299 |
onUnclaim={unclaim}
|
| 300 |
onSetStatus={setStatus}
|
| 301 |
onAddLink={addLink}
|
| 302 |
onRemoveLink={removeLink}
|
|
|
|
| 303 |
/>
|
| 304 |
<TaskColumn
|
| 305 |
title="In Progress"
|
| 306 |
items={grouped.inProgress}
|
| 307 |
viewerAnonId={idea.viewerAnonId}
|
|
|
|
|
|
|
| 308 |
onClaim={claim}
|
| 309 |
onUnclaim={unclaim}
|
| 310 |
onSetStatus={setStatus}
|
| 311 |
onAddLink={addLink}
|
| 312 |
onRemoveLink={removeLink}
|
|
|
|
| 313 |
/>
|
| 314 |
<TaskColumn
|
| 315 |
title="Done"
|
| 316 |
items={grouped.done}
|
| 317 |
viewerAnonId={idea.viewerAnonId}
|
|
|
|
|
|
|
| 318 |
onClaim={claim}
|
| 319 |
onUnclaim={unclaim}
|
| 320 |
onSetStatus={setStatus}
|
| 321 |
onAddLink={addLink}
|
| 322 |
onRemoveLink={removeLink}
|
|
|
|
| 323 |
/>
|
| 324 |
</section>
|
| 325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
<section className="card reveal-up space-y-4" style={{ animationDelay: "240ms" }}>
|
| 327 |
<div className="flex items-end justify-between gap-2">
|
| 328 |
<h2 className="section-title">Comments</h2>
|
|
@@ -346,7 +652,7 @@ export function IdeaDetailClient({
|
|
| 346 |
idea.comments.map((comment) => (
|
| 347 |
<div key={comment.id} className="rounded-xl border border-white/70 bg-white/60 p-3 text-sm">
|
| 348 |
<p>{comment.body}</p>
|
| 349 |
-
<p className="subtle mt-1 text-xs">{new Date(comment.createdAt).toLocaleString()}</p>
|
| 350 |
</div>
|
| 351 |
))
|
| 352 |
) : (
|
|
@@ -368,44 +674,54 @@ function TaskColumn({
|
|
| 368 |
title,
|
| 369 |
items,
|
| 370 |
viewerAnonId,
|
|
|
|
|
|
|
| 371 |
onClaim,
|
| 372 |
onUnclaim,
|
| 373 |
onSetStatus,
|
| 374 |
onAddLink,
|
| 375 |
onRemoveLink,
|
|
|
|
| 376 |
}: {
|
| 377 |
title: string;
|
| 378 |
items: TaskItem[];
|
| 379 |
viewerAnonId: string;
|
|
|
|
|
|
|
| 380 |
onClaim: (taskId: string) => Promise<void>;
|
| 381 |
onUnclaim: (taskId: string) => Promise<void>;
|
| 382 |
onSetStatus: (taskId: string, status: TaskItem["status"]) => Promise<void>;
|
| 383 |
onAddLink: (taskId: string) => Promise<void>;
|
| 384 |
onRemoveLink: (taskId: string, linkId: string) => Promise<void>;
|
|
|
|
| 385 |
}) {
|
| 386 |
return (
|
| 387 |
<div className="space-y-2">
|
| 388 |
<h3 className="text-sm font-semibold uppercase tracking-[0.16em] text-zinc-600">{title}</h3>
|
| 389 |
{items.length === 0 ? <p className="subtle text-sm">No tasks.</p> : null}
|
| 390 |
{items.map((task) => {
|
| 391 |
-
const isClaimedByMe =
|
| 392 |
-
|
|
|
|
|
|
|
|
|
|
| 393 |
|
| 394 |
return (
|
| 395 |
-
<details key={task.id} className="rounded-xl border border-white/70 bg-white/
|
| 396 |
<summary className="cursor-pointer text-sm font-semibold">
|
| 397 |
<span>{task.title}</span>
|
| 398 |
<span className={`ml-2 inline-flex rounded-full border px-2 py-0.5 text-xs ${statusBadgeClass(task.status)}`}>
|
| 399 |
{formatStatus(task.status)}
|
| 400 |
</span>
|
| 401 |
{task.effort ? <span className="ml-2 text-xs text-zinc-500">Effort {task.effort}</span> : null}
|
|
|
|
| 402 |
</summary>
|
| 403 |
|
| 404 |
<div className="mt-3 space-y-2 text-sm">
|
| 405 |
{task.description ? <p>{task.description}</p> : null}
|
| 406 |
-
{task.claimedByAnonId ? (
|
| 407 |
<p className="text-xs text-zinc-600">
|
| 408 |
-
Claimed by <span className="font-medium">{task.
|
| 409 |
</p>
|
| 410 |
) : (
|
| 411 |
<p className="text-xs text-zinc-600">Unclaimed</p>
|
|
@@ -420,7 +736,7 @@ function TaskColumn({
|
|
| 420 |
) : null}
|
| 421 |
|
| 422 |
<div className="flex flex-wrap gap-2">
|
| 423 |
-
{!task.claimedByAnonId ? (
|
| 424 |
<button className="btn" onClick={() => onClaim(task.id)}>
|
| 425 |
Claim
|
| 426 |
</button>
|
|
@@ -446,12 +762,19 @@ function TaskColumn({
|
|
| 446 |
</>
|
| 447 |
) : null}
|
| 448 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
{isClaimedBySomeoneElse ? <span className="subtle text-xs">Only claimant can update this task.</span> : null}
|
| 450 |
</div>
|
| 451 |
|
| 452 |
<div className="space-y-1.5">
|
| 453 |
{task.links.map((link) => {
|
| 454 |
-
const
|
|
|
|
|
|
|
|
|
|
| 455 |
return (
|
| 456 |
<div key={link.id} className="flex items-center justify-between gap-2 rounded-lg border border-zinc-200 bg-white/90 px-2 py-1">
|
| 457 |
<a href={link.url} target="_blank" rel="noreferrer" className="truncate text-cyan-700 underline">
|
|
|
|
| 1 |
"use client";
|
| 2 |
|
| 3 |
+
import Link from "next/link";
|
| 4 |
import { useMemo, useState } from "react";
|
| 5 |
import { fetchWithAnon } from "@/lib/client-anon";
|
| 6 |
|
|
|
|
| 8 |
id: string;
|
| 9 |
url: string;
|
| 10 |
label: string | null;
|
| 11 |
+
createdByAnonId: string | null;
|
| 12 |
+
createdByUserId: string | null;
|
| 13 |
};
|
| 14 |
|
| 15 |
type TaskItem = {
|
|
|
|
| 20 |
effort: string | null;
|
| 21 |
status: "OPEN" | "IN_PROGRESS" | "DONE";
|
| 22 |
claimedByAnonId: string | null;
|
| 23 |
+
claimedByUserId: string | null;
|
| 24 |
claimantNickname: string | null;
|
| 25 |
+
claimantDisplayName: string | null;
|
| 26 |
links: LinkItem[];
|
| 27 |
+
working_count: number;
|
| 28 |
+
working: boolean;
|
| 29 |
};
|
| 30 |
|
| 31 |
type CommentItem = {
|
| 32 |
id: string;
|
| 33 |
body: string;
|
| 34 |
createdAt: string;
|
| 35 |
+
author_label?: string;
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
type SolutionItem = {
|
| 39 |
+
id: string;
|
| 40 |
+
ideaId: string;
|
| 41 |
+
taskId: string | null;
|
| 42 |
+
taskTitle: string | null;
|
| 43 |
+
url: string;
|
| 44 |
+
label: string | null;
|
| 45 |
+
description: string | null;
|
| 46 |
+
type: "APP_URL" | "GITHUB_REPO" | "OTHER";
|
| 47 |
+
createdAt: string;
|
| 48 |
+
approvedAt: string | null;
|
| 49 |
+
createdByDisplayName: string;
|
| 50 |
+
voteScore: number;
|
| 51 |
+
myVote: number;
|
| 52 |
+
commentsCount: number;
|
| 53 |
};
|
| 54 |
|
| 55 |
type IdeaPayload = {
|
|
|
|
| 61 |
open_questions: string[];
|
| 62 |
upvotesCount: number;
|
| 63 |
commentsCount: number;
|
| 64 |
+
submitter_label: string;
|
| 65 |
viewerAnonId: string;
|
| 66 |
+
viewerUserId: string | null;
|
| 67 |
+
isAuthenticated: boolean;
|
| 68 |
+
canApproveSolutions: boolean;
|
| 69 |
+
idea_working_count: number;
|
| 70 |
+
idea_working: boolean;
|
| 71 |
tasks: TaskItem[];
|
| 72 |
comments: CommentItem[];
|
| 73 |
+
solutions: SolutionItem[];
|
| 74 |
};
|
| 75 |
|
| 76 |
type TaskUpdate = {
|
| 77 |
id: string;
|
| 78 |
status: "OPEN" | "IN_PROGRESS" | "DONE";
|
| 79 |
claimedByAnonId: string | null;
|
| 80 |
+
claimedByUserId: string | null;
|
| 81 |
claimantNickname?: string | null;
|
| 82 |
+
claimantDisplayName?: string | null;
|
| 83 |
links?: LinkItem[];
|
| 84 |
};
|
| 85 |
|
| 86 |
+
type SolutionCommentItem = {
|
| 87 |
+
id: string;
|
| 88 |
+
body: string;
|
| 89 |
+
createdAt: string;
|
| 90 |
+
author_label?: string;
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
function formatStatus(status: TaskItem["status"]): string {
|
| 94 |
if (status === "IN_PROGRESS") return "In Progress";
|
| 95 |
if (status === "DONE") return "Done";
|
|
|
|
| 111 |
const [nickInput, setNickInput] = useState(initialNickname);
|
| 112 |
const [commentInput, setCommentInput] = useState("");
|
| 113 |
|
| 114 |
+
const [solutions, setSolutions] = useState<SolutionItem[]>(initialIdea.solutions || []);
|
| 115 |
+
const [solutionUrl, setSolutionUrl] = useState("");
|
| 116 |
+
const [solutionLabel, setSolutionLabel] = useState("");
|
| 117 |
+
const [solutionDescription, setSolutionDescription] = useState("");
|
| 118 |
+
const [solutionType, setSolutionType] = useState<"APP_URL" | "GITHUB_REPO" | "OTHER">("APP_URL");
|
| 119 |
+
const [solutionTaskId, setSolutionTaskId] = useState<string>("");
|
| 120 |
+
|
| 121 |
+
const [solutionComments, setSolutionComments] = useState<Record<string, SolutionCommentItem[]>>({});
|
| 122 |
+
const [solutionCommentInput, setSolutionCommentInput] = useState<Record<string, string>>({});
|
| 123 |
+
|
| 124 |
function applyTaskUpdate(taskId: string, taskUpdate: TaskUpdate) {
|
| 125 |
setIdea((prev) => ({
|
| 126 |
...prev,
|
| 127 |
tasks: prev.tasks.map((task) => {
|
| 128 |
if (task.id !== taskId) return task;
|
| 129 |
|
| 130 |
+
const nextClaimedByUser = taskUpdate.claimedByUserId;
|
| 131 |
+
const nextClaimedByAnon = taskUpdate.claimedByAnonId;
|
| 132 |
+
const nextClaimantDisplayName =
|
| 133 |
+
taskUpdate.claimantDisplayName ??
|
| 134 |
+
taskUpdate.claimantNickname ??
|
| 135 |
+
(nextClaimedByAnon === prev.viewerAnonId ? nickname || "anon" : task.claimantDisplayName);
|
|
|
|
| 136 |
|
| 137 |
return {
|
| 138 |
...task,
|
| 139 |
status: taskUpdate.status,
|
| 140 |
+
claimedByUserId: nextClaimedByUser,
|
| 141 |
+
claimedByAnonId: nextClaimedByAnon,
|
| 142 |
+
claimantNickname: nextClaimantDisplayName,
|
| 143 |
+
claimantDisplayName: nextClaimantDisplayName,
|
| 144 |
links: taskUpdate.links ?? task.links,
|
| 145 |
};
|
| 146 |
}),
|
|
|
|
| 160 |
}
|
| 161 |
}
|
| 162 |
|
| 163 |
+
async function toggleIdeaWorking() {
|
| 164 |
+
if (!idea.isAuthenticated) return;
|
| 165 |
+
|
| 166 |
+
const next = !idea.idea_working;
|
| 167 |
+
const method = next ? "POST" : "DELETE";
|
| 168 |
+
const response = await fetchWithAnon(`/api/ideas/${idea.id}/work-vote`, { method });
|
| 169 |
+
if (!response.ok) return;
|
| 170 |
+
|
| 171 |
+
const data = await response.json();
|
| 172 |
+
setIdea((prev) => ({
|
| 173 |
+
...prev,
|
| 174 |
+
idea_working: data.working,
|
| 175 |
+
idea_working_count: data.working_count,
|
| 176 |
+
}));
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
async function toggleTaskWorking(taskId: string, working: boolean) {
|
| 180 |
+
if (!idea.isAuthenticated) return;
|
| 181 |
+
|
| 182 |
+
const response = await fetchWithAnon(`/api/tasks/${taskId}/work-vote`, { method: working ? "DELETE" : "POST" });
|
| 183 |
+
if (!response.ok) return;
|
| 184 |
+
|
| 185 |
+
const data = await response.json();
|
| 186 |
+
setIdea((prev) => ({
|
| 187 |
+
...prev,
|
| 188 |
+
tasks: prev.tasks.map((task) =>
|
| 189 |
+
task.id === taskId
|
| 190 |
+
? {
|
| 191 |
+
...task,
|
| 192 |
+
working: data.working,
|
| 193 |
+
working_count: data.working_count,
|
| 194 |
+
}
|
| 195 |
+
: task
|
| 196 |
+
),
|
| 197 |
+
}));
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
async function saveNickname() {
|
| 201 |
const response = await fetchWithAnon("/api/me/nickname", {
|
| 202 |
method: "POST",
|
|
|
|
| 209 |
setIdea((prev) => ({
|
| 210 |
...prev,
|
| 211 |
tasks: prev.tasks.map((task) =>
|
| 212 |
+
task.claimedByAnonId === prev.viewerAnonId ? { ...task, claimantNickname: nickInput || "anon", claimantDisplayName: nickInput || "anon" } : task
|
| 213 |
),
|
| 214 |
}));
|
| 215 |
}
|
|
|
|
| 301 |
}));
|
| 302 |
}
|
| 303 |
|
| 304 |
+
async function submitSolution() {
|
| 305 |
+
if (!idea.isAuthenticated) return;
|
| 306 |
+
if (!solutionUrl.trim()) return;
|
| 307 |
+
|
| 308 |
+
const response = await fetchWithAnon(`/api/ideas/${idea.id}/solutions`, {
|
| 309 |
+
method: "POST",
|
| 310 |
+
headers: { "Content-Type": "application/json" },
|
| 311 |
+
body: JSON.stringify({
|
| 312 |
+
taskId: solutionTaskId || undefined,
|
| 313 |
+
url: solutionUrl.trim(),
|
| 314 |
+
label: solutionLabel.trim() || undefined,
|
| 315 |
+
description: solutionDescription.trim() || undefined,
|
| 316 |
+
type: solutionType,
|
| 317 |
+
}),
|
| 318 |
+
});
|
| 319 |
+
|
| 320 |
+
if (!response.ok) return;
|
| 321 |
+
const data = await response.json();
|
| 322 |
+
setSolutions(data.items || []);
|
| 323 |
+
setSolutionUrl("");
|
| 324 |
+
setSolutionLabel("");
|
| 325 |
+
setSolutionDescription("");
|
| 326 |
+
setSolutionTaskId("");
|
| 327 |
+
setSolutionType("APP_URL");
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
async function setSolutionVote(solutionId: string, value: number) {
|
| 331 |
+
const current = solutions.find((solution) => solution.id === solutionId)?.myVote || 0;
|
| 332 |
+
const response =
|
| 333 |
+
current === value
|
| 334 |
+
? await fetchWithAnon(`/api/solutions/${solutionId}/vote`, { method: "DELETE" })
|
| 335 |
+
: await fetchWithAnon(`/api/solutions/${solutionId}/vote`, {
|
| 336 |
+
method: "POST",
|
| 337 |
+
headers: { "Content-Type": "application/json" },
|
| 338 |
+
body: JSON.stringify({ value }),
|
| 339 |
+
});
|
| 340 |
+
|
| 341 |
+
if (!response.ok) return;
|
| 342 |
+
const data = await response.json();
|
| 343 |
+
|
| 344 |
+
setSolutions((prev) =>
|
| 345 |
+
prev.map((solution) =>
|
| 346 |
+
solution.id === solutionId
|
| 347 |
+
? {
|
| 348 |
+
...solution,
|
| 349 |
+
voteScore: data.score,
|
| 350 |
+
myVote: data.myVote,
|
| 351 |
+
}
|
| 352 |
+
: solution
|
| 353 |
+
)
|
| 354 |
+
);
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
async function approveSolution(solutionId: string) {
|
| 358 |
+
const response = await fetchWithAnon(`/api/solutions/${solutionId}/approve`, { method: "POST" });
|
| 359 |
+
if (!response.ok) return;
|
| 360 |
+
|
| 361 |
+
const data = await response.json();
|
| 362 |
+
const approvedAt = data.solution?.approvedAt || new Date().toISOString();
|
| 363 |
+
setSolutions((prev) => prev.map((solution) => (solution.id === solutionId ? { ...solution, approvedAt } : solution)));
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
async function loadSolutionComments(solutionId: string) {
|
| 367 |
+
const response = await fetchWithAnon(`/api/solutions/${solutionId}/comments`);
|
| 368 |
+
if (!response.ok) return;
|
| 369 |
+
|
| 370 |
+
const data = await response.json();
|
| 371 |
+
setSolutionComments((prev) => ({ ...prev, [solutionId]: data.items || [] }));
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
async function addSolutionComment(solutionId: string) {
|
| 375 |
+
const body = (solutionCommentInput[solutionId] || "").trim();
|
| 376 |
+
if (!body) return;
|
| 377 |
+
|
| 378 |
+
const response = await fetchWithAnon(`/api/solutions/${solutionId}/comments`, {
|
| 379 |
+
method: "POST",
|
| 380 |
+
headers: { "Content-Type": "application/json" },
|
| 381 |
+
body: JSON.stringify({ body }),
|
| 382 |
+
});
|
| 383 |
+
if (!response.ok) return;
|
| 384 |
+
|
| 385 |
+
const data = await response.json();
|
| 386 |
+
setSolutionComments((prev) => ({ ...prev, [solutionId]: data.items || [] }));
|
| 387 |
+
setSolutionCommentInput((prev) => ({ ...prev, [solutionId]: "" }));
|
| 388 |
+
setSolutions((prev) =>
|
| 389 |
+
prev.map((solution) => (solution.id === solutionId ? { ...solution, commentsCount: (data.items || []).length } : solution))
|
| 390 |
+
);
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
const grouped = useMemo(() => {
|
| 394 |
return {
|
| 395 |
open: idea.tasks.filter((task) => task.status === "OPEN"),
|
|
|
|
| 411 |
{tag}
|
| 412 |
</span>
|
| 413 |
))}
|
| 414 |
+
<span className="pill">Submitter: {idea.submitter_label}</span>
|
| 415 |
</div>
|
| 416 |
|
| 417 |
<div className="mt-5 flex flex-wrap items-center gap-2 md:gap-3">
|
| 418 |
<button className={`btn ${voted ? "btn-primary" : ""}`} onClick={toggleVote}>
|
| 419 |
{voted ? "Upvoted" : "Upvote"} ({idea.upvotesCount})
|
| 420 |
</button>
|
| 421 |
+
<button className={`btn ${idea.idea_working ? "btn-primary" : ""}`} onClick={toggleIdeaWorking} disabled={!idea.isAuthenticated}>
|
| 422 |
+
Working on this ({idea.idea_working_count})
|
| 423 |
+
</button>
|
| 424 |
<span className="pill">{idea.commentsCount} comments</span>
|
| 425 |
<span className="pill">{idea.tasks.length} tasks</span>
|
| 426 |
</div>
|
| 427 |
+
|
| 428 |
+
{!idea.isAuthenticated ? (
|
| 429 |
+
<p className="subtle mt-2 text-xs">
|
| 430 |
+
<Link href="/login" className="underline">Sign in</Link> to submit solutions and add developer work votes.
|
| 431 |
+
</p>
|
| 432 |
+
) : null}
|
| 433 |
</section>
|
| 434 |
|
| 435 |
<section className="grid gap-4 md:grid-cols-2 reveal-up" style={{ animationDelay: "80ms" }}>
|
|
|
|
| 453 |
<section className="card reveal-up space-y-4" style={{ animationDelay: "140ms" }}>
|
| 454 |
<div className="flex flex-wrap items-end justify-between gap-3">
|
| 455 |
<div>
|
| 456 |
+
<h2 className="section-title">Anonymous Nickname</h2>
|
| 457 |
+
<p className="subtle mt-1 text-sm">Used for anonymous comments and legacy task claims.</p>
|
| 458 |
</div>
|
| 459 |
<span className="pill">Current: {nickname || "anon"}</span>
|
| 460 |
</div>
|
|
|
|
| 474 |
<div className="flex items-end justify-between gap-2">
|
| 475 |
<div>
|
| 476 |
<h2 className="section-title">Tasks</h2>
|
| 477 |
+
<p className="subtle mt-1 text-sm">Claim tasks, attach implementation links, and vote to signal developer interest.</p>
|
| 478 |
</div>
|
| 479 |
</div>
|
| 480 |
|
|
|
|
| 482 |
title="Open"
|
| 483 |
items={grouped.open}
|
| 484 |
viewerAnonId={idea.viewerAnonId}
|
| 485 |
+
viewerUserId={idea.viewerUserId}
|
| 486 |
+
isAuthenticated={idea.isAuthenticated}
|
| 487 |
onClaim={claim}
|
| 488 |
onUnclaim={unclaim}
|
| 489 |
onSetStatus={setStatus}
|
| 490 |
onAddLink={addLink}
|
| 491 |
onRemoveLink={removeLink}
|
| 492 |
+
onToggleWorking={toggleTaskWorking}
|
| 493 |
/>
|
| 494 |
<TaskColumn
|
| 495 |
title="In Progress"
|
| 496 |
items={grouped.inProgress}
|
| 497 |
viewerAnonId={idea.viewerAnonId}
|
| 498 |
+
viewerUserId={idea.viewerUserId}
|
| 499 |
+
isAuthenticated={idea.isAuthenticated}
|
| 500 |
onClaim={claim}
|
| 501 |
onUnclaim={unclaim}
|
| 502 |
onSetStatus={setStatus}
|
| 503 |
onAddLink={addLink}
|
| 504 |
onRemoveLink={removeLink}
|
| 505 |
+
onToggleWorking={toggleTaskWorking}
|
| 506 |
/>
|
| 507 |
<TaskColumn
|
| 508 |
title="Done"
|
| 509 |
items={grouped.done}
|
| 510 |
viewerAnonId={idea.viewerAnonId}
|
| 511 |
+
viewerUserId={idea.viewerUserId}
|
| 512 |
+
isAuthenticated={idea.isAuthenticated}
|
| 513 |
onClaim={claim}
|
| 514 |
onUnclaim={unclaim}
|
| 515 |
onSetStatus={setStatus}
|
| 516 |
onAddLink={addLink}
|
| 517 |
onRemoveLink={removeLink}
|
| 518 |
+
onToggleWorking={toggleTaskWorking}
|
| 519 |
/>
|
| 520 |
</section>
|
| 521 |
|
| 522 |
+
<section className="card reveal-up space-y-4" style={{ animationDelay: "200ms" }}>
|
| 523 |
+
<div className="flex items-end justify-between gap-2">
|
| 524 |
+
<div>
|
| 525 |
+
<h2 className="section-title">Solutions</h2>
|
| 526 |
+
<p className="subtle mt-1 text-sm">Developers can submit app/repo URLs and the idea submitter can approve.</p>
|
| 527 |
+
</div>
|
| 528 |
+
</div>
|
| 529 |
+
|
| 530 |
+
<div className="rounded-xl border border-zinc-200 bg-white/70 p-3">
|
| 531 |
+
<div className="grid gap-2 md:grid-cols-2">
|
| 532 |
+
<input className="input" value={solutionUrl} onChange={(e) => setSolutionUrl(e.target.value)} placeholder="Solution URL (app or repo)" />
|
| 533 |
+
<input className="input" value={solutionLabel} onChange={(e) => setSolutionLabel(e.target.value)} placeholder="Label (optional)" />
|
| 534 |
+
<select className="input" value={solutionType} onChange={(e) => setSolutionType(e.target.value as "APP_URL" | "GITHUB_REPO" | "OTHER")}>
|
| 535 |
+
<option value="APP_URL">App URL</option>
|
| 536 |
+
<option value="GITHUB_REPO">GitHub repo</option>
|
| 537 |
+
<option value="OTHER">Other</option>
|
| 538 |
+
</select>
|
| 539 |
+
<select className="input" value={solutionTaskId} onChange={(e) => setSolutionTaskId(e.target.value)}>
|
| 540 |
+
<option value="">For whole idea</option>
|
| 541 |
+
{idea.tasks.map((task) => (
|
| 542 |
+
<option key={task.id} value={task.id}>{task.title}</option>
|
| 543 |
+
))}
|
| 544 |
+
</select>
|
| 545 |
+
<textarea
|
| 546 |
+
className="input md:col-span-2 min-h-20"
|
| 547 |
+
value={solutionDescription}
|
| 548 |
+
onChange={(e) => setSolutionDescription(e.target.value)}
|
| 549 |
+
placeholder="How this solution addresses the demand"
|
| 550 |
+
/>
|
| 551 |
+
</div>
|
| 552 |
+
<div className="mt-2 flex items-center gap-2">
|
| 553 |
+
<button className="btn btn-primary" onClick={submitSolution} disabled={!idea.isAuthenticated}>
|
| 554 |
+
Submit Solution
|
| 555 |
+
</button>
|
| 556 |
+
{!idea.isAuthenticated ? <span className="subtle text-xs">Login required for solution submission.</span> : null}
|
| 557 |
+
</div>
|
| 558 |
+
</div>
|
| 559 |
+
|
| 560 |
+
<div className="space-y-2">
|
| 561 |
+
{solutions.length === 0 ? <p className="subtle text-sm">No solutions submitted yet.</p> : null}
|
| 562 |
+
{solutions.map((solution) => (
|
| 563 |
+
<details key={solution.id} className="rounded-xl border border-zinc-200 bg-white/65 p-3">
|
| 564 |
+
<summary className="cursor-pointer">
|
| 565 |
+
<div className="flex flex-wrap items-center justify-between gap-2">
|
| 566 |
+
<div>
|
| 567 |
+
<p className="text-sm font-semibold">{solution.label || solution.url}</p>
|
| 568 |
+
<p className="subtle text-xs">
|
| 569 |
+
by {solution.createdByDisplayName}
|
| 570 |
+
{solution.taskTitle ? ` • task: ${solution.taskTitle}` : " • idea-level solution"}
|
| 571 |
+
</p>
|
| 572 |
+
</div>
|
| 573 |
+
<div className="flex items-center gap-2">
|
| 574 |
+
{solution.approvedAt ? <span className="pill">Approved</span> : null}
|
| 575 |
+
<span className="pill">Score {solution.voteScore}</span>
|
| 576 |
+
<span className="pill">{solution.commentsCount} comments</span>
|
| 577 |
+
</div>
|
| 578 |
+
</div>
|
| 579 |
+
</summary>
|
| 580 |
+
|
| 581 |
+
<div className="mt-3 space-y-2 text-sm">
|
| 582 |
+
<a href={solution.url} target="_blank" rel="noreferrer" className="text-cyan-700 underline">{solution.url}</a>
|
| 583 |
+
{solution.description ? <p>{solution.description}</p> : null}
|
| 584 |
+
<p className="subtle text-xs">{new Date(solution.createdAt).toLocaleString()}</p>
|
| 585 |
+
|
| 586 |
+
<div className="flex flex-wrap gap-2">
|
| 587 |
+
<button className={`btn ${solution.myVote === 1 ? "btn-primary" : ""}`} onClick={() => setSolutionVote(solution.id, 1)}>
|
| 588 |
+
Like
|
| 589 |
+
</button>
|
| 590 |
+
<button className={`btn ${solution.myVote === -1 ? "btn-primary" : ""}`} onClick={() => setSolutionVote(solution.id, -1)}>
|
| 591 |
+
Unlike
|
| 592 |
+
</button>
|
| 593 |
+
{idea.canApproveSolutions && !solution.approvedAt ? (
|
| 594 |
+
<button className="btn" onClick={() => approveSolution(solution.id)}>
|
| 595 |
+
Approve Solution
|
| 596 |
+
</button>
|
| 597 |
+
) : null}
|
| 598 |
+
<button className="btn" onClick={() => loadSolutionComments(solution.id)}>
|
| 599 |
+
Load Comments
|
| 600 |
+
</button>
|
| 601 |
+
</div>
|
| 602 |
+
|
| 603 |
+
<div className="flex gap-2">
|
| 604 |
+
<input
|
| 605 |
+
className="input"
|
| 606 |
+
value={solutionCommentInput[solution.id] || ""}
|
| 607 |
+
onChange={(e) =>
|
| 608 |
+
setSolutionCommentInput((prev) => ({
|
| 609 |
+
...prev,
|
| 610 |
+
[solution.id]: e.target.value,
|
| 611 |
+
}))
|
| 612 |
+
}
|
| 613 |
+
placeholder="Comment on this solution"
|
| 614 |
+
/>
|
| 615 |
+
<button className="btn" onClick={() => addSolutionComment(solution.id)}>
|
| 616 |
+
Post
|
| 617 |
+
</button>
|
| 618 |
+
</div>
|
| 619 |
+
|
| 620 |
+
{(solutionComments[solution.id] || []).map((comment) => (
|
| 621 |
+
<div key={comment.id} className="rounded-lg border border-zinc-200 bg-white/90 p-2 text-xs">
|
| 622 |
+
<p>{comment.body}</p>
|
| 623 |
+
<p className="subtle mt-1">{comment.author_label || "Anon"} • {new Date(comment.createdAt).toLocaleString()}</p>
|
| 624 |
+
</div>
|
| 625 |
+
))}
|
| 626 |
+
</div>
|
| 627 |
+
</details>
|
| 628 |
+
))}
|
| 629 |
+
</div>
|
| 630 |
+
</section>
|
| 631 |
+
|
| 632 |
<section className="card reveal-up space-y-4" style={{ animationDelay: "240ms" }}>
|
| 633 |
<div className="flex items-end justify-between gap-2">
|
| 634 |
<h2 className="section-title">Comments</h2>
|
|
|
|
| 652 |
idea.comments.map((comment) => (
|
| 653 |
<div key={comment.id} className="rounded-xl border border-white/70 bg-white/60 p-3 text-sm">
|
| 654 |
<p>{comment.body}</p>
|
| 655 |
+
<p className="subtle mt-1 text-xs">{comment.author_label || "Anon"} • {new Date(comment.createdAt).toLocaleString()}</p>
|
| 656 |
</div>
|
| 657 |
))
|
| 658 |
) : (
|
|
|
|
| 674 |
title,
|
| 675 |
items,
|
| 676 |
viewerAnonId,
|
| 677 |
+
viewerUserId,
|
| 678 |
+
isAuthenticated,
|
| 679 |
onClaim,
|
| 680 |
onUnclaim,
|
| 681 |
onSetStatus,
|
| 682 |
onAddLink,
|
| 683 |
onRemoveLink,
|
| 684 |
+
onToggleWorking,
|
| 685 |
}: {
|
| 686 |
title: string;
|
| 687 |
items: TaskItem[];
|
| 688 |
viewerAnonId: string;
|
| 689 |
+
viewerUserId: string | null;
|
| 690 |
+
isAuthenticated: boolean;
|
| 691 |
onClaim: (taskId: string) => Promise<void>;
|
| 692 |
onUnclaim: (taskId: string) => Promise<void>;
|
| 693 |
onSetStatus: (taskId: string, status: TaskItem["status"]) => Promise<void>;
|
| 694 |
onAddLink: (taskId: string) => Promise<void>;
|
| 695 |
onRemoveLink: (taskId: string, linkId: string) => Promise<void>;
|
| 696 |
+
onToggleWorking: (taskId: string, working: boolean) => Promise<void>;
|
| 697 |
}) {
|
| 698 |
return (
|
| 699 |
<div className="space-y-2">
|
| 700 |
<h3 className="text-sm font-semibold uppercase tracking-[0.16em] text-zinc-600">{title}</h3>
|
| 701 |
{items.length === 0 ? <p className="subtle text-sm">No tasks.</p> : null}
|
| 702 |
{items.map((task) => {
|
| 703 |
+
const isClaimedByMe = viewerUserId
|
| 704 |
+
? task.claimedByUserId === viewerUserId
|
| 705 |
+
: !task.claimedByUserId && task.claimedByAnonId === viewerAnonId;
|
| 706 |
+
|
| 707 |
+
const isClaimedBySomeoneElse = Boolean(task.claimedByUserId || task.claimedByAnonId) && !isClaimedByMe;
|
| 708 |
|
| 709 |
return (
|
| 710 |
+
<details key={task.id} className="rounded-xl border border-white/70 bg-white/65 p-3">
|
| 711 |
<summary className="cursor-pointer text-sm font-semibold">
|
| 712 |
<span>{task.title}</span>
|
| 713 |
<span className={`ml-2 inline-flex rounded-full border px-2 py-0.5 text-xs ${statusBadgeClass(task.status)}`}>
|
| 714 |
{formatStatus(task.status)}
|
| 715 |
</span>
|
| 716 |
{task.effort ? <span className="ml-2 text-xs text-zinc-500">Effort {task.effort}</span> : null}
|
| 717 |
+
<span className="ml-2 text-xs text-zinc-500">Working votes {task.working_count}</span>
|
| 718 |
</summary>
|
| 719 |
|
| 720 |
<div className="mt-3 space-y-2 text-sm">
|
| 721 |
{task.description ? <p>{task.description}</p> : null}
|
| 722 |
+
{task.claimedByAnonId || task.claimedByUserId ? (
|
| 723 |
<p className="text-xs text-zinc-600">
|
| 724 |
+
Claimed by <span className="font-medium">{task.claimantDisplayName || "anon"}</span>
|
| 725 |
</p>
|
| 726 |
) : (
|
| 727 |
<p className="text-xs text-zinc-600">Unclaimed</p>
|
|
|
|
| 736 |
) : null}
|
| 737 |
|
| 738 |
<div className="flex flex-wrap gap-2">
|
| 739 |
+
{!task.claimedByAnonId && !task.claimedByUserId ? (
|
| 740 |
<button className="btn" onClick={() => onClaim(task.id)}>
|
| 741 |
Claim
|
| 742 |
</button>
|
|
|
|
| 762 |
</>
|
| 763 |
) : null}
|
| 764 |
|
| 765 |
+
<button className={`btn ${task.working ? "btn-primary" : ""}`} onClick={() => onToggleWorking(task.id, task.working)} disabled={!isAuthenticated}>
|
| 766 |
+
I am working
|
| 767 |
+
</button>
|
| 768 |
+
|
| 769 |
{isClaimedBySomeoneElse ? <span className="subtle text-xs">Only claimant can update this task.</span> : null}
|
| 770 |
</div>
|
| 771 |
|
| 772 |
<div className="space-y-1.5">
|
| 773 |
{task.links.map((link) => {
|
| 774 |
+
const canRemoveAsUser = Boolean(viewerUserId) && (link.createdByUserId === viewerUserId || task.claimedByUserId === viewerUserId);
|
| 775 |
+
const canRemoveAsAnon = !viewerUserId && (link.createdByAnonId === viewerAnonId || task.claimedByAnonId === viewerAnonId);
|
| 776 |
+
const canRemove = canRemoveAsUser || canRemoveAsAnon;
|
| 777 |
+
|
| 778 |
return (
|
| 779 |
<div key={link.id} className="flex items-center justify-between gap-2 rounded-lg border border-zinc-200 bg-white/90 px-2 py-1">
|
| 780 |
<a href={link.url} target="_blank" rel="noreferrer" className="truncate text-cyan-700 underline">
|
components/SubmitForm.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
"use client";
|
| 2 |
|
|
|
|
| 3 |
import { useRouter } from "next/navigation";
|
| 4 |
import { useMemo, useState } from "react";
|
| 5 |
import { fetchWithAnon } from "@/lib/client-anon";
|
|
@@ -15,12 +16,13 @@ function parseErrorMessage(error: unknown): string {
|
|
| 15 |
return "Failed to generate requirements.";
|
| 16 |
}
|
| 17 |
|
| 18 |
-
export function SubmitForm() {
|
| 19 |
const router = useRouter();
|
| 20 |
const [rawText, setRawText] = useState("");
|
| 21 |
const [targetUsers, setTargetUsers] = useState("");
|
| 22 |
const [platform, setPlatform] = useState("Any");
|
| 23 |
const [constraints, setConstraints] = useState("");
|
|
|
|
| 24 |
const [loading, setLoading] = useState(false);
|
| 25 |
const [error, setError] = useState("");
|
| 26 |
|
|
@@ -40,6 +42,7 @@ export function SubmitForm() {
|
|
| 40 |
target_users: targetUsers || undefined,
|
| 41 |
platform: platform === "Any" ? undefined : platform,
|
| 42 |
constraints: constraints || undefined,
|
|
|
|
| 43 |
}),
|
| 44 |
});
|
| 45 |
|
|
@@ -108,6 +111,25 @@ export function SubmitForm() {
|
|
| 108 |
maxLength={500}
|
| 109 |
/>
|
| 110 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
</div>
|
| 112 |
|
| 113 |
<div className="rounded-xl border border-amber-200 bg-amber-50/80 p-3 text-xs text-amber-900">
|
|
|
|
| 1 |
"use client";
|
| 2 |
|
| 3 |
+
import Link from "next/link";
|
| 4 |
import { useRouter } from "next/navigation";
|
| 5 |
import { useMemo, useState } from "react";
|
| 6 |
import { fetchWithAnon } from "@/lib/client-anon";
|
|
|
|
| 16 |
return "Failed to generate requirements.";
|
| 17 |
}
|
| 18 |
|
| 19 |
+
export function SubmitForm({ canShowIdentity }: { canShowIdentity: boolean }) {
|
| 20 |
const router = useRouter();
|
| 21 |
const [rawText, setRawText] = useState("");
|
| 22 |
const [targetUsers, setTargetUsers] = useState("");
|
| 23 |
const [platform, setPlatform] = useState("Any");
|
| 24 |
const [constraints, setConstraints] = useState("");
|
| 25 |
+
const [showName, setShowName] = useState(false);
|
| 26 |
const [loading, setLoading] = useState(false);
|
| 27 |
const [error, setError] = useState("");
|
| 28 |
|
|
|
|
| 42 |
target_users: targetUsers || undefined,
|
| 43 |
platform: platform === "Any" ? undefined : platform,
|
| 44 |
constraints: constraints || undefined,
|
| 45 |
+
show_name: showName,
|
| 46 |
}),
|
| 47 |
});
|
| 48 |
|
|
|
|
| 111 |
maxLength={500}
|
| 112 |
/>
|
| 113 |
</div>
|
| 114 |
+
|
| 115 |
+
<div className="md:col-span-2 rounded-xl border border-zinc-200 bg-white/70 p-3">
|
| 116 |
+
<label className="inline-flex items-center gap-2 text-sm font-medium">
|
| 117 |
+
<input
|
| 118 |
+
type="checkbox"
|
| 119 |
+
checked={showName}
|
| 120 |
+
onChange={(e) => setShowName(e.target.checked)}
|
| 121 |
+
disabled={!canShowIdentity}
|
| 122 |
+
/>
|
| 123 |
+
Show my name publicly as idea submitter
|
| 124 |
+
</label>
|
| 125 |
+
{!canShowIdentity ? (
|
| 126 |
+
<p className="subtle mt-2 text-xs">
|
| 127 |
+
Login is required to publish with your visible name. <Link href="/login" className="underline">Sign in</Link>
|
| 128 |
+
</p>
|
| 129 |
+
) : (
|
| 130 |
+
<p className="subtle mt-2 text-xs">Default remains anonymous even when logged in.</p>
|
| 131 |
+
)}
|
| 132 |
+
</div>
|
| 133 |
</div>
|
| 134 |
|
| 135 |
<div className="rounded-xl border border-amber-200 bg-amber-50/80 p-3 text-xs text-amber-900">
|
lib/actor.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { auth } from "@/auth";
|
| 2 |
+
import { getAnonId } from "@/lib/identity";
|
| 3 |
+
|
| 4 |
+
export async function getActor() {
|
| 5 |
+
const session = await auth();
|
| 6 |
+
const anonId = await getAnonId();
|
| 7 |
+
|
| 8 |
+
return {
|
| 9 |
+
session,
|
| 10 |
+
userId: session?.user?.id ?? null,
|
| 11 |
+
anonId: anonId || null,
|
| 12 |
+
};
|
| 13 |
+
}
|
next.config.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
import type { NextConfig } from "next";
|
| 2 |
|
| 3 |
const nextConfig: NextConfig = {
|
| 4 |
-
|
| 5 |
-
typedRoutes: true,
|
| 6 |
-
},
|
| 7 |
};
|
| 8 |
|
| 9 |
export default nextConfig;
|
|
|
|
| 1 |
import type { NextConfig } from "next";
|
| 2 |
|
| 3 |
const nextConfig: NextConfig = {
|
| 4 |
+
typedRoutes: true,
|
|
|
|
|
|
|
| 5 |
};
|
| 6 |
|
| 7 |
export default nextConfig;
|
package-lock.json
CHANGED
|
@@ -8,8 +8,10 @@
|
|
| 8 |
"name": "demandsolution-codex",
|
| 9 |
"version": "0.1.0",
|
| 10 |
"dependencies": {
|
|
|
|
| 11 |
"@prisma/client": "^6.4.1",
|
| 12 |
"next": "^15.5.12",
|
|
|
|
| 13 |
"openai": "^4.80.1",
|
| 14 |
"react": "^19.0.0",
|
| 15 |
"react-dom": "^19.0.0",
|
|
@@ -39,6 +41,76 @@
|
|
| 39 |
"url": "https://github.com/sponsors/sindresorhus"
|
| 40 |
}
|
| 41 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
"node_modules/@emnapi/runtime": {
|
| 43 |
"version": "1.8.1",
|
| 44 |
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.8.1.tgz",
|
|
@@ -726,6 +798,15 @@
|
|
| 726 |
"node": ">= 8"
|
| 727 |
}
|
| 728 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 729 |
"node_modules/@prisma/client": {
|
| 730 |
"version": "6.19.2",
|
| 731 |
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-6.19.2.tgz",
|
|
@@ -1729,6 +1810,15 @@
|
|
| 1729 |
"jiti": "lib/jiti-cli.mjs"
|
| 1730 |
}
|
| 1731 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1732 |
"node_modules/lilconfig": {
|
| 1733 |
"version": "3.1.3",
|
| 1734 |
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.3.tgz",
|
|
@@ -1891,6 +1981,33 @@
|
|
| 1891 |
}
|
| 1892 |
}
|
| 1893 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1894 |
"node_modules/next/node_modules/postcss": {
|
| 1895 |
"version": "8.4.31",
|
| 1896 |
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
|
|
@@ -2008,6 +2125,15 @@
|
|
| 2008 |
"devOptional": true,
|
| 2009 |
"license": "MIT"
|
| 2010 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2011 |
"node_modules/object-assign": {
|
| 2012 |
"version": "4.1.1",
|
| 2013 |
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
|
@@ -2315,6 +2441,25 @@
|
|
| 2315 |
"dev": true,
|
| 2316 |
"license": "MIT"
|
| 2317 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2318 |
"node_modules/prisma": {
|
| 2319 |
"version": "6.19.2",
|
| 2320 |
"resolved": "https://registry.npmjs.org/prisma/-/prisma-6.19.2.tgz",
|
|
|
|
| 8 |
"name": "demandsolution-codex",
|
| 9 |
"version": "0.1.0",
|
| 10 |
"dependencies": {
|
| 11 |
+
"@auth/prisma-adapter": "^2.11.1",
|
| 12 |
"@prisma/client": "^6.4.1",
|
| 13 |
"next": "^15.5.12",
|
| 14 |
+
"next-auth": "^5.0.0-beta.30",
|
| 15 |
"openai": "^4.80.1",
|
| 16 |
"react": "^19.0.0",
|
| 17 |
"react-dom": "^19.0.0",
|
|
|
|
| 41 |
"url": "https://github.com/sponsors/sindresorhus"
|
| 42 |
}
|
| 43 |
},
|
| 44 |
+
"node_modules/@auth/core": {
|
| 45 |
+
"version": "0.41.0",
|
| 46 |
+
"resolved": "https://registry.npmjs.org/@auth/core/-/core-0.41.0.tgz",
|
| 47 |
+
"integrity": "sha512-Wd7mHPQ/8zy6Qj7f4T46vg3aoor8fskJm6g2Zyj064oQ3+p0xNZXAV60ww0hY+MbTesfu29kK14Zk5d5JTazXQ==",
|
| 48 |
+
"license": "ISC",
|
| 49 |
+
"dependencies": {
|
| 50 |
+
"@panva/hkdf": "^1.2.1",
|
| 51 |
+
"jose": "^6.0.6",
|
| 52 |
+
"oauth4webapi": "^3.3.0",
|
| 53 |
+
"preact": "10.24.3",
|
| 54 |
+
"preact-render-to-string": "6.5.11"
|
| 55 |
+
},
|
| 56 |
+
"peerDependencies": {
|
| 57 |
+
"@simplewebauthn/browser": "^9.0.1",
|
| 58 |
+
"@simplewebauthn/server": "^9.0.2",
|
| 59 |
+
"nodemailer": "^6.8.0"
|
| 60 |
+
},
|
| 61 |
+
"peerDependenciesMeta": {
|
| 62 |
+
"@simplewebauthn/browser": {
|
| 63 |
+
"optional": true
|
| 64 |
+
},
|
| 65 |
+
"@simplewebauthn/server": {
|
| 66 |
+
"optional": true
|
| 67 |
+
},
|
| 68 |
+
"nodemailer": {
|
| 69 |
+
"optional": true
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
},
|
| 73 |
+
"node_modules/@auth/prisma-adapter": {
|
| 74 |
+
"version": "2.11.1",
|
| 75 |
+
"resolved": "https://registry.npmjs.org/@auth/prisma-adapter/-/prisma-adapter-2.11.1.tgz",
|
| 76 |
+
"integrity": "sha512-Ke7DXP0Fy0Mlmjz/ZJLXwQash2UkA4621xCM0rMtEczr1kppLc/njCbUkHkIQ/PnmILjqSPEKeTjDPsYruvkug==",
|
| 77 |
+
"license": "ISC",
|
| 78 |
+
"dependencies": {
|
| 79 |
+
"@auth/core": "0.41.1"
|
| 80 |
+
},
|
| 81 |
+
"peerDependencies": {
|
| 82 |
+
"@prisma/client": ">=2.26.0 || >=3 || >=4 || >=5 || >=6"
|
| 83 |
+
}
|
| 84 |
+
},
|
| 85 |
+
"node_modules/@auth/prisma-adapter/node_modules/@auth/core": {
|
| 86 |
+
"version": "0.41.1",
|
| 87 |
+
"resolved": "https://registry.npmjs.org/@auth/core/-/core-0.41.1.tgz",
|
| 88 |
+
"integrity": "sha512-t9cJ2zNYAdWMacGRMT6+r4xr1uybIdmYa49calBPeTqwgAFPV/88ac9TEvCR85pvATiSPt8VaNf+Gt24JIT/uw==",
|
| 89 |
+
"license": "ISC",
|
| 90 |
+
"dependencies": {
|
| 91 |
+
"@panva/hkdf": "^1.2.1",
|
| 92 |
+
"jose": "^6.0.6",
|
| 93 |
+
"oauth4webapi": "^3.3.0",
|
| 94 |
+
"preact": "10.24.3",
|
| 95 |
+
"preact-render-to-string": "6.5.11"
|
| 96 |
+
},
|
| 97 |
+
"peerDependencies": {
|
| 98 |
+
"@simplewebauthn/browser": "^9.0.1",
|
| 99 |
+
"@simplewebauthn/server": "^9.0.2",
|
| 100 |
+
"nodemailer": "^7.0.7"
|
| 101 |
+
},
|
| 102 |
+
"peerDependenciesMeta": {
|
| 103 |
+
"@simplewebauthn/browser": {
|
| 104 |
+
"optional": true
|
| 105 |
+
},
|
| 106 |
+
"@simplewebauthn/server": {
|
| 107 |
+
"optional": true
|
| 108 |
+
},
|
| 109 |
+
"nodemailer": {
|
| 110 |
+
"optional": true
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
},
|
| 114 |
"node_modules/@emnapi/runtime": {
|
| 115 |
"version": "1.8.1",
|
| 116 |
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.8.1.tgz",
|
|
|
|
| 798 |
"node": ">= 8"
|
| 799 |
}
|
| 800 |
},
|
| 801 |
+
"node_modules/@panva/hkdf": {
|
| 802 |
+
"version": "1.2.1",
|
| 803 |
+
"resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.2.1.tgz",
|
| 804 |
+
"integrity": "sha512-6oclG6Y3PiDFcoyk8srjLfVKyMfVCKJ27JwNPViuXziFpmdz+MZnZN/aKY0JGXgYuO/VghU0jcOAZgWXZ1Dmrw==",
|
| 805 |
+
"license": "MIT",
|
| 806 |
+
"funding": {
|
| 807 |
+
"url": "https://github.com/sponsors/panva"
|
| 808 |
+
}
|
| 809 |
+
},
|
| 810 |
"node_modules/@prisma/client": {
|
| 811 |
"version": "6.19.2",
|
| 812 |
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-6.19.2.tgz",
|
|
|
|
| 1810 |
"jiti": "lib/jiti-cli.mjs"
|
| 1811 |
}
|
| 1812 |
},
|
| 1813 |
+
"node_modules/jose": {
|
| 1814 |
+
"version": "6.1.3",
|
| 1815 |
+
"resolved": "https://registry.npmjs.org/jose/-/jose-6.1.3.tgz",
|
| 1816 |
+
"integrity": "sha512-0TpaTfihd4QMNwrz/ob2Bp7X04yuxJkjRGi4aKmOqwhov54i6u79oCv7T+C7lo70MKH6BesI3vscD1yb/yzKXQ==",
|
| 1817 |
+
"license": "MIT",
|
| 1818 |
+
"funding": {
|
| 1819 |
+
"url": "https://github.com/sponsors/panva"
|
| 1820 |
+
}
|
| 1821 |
+
},
|
| 1822 |
"node_modules/lilconfig": {
|
| 1823 |
"version": "3.1.3",
|
| 1824 |
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.3.tgz",
|
|
|
|
| 1981 |
}
|
| 1982 |
}
|
| 1983 |
},
|
| 1984 |
+
"node_modules/next-auth": {
|
| 1985 |
+
"version": "5.0.0-beta.30",
|
| 1986 |
+
"resolved": "https://registry.npmjs.org/next-auth/-/next-auth-5.0.0-beta.30.tgz",
|
| 1987 |
+
"integrity": "sha512-+c51gquM3F6nMVmoAusRJ7RIoY0K4Ts9HCCwyy/BRoe4mp3msZpOzYMyb5LAYc1wSo74PMQkGDcaghIO7W6Xjg==",
|
| 1988 |
+
"license": "ISC",
|
| 1989 |
+
"dependencies": {
|
| 1990 |
+
"@auth/core": "0.41.0"
|
| 1991 |
+
},
|
| 1992 |
+
"peerDependencies": {
|
| 1993 |
+
"@simplewebauthn/browser": "^9.0.1",
|
| 1994 |
+
"@simplewebauthn/server": "^9.0.2",
|
| 1995 |
+
"next": "^14.0.0-0 || ^15.0.0 || ^16.0.0",
|
| 1996 |
+
"nodemailer": "^7.0.7",
|
| 1997 |
+
"react": "^18.2.0 || ^19.0.0"
|
| 1998 |
+
},
|
| 1999 |
+
"peerDependenciesMeta": {
|
| 2000 |
+
"@simplewebauthn/browser": {
|
| 2001 |
+
"optional": true
|
| 2002 |
+
},
|
| 2003 |
+
"@simplewebauthn/server": {
|
| 2004 |
+
"optional": true
|
| 2005 |
+
},
|
| 2006 |
+
"nodemailer": {
|
| 2007 |
+
"optional": true
|
| 2008 |
+
}
|
| 2009 |
+
}
|
| 2010 |
+
},
|
| 2011 |
"node_modules/next/node_modules/postcss": {
|
| 2012 |
"version": "8.4.31",
|
| 2013 |
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
|
|
|
|
| 2125 |
"devOptional": true,
|
| 2126 |
"license": "MIT"
|
| 2127 |
},
|
| 2128 |
+
"node_modules/oauth4webapi": {
|
| 2129 |
+
"version": "3.8.5",
|
| 2130 |
+
"resolved": "https://registry.npmjs.org/oauth4webapi/-/oauth4webapi-3.8.5.tgz",
|
| 2131 |
+
"integrity": "sha512-A8jmyUckVhRJj5lspguklcl90Ydqk61H3dcU0oLhH3Yv13KpAliKTt5hknpGGPZSSfOwGyraNEFmofDYH+1kSg==",
|
| 2132 |
+
"license": "MIT",
|
| 2133 |
+
"funding": {
|
| 2134 |
+
"url": "https://github.com/sponsors/panva"
|
| 2135 |
+
}
|
| 2136 |
+
},
|
| 2137 |
"node_modules/object-assign": {
|
| 2138 |
"version": "4.1.1",
|
| 2139 |
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
|
|
|
| 2441 |
"dev": true,
|
| 2442 |
"license": "MIT"
|
| 2443 |
},
|
| 2444 |
+
"node_modules/preact": {
|
| 2445 |
+
"version": "10.24.3",
|
| 2446 |
+
"resolved": "https://registry.npmjs.org/preact/-/preact-10.24.3.tgz",
|
| 2447 |
+
"integrity": "sha512-Z2dPnBnMUfyQfSQ+GBdsGa16hz35YmLmtTLhM169uW944hYL6xzTYkJjC07j+Wosz733pMWx0fgON3JNw1jJQA==",
|
| 2448 |
+
"license": "MIT",
|
| 2449 |
+
"funding": {
|
| 2450 |
+
"type": "opencollective",
|
| 2451 |
+
"url": "https://opencollective.com/preact"
|
| 2452 |
+
}
|
| 2453 |
+
},
|
| 2454 |
+
"node_modules/preact-render-to-string": {
|
| 2455 |
+
"version": "6.5.11",
|
| 2456 |
+
"resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-6.5.11.tgz",
|
| 2457 |
+
"integrity": "sha512-ubnauqoGczeGISiOh6RjX0/cdaF8v/oDXIjO85XALCQjwQP+SB4RDXXtvZ6yTYSjG+PC1QRP2AhPgCEsM2EvUw==",
|
| 2458 |
+
"license": "MIT",
|
| 2459 |
+
"peerDependencies": {
|
| 2460 |
+
"preact": ">=10"
|
| 2461 |
+
}
|
| 2462 |
+
},
|
| 2463 |
"node_modules/prisma": {
|
| 2464 |
"version": "6.19.2",
|
| 2465 |
"resolved": "https://registry.npmjs.org/prisma/-/prisma-6.19.2.tgz",
|
package.json
CHANGED
|
@@ -11,8 +11,10 @@
|
|
| 11 |
"prisma:migrate": "prisma migrate dev --name init"
|
| 12 |
},
|
| 13 |
"dependencies": {
|
|
|
|
| 14 |
"@prisma/client": "^6.4.1",
|
| 15 |
"next": "^15.5.12",
|
|
|
|
| 16 |
"openai": "^4.80.1",
|
| 17 |
"react": "^19.0.0",
|
| 18 |
"react-dom": "^19.0.0",
|
|
|
|
| 11 |
"prisma:migrate": "prisma migrate dev --name init"
|
| 12 |
},
|
| 13 |
"dependencies": {
|
| 14 |
+
"@auth/prisma-adapter": "^2.11.1",
|
| 15 |
"@prisma/client": "^6.4.1",
|
| 16 |
"next": "^15.5.12",
|
| 17 |
+
"next-auth": "^5.0.0-beta.30",
|
| 18 |
"openai": "^4.80.1",
|
| 19 |
"react": "^19.0.0",
|
| 20 |
"react-dom": "^19.0.0",
|
prisma/schema.prisma
CHANGED
|
@@ -7,82 +7,281 @@ datasource db {
|
|
| 7 |
url = env("DATABASE_URL")
|
| 8 |
}
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
model Idea {
|
| 11 |
-
id
|
| 12 |
-
createdAt
|
| 13 |
-
createdByAnonId
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
|
| 30 |
model Task {
|
| 31 |
-
id
|
| 32 |
-
createdAt
|
| 33 |
-
ideaId
|
| 34 |
-
title
|
| 35 |
-
description
|
| 36 |
-
acceptance
|
| 37 |
-
effort
|
| 38 |
-
status
|
| 39 |
-
claimedByAnonId
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
model TaskLink {
|
| 47 |
id String @id @default(uuid())
|
| 48 |
-
taskId
|
| 49 |
-
url
|
| 50 |
-
label
|
| 51 |
-
createdByAnonId
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
| 55 |
|
| 56 |
model Comment {
|
| 57 |
id String @id @default(uuid())
|
| 58 |
ideaId String
|
| 59 |
body String
|
| 60 |
-
createdByAnonId String
|
|
|
|
| 61 |
createdAt DateTime @default(now())
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
}
|
| 64 |
|
| 65 |
model Vote {
|
| 66 |
-
ideaId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
anonId String
|
|
|
|
| 68 |
createdAt DateTime @default(now())
|
| 69 |
-
idea Idea @relation(fields: [ideaId], references: [id], onDelete: Cascade)
|
| 70 |
|
| 71 |
-
@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
}
|
| 73 |
|
| 74 |
model Nickname {
|
| 75 |
-
anonId String
|
| 76 |
nickname String
|
| 77 |
updatedAt DateTime @updatedAt
|
| 78 |
}
|
| 79 |
|
| 80 |
model SubmissionRateLimit {
|
| 81 |
-
id String
|
| 82 |
anonId String
|
| 83 |
ipAddress String
|
| 84 |
windowStart String
|
| 85 |
-
count Int
|
| 86 |
|
| 87 |
@@unique([anonId, ipAddress, windowStart])
|
| 88 |
}
|
|
|
|
| 7 |
url = env("DATABASE_URL")
|
| 8 |
}
|
| 9 |
|
| 10 |
+
model User {
|
| 11 |
+
id String @id @default(cuid())
|
| 12 |
+
name String?
|
| 13 |
+
email String? @unique
|
| 14 |
+
emailVerified DateTime?
|
| 15 |
+
image String?
|
| 16 |
+
createdAt DateTime @default(now())
|
| 17 |
+
updatedAt DateTime @updatedAt
|
| 18 |
+
|
| 19 |
+
accounts Account[]
|
| 20 |
+
sessions Session[]
|
| 21 |
+
|
| 22 |
+
developerProfile DeveloperProfile?
|
| 23 |
+
|
| 24 |
+
ideas Idea[] @relation("IdeaCreatorUser")
|
| 25 |
+
taskClaims Task[] @relation("TaskClaimUser")
|
| 26 |
+
taskLinks TaskLink[] @relation("TaskLinkCreatorUser")
|
| 27 |
+
comments Comment[] @relation("CommentCreatorUser")
|
| 28 |
+
ideaVotes IdeaUserVote[]
|
| 29 |
+
ideaWorkVotes IdeaWorkVote[]
|
| 30 |
+
taskWorkVotes TaskWorkVote[]
|
| 31 |
+
solutions Solution[] @relation("SolutionCreatorUser")
|
| 32 |
+
approvedSolutions Solution[] @relation("SolutionApprovedByUser")
|
| 33 |
+
solutionVotes SolutionUserVote[]
|
| 34 |
+
solutionComments SolutionComment[] @relation("SolutionCommentUser")
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
model Account {
|
| 38 |
+
userId String
|
| 39 |
+
type String
|
| 40 |
+
provider String
|
| 41 |
+
providerAccountId String
|
| 42 |
+
refresh_token String?
|
| 43 |
+
access_token String?
|
| 44 |
+
expires_at Int?
|
| 45 |
+
token_type String?
|
| 46 |
+
scope String?
|
| 47 |
+
id_token String?
|
| 48 |
+
session_state String?
|
| 49 |
+
createdAt DateTime @default(now())
|
| 50 |
+
updatedAt DateTime @updatedAt
|
| 51 |
+
|
| 52 |
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
| 53 |
+
|
| 54 |
+
@@id([provider, providerAccountId])
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
model Session {
|
| 58 |
+
sessionToken String @id
|
| 59 |
+
userId String
|
| 60 |
+
expires DateTime
|
| 61 |
+
createdAt DateTime @default(now())
|
| 62 |
+
updatedAt DateTime @updatedAt
|
| 63 |
+
|
| 64 |
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
model VerificationToken {
|
| 68 |
+
identifier String
|
| 69 |
+
token String @unique
|
| 70 |
+
expires DateTime
|
| 71 |
+
|
| 72 |
+
@@id([identifier, token])
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
model DeveloperProfile {
|
| 76 |
+
id String @id @default(cuid())
|
| 77 |
+
userId String @unique
|
| 78 |
+
displayName String
|
| 79 |
+
headline String?
|
| 80 |
+
bio String?
|
| 81 |
+
githubUrl String?
|
| 82 |
+
websiteUrl String?
|
| 83 |
+
createdAt DateTime @default(now())
|
| 84 |
+
updatedAt DateTime @updatedAt
|
| 85 |
+
|
| 86 |
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
model Idea {
|
| 90 |
+
id String @id @default(uuid())
|
| 91 |
+
createdAt DateTime @default(now())
|
| 92 |
+
createdByAnonId String?
|
| 93 |
+
createdByUserId String?
|
| 94 |
+
isAnonymous Boolean @default(true)
|
| 95 |
+
submitterVisibleName String?
|
| 96 |
+
rawInputText String
|
| 97 |
+
targetUsers String?
|
| 98 |
+
platform String?
|
| 99 |
+
constraints String?
|
| 100 |
+
title String
|
| 101 |
+
problemStatement String
|
| 102 |
+
tags String
|
| 103 |
+
features String
|
| 104 |
+
openQuestions String
|
| 105 |
+
upvotesCount Int @default(0)
|
| 106 |
+
commentsCount Int @default(0)
|
| 107 |
+
|
| 108 |
+
createdByUser User? @relation("IdeaCreatorUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
|
| 109 |
+
|
| 110 |
+
tasks Task[]
|
| 111 |
+
comments Comment[]
|
| 112 |
+
votes Vote[]
|
| 113 |
+
userVotes IdeaUserVote[]
|
| 114 |
+
workVotes IdeaWorkVote[]
|
| 115 |
+
solutions Solution[]
|
| 116 |
}
|
| 117 |
|
| 118 |
model Task {
|
| 119 |
+
id String @id @default(uuid())
|
| 120 |
+
createdAt DateTime @default(now())
|
| 121 |
+
ideaId String
|
| 122 |
+
title String
|
| 123 |
+
description String?
|
| 124 |
+
acceptance String
|
| 125 |
+
effort String?
|
| 126 |
+
status String @default("OPEN")
|
| 127 |
+
claimedByAnonId String?
|
| 128 |
+
claimedByUserId String?
|
| 129 |
+
claimedAt DateTime?
|
| 130 |
+
updatedAt DateTime @updatedAt
|
| 131 |
+
|
| 132 |
+
idea Idea @relation(fields: [ideaId], references: [id], onDelete: Cascade)
|
| 133 |
+
claimedByUser User? @relation("TaskClaimUser", fields: [claimedByUserId], references: [id], onDelete: SetNull)
|
| 134 |
+
links TaskLink[]
|
| 135 |
+
workVotes TaskWorkVote[]
|
| 136 |
+
solutions Solution[]
|
| 137 |
}
|
| 138 |
|
| 139 |
model TaskLink {
|
| 140 |
id String @id @default(uuid())
|
| 141 |
+
taskId String
|
| 142 |
+
url String
|
| 143 |
+
label String?
|
| 144 |
+
createdByAnonId String?
|
| 145 |
+
createdByUserId String?
|
| 146 |
+
createdAt DateTime @default(now())
|
| 147 |
+
|
| 148 |
+
task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
|
| 149 |
+
createdByUser User? @relation("TaskLinkCreatorUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
|
| 150 |
}
|
| 151 |
|
| 152 |
model Comment {
|
| 153 |
id String @id @default(uuid())
|
| 154 |
ideaId String
|
| 155 |
body String
|
| 156 |
+
createdByAnonId String?
|
| 157 |
+
createdByUserId String?
|
| 158 |
createdAt DateTime @default(now())
|
| 159 |
+
|
| 160 |
+
idea Idea @relation(fields: [ideaId], references: [id], onDelete: Cascade)
|
| 161 |
+
createdByUser User? @relation("CommentCreatorUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
|
| 162 |
}
|
| 163 |
|
| 164 |
model Vote {
|
| 165 |
+
ideaId String
|
| 166 |
+
anonId String
|
| 167 |
+
createdAt DateTime @default(now())
|
| 168 |
+
|
| 169 |
+
idea Idea @relation(fields: [ideaId], references: [id], onDelete: Cascade)
|
| 170 |
+
|
| 171 |
+
@@id([ideaId, anonId])
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
model IdeaUserVote {
|
| 175 |
+
ideaId String
|
| 176 |
+
userId String
|
| 177 |
+
createdAt DateTime @default(now())
|
| 178 |
+
|
| 179 |
+
idea Idea @relation(fields: [ideaId], references: [id], onDelete: Cascade)
|
| 180 |
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
| 181 |
+
|
| 182 |
+
@@id([ideaId, userId])
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
model IdeaWorkVote {
|
| 186 |
+
ideaId String
|
| 187 |
+
userId String
|
| 188 |
+
createdAt DateTime @default(now())
|
| 189 |
+
|
| 190 |
+
idea Idea @relation(fields: [ideaId], references: [id], onDelete: Cascade)
|
| 191 |
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
| 192 |
+
|
| 193 |
+
@@id([ideaId, userId])
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
model TaskWorkVote {
|
| 197 |
+
taskId String
|
| 198 |
+
userId String
|
| 199 |
+
createdAt DateTime @default(now())
|
| 200 |
+
|
| 201 |
+
task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
|
| 202 |
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
| 203 |
+
|
| 204 |
+
@@id([taskId, userId])
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
enum SolutionType {
|
| 208 |
+
APP_URL
|
| 209 |
+
GITHUB_REPO
|
| 210 |
+
OTHER
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
model Solution {
|
| 214 |
+
id String @id @default(uuid())
|
| 215 |
+
ideaId String
|
| 216 |
+
taskId String?
|
| 217 |
+
createdByUserId String
|
| 218 |
+
url String
|
| 219 |
+
label String?
|
| 220 |
+
description String?
|
| 221 |
+
type SolutionType @default(OTHER)
|
| 222 |
+
createdAt DateTime @default(now())
|
| 223 |
+
updatedAt DateTime @updatedAt
|
| 224 |
+
approvedAt DateTime?
|
| 225 |
+
approvedBySubmitterAnonId String?
|
| 226 |
+
approvedBySubmitterUserId String?
|
| 227 |
+
|
| 228 |
+
idea Idea @relation(fields: [ideaId], references: [id], onDelete: Cascade)
|
| 229 |
+
task Task? @relation(fields: [taskId], references: [id], onDelete: SetNull)
|
| 230 |
+
createdByUser User @relation("SolutionCreatorUser", fields: [createdByUserId], references: [id], onDelete: Cascade)
|
| 231 |
+
approvedByUser User? @relation("SolutionApprovedByUser", fields: [approvedBySubmitterUserId], references: [id], onDelete: SetNull)
|
| 232 |
+
|
| 233 |
+
userVotes SolutionUserVote[]
|
| 234 |
+
anonVotes SolutionAnonVote[]
|
| 235 |
+
comments SolutionComment[]
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
model SolutionUserVote {
|
| 239 |
+
solutionId String
|
| 240 |
+
userId String
|
| 241 |
+
value Int
|
| 242 |
+
createdAt DateTime @default(now())
|
| 243 |
+
|
| 244 |
+
solution Solution @relation(fields: [solutionId], references: [id], onDelete: Cascade)
|
| 245 |
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
| 246 |
+
|
| 247 |
+
@@id([solutionId, userId])
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
model SolutionAnonVote {
|
| 251 |
+
solutionId String
|
| 252 |
anonId String
|
| 253 |
+
value Int
|
| 254 |
createdAt DateTime @default(now())
|
|
|
|
| 255 |
|
| 256 |
+
solution Solution @relation(fields: [solutionId], references: [id], onDelete: Cascade)
|
| 257 |
+
|
| 258 |
+
@@id([solutionId, anonId])
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
model SolutionComment {
|
| 262 |
+
id String @id @default(uuid())
|
| 263 |
+
solutionId String
|
| 264 |
+
body String
|
| 265 |
+
createdByUserId String?
|
| 266 |
+
createdByAnonId String?
|
| 267 |
+
createdAt DateTime @default(now())
|
| 268 |
+
|
| 269 |
+
solution Solution @relation(fields: [solutionId], references: [id], onDelete: Cascade)
|
| 270 |
+
createdByUser User? @relation("SolutionCommentUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
|
| 271 |
}
|
| 272 |
|
| 273 |
model Nickname {
|
| 274 |
+
anonId String @id
|
| 275 |
nickname String
|
| 276 |
updatedAt DateTime @updatedAt
|
| 277 |
}
|
| 278 |
|
| 279 |
model SubmissionRateLimit {
|
| 280 |
+
id String @id @default(uuid())
|
| 281 |
anonId String
|
| 282 |
ipAddress String
|
| 283 |
windowStart String
|
| 284 |
+
count Int @default(0)
|
| 285 |
|
| 286 |
@@unique([anonId, ipAddress, windowStart])
|
| 287 |
}
|
types/next-auth.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { DefaultSession } from "next-auth";
|
| 2 |
+
|
| 3 |
+
declare module "next-auth" {
|
| 4 |
+
interface Session {
|
| 5 |
+
user?: {
|
| 6 |
+
id: string;
|
| 7 |
+
} & DefaultSession["user"];
|
| 8 |
+
}
|
| 9 |
+
}
|