Spaces:
Running
Running
Browse UI: remove cookie text and show developers working per idea
Browse files- app/api/ideas/route.ts +27 -0
- app/icon.svg +13 -0
- app/page.tsx +0 -1
- components/HomeList.tsx +66 -33
app/api/ideas/route.ts
CHANGED
|
@@ -61,6 +61,17 @@ export async function GET(request: NextRequest) {
|
|
| 61 |
createdByUser: {
|
| 62 |
select: { name: true, developerProfile: { select: { displayName: true } } },
|
| 63 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
},
|
| 65 |
orderBy: { createdAt: "desc" },
|
| 66 |
});
|
|
@@ -72,11 +83,27 @@ export async function GET(request: NextRequest) {
|
|
| 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 |
|
|
|
|
| 61 |
createdByUser: {
|
| 62 |
select: { name: true, developerProfile: { select: { displayName: true } } },
|
| 63 |
},
|
| 64 |
+
workVotes: {
|
| 65 |
+
include: {
|
| 66 |
+
user: {
|
| 67 |
+
select: {
|
| 68 |
+
name: true,
|
| 69 |
+
email: true,
|
| 70 |
+
developerProfile: { select: { displayName: true } },
|
| 71 |
+
},
|
| 72 |
+
},
|
| 73 |
+
},
|
| 74 |
+
},
|
| 75 |
},
|
| 76 |
orderBy: { createdAt: "desc" },
|
| 77 |
});
|
|
|
|
| 83 |
const visibleName =
|
| 84 |
idea.submitterVisibleName || idea.createdByUser?.developerProfile?.displayName || idea.createdByUser?.name || null;
|
| 85 |
|
| 86 |
+
const workingDevelopers = Array.from(
|
| 87 |
+
new Set(
|
| 88 |
+
idea.workVotes
|
| 89 |
+
.map(
|
| 90 |
+
(vote) =>
|
| 91 |
+
vote.user.developerProfile?.displayName ||
|
| 92 |
+
vote.user.name ||
|
| 93 |
+
vote.user.email?.split("@")[0] ||
|
| 94 |
+
"Developer"
|
| 95 |
+
)
|
| 96 |
+
.filter(Boolean)
|
| 97 |
+
)
|
| 98 |
+
);
|
| 99 |
+
|
| 100 |
return {
|
| 101 |
...mapIdea(idea),
|
| 102 |
comment_count: idea.commentsCount,
|
| 103 |
submitter_label: idea.isAnonymous ? "Anonymous" : visibleName || "Member",
|
| 104 |
is_anonymous: idea.isAnonymous,
|
| 105 |
+
idea_working_count: workingDevelopers.length,
|
| 106 |
+
working_developers: workingDevelopers,
|
| 107 |
};
|
| 108 |
});
|
| 109 |
|
app/icon.svg
ADDED
|
|
app/page.tsx
CHANGED
|
@@ -18,7 +18,6 @@ export default function HomePage() {
|
|
| 18 |
Start a New Idea
|
| 19 |
</Link>
|
| 20 |
<span className="pill">No login required</span>
|
| 21 |
-
<span className="pill">Cookie-based identity</span>
|
| 22 |
</div>
|
| 23 |
</div>
|
| 24 |
|
|
|
|
| 18 |
Start a New Idea
|
| 19 |
</Link>
|
| 20 |
<span className="pill">No login required</span>
|
|
|
|
| 21 |
</div>
|
| 22 |
</div>
|
| 23 |
|
components/HomeList.tsx
CHANGED
|
@@ -12,6 +12,8 @@ type IdeaCard = {
|
|
| 12 |
comment_count: number;
|
| 13 |
createdAt: string;
|
| 14 |
submitter_label?: string;
|
|
|
|
|
|
|
| 15 |
};
|
| 16 |
|
| 17 |
export function HomeList() {
|
|
@@ -19,6 +21,7 @@ export function HomeList() {
|
|
| 19 |
const [loading, setLoading] = useState(true);
|
| 20 |
const [items, setItems] = useState<IdeaCard[]>([]);
|
| 21 |
const [error, setError] = useState("");
|
|
|
|
| 22 |
|
| 23 |
useEffect(() => {
|
| 24 |
let active = true;
|
|
@@ -72,43 +75,73 @@ export function HomeList() {
|
|
| 72 |
{empty ? <p className="subtle text-sm">No ideas yet. Be the first to submit one.</p> : null}
|
| 73 |
|
| 74 |
<div className="grid gap-3">
|
| 75 |
-
{items.map((idea, index) =>
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
href={`/ideas/${idea.id}`}
|
| 79 |
-
className="card block reveal-up"
|
| 80 |
-
style={{ animationDelay: `${Math.min(index * 45, 240)}ms` }}
|
| 81 |
-
>
|
| 82 |
-
<div className="flex flex-wrap items-start justify-between gap-2">
|
| 83 |
-
<h3 className="text-base font-semibold md:text-lg">{idea.title}</h3>
|
| 84 |
-
<span className="subtle text-xs">{new Date(idea.createdAt).toLocaleString()}</span>
|
| 85 |
-
</div>
|
| 86 |
|
| 87 |
-
|
| 88 |
-
<
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
{tag}
|
| 95 |
-
</span>
|
| 96 |
-
))}
|
| 97 |
</div>
|
| 98 |
-
) : null}
|
| 99 |
|
| 100 |
-
|
| 101 |
-
<
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
</div>
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
</div>
|
| 113 |
</div>
|
| 114 |
);
|
|
|
|
| 12 |
comment_count: number;
|
| 13 |
createdAt: string;
|
| 14 |
submitter_label?: string;
|
| 15 |
+
idea_working_count?: number;
|
| 16 |
+
working_developers?: string[];
|
| 17 |
};
|
| 18 |
|
| 19 |
export function HomeList() {
|
|
|
|
| 21 |
const [loading, setLoading] = useState(true);
|
| 22 |
const [items, setItems] = useState<IdeaCard[]>([]);
|
| 23 |
const [error, setError] = useState("");
|
| 24 |
+
const [expanded, setExpanded] = useState<Record<string, boolean>>({});
|
| 25 |
|
| 26 |
useEffect(() => {
|
| 27 |
let active = true;
|
|
|
|
| 75 |
{empty ? <p className="subtle text-sm">No ideas yet. Be the first to submit one.</p> : null}
|
| 76 |
|
| 77 |
<div className="grid gap-3">
|
| 78 |
+
{items.map((idea, index) => {
|
| 79 |
+
const workers = idea.working_developers || [];
|
| 80 |
+
const isExpanded = Boolean(expanded[idea.id]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
return (
|
| 83 |
+
<article key={idea.id} className="card reveal-up" style={{ animationDelay: `${Math.min(index * 45, 240)}ms` }}>
|
| 84 |
+
<div className="flex flex-wrap items-start justify-between gap-2">
|
| 85 |
+
<Link href={`/ideas/${idea.id}`} className="text-base font-semibold md:text-lg hover:underline">
|
| 86 |
+
{idea.title}
|
| 87 |
+
</Link>
|
| 88 |
+
<span className="subtle text-xs">{new Date(idea.createdAt).toLocaleString()}</span>
|
|
|
|
|
|
|
|
|
|
| 89 |
</div>
|
|
|
|
| 90 |
|
| 91 |
+
<p className="subtle mt-2 text-sm">{idea.problemStatement}</p>
|
| 92 |
+
<p className="subtle mt-2 text-xs">Submitter: {idea.submitter_label || "Anonymous"}</p>
|
| 93 |
+
|
| 94 |
+
{idea.tags.length ? (
|
| 95 |
+
<div className="mt-4 flex flex-wrap gap-1.5">
|
| 96 |
+
{idea.tags.slice(0, 6).map((tag) => (
|
| 97 |
+
<span key={tag} className="badge">
|
| 98 |
+
{tag}
|
| 99 |
+
</span>
|
| 100 |
+
))}
|
| 101 |
+
</div>
|
| 102 |
+
) : null}
|
| 103 |
+
|
| 104 |
+
<div className="mt-4 grid grid-cols-3 gap-2 md:max-w-md">
|
| 105 |
+
<div className="metric">
|
| 106 |
+
<p className="text-xs uppercase tracking-[0.16em] text-zinc-500">Upvotes</p>
|
| 107 |
+
<p className="mt-1 text-sm font-semibold">{idea.upvotesCount}</p>
|
| 108 |
+
</div>
|
| 109 |
+
<div className="metric">
|
| 110 |
+
<p className="text-xs uppercase tracking-[0.16em] text-zinc-500">Comments</p>
|
| 111 |
+
<p className="mt-1 text-sm font-semibold">{idea.comment_count}</p>
|
| 112 |
+
</div>
|
| 113 |
+
<button
|
| 114 |
+
type="button"
|
| 115 |
+
className="metric text-left"
|
| 116 |
+
onClick={() =>
|
| 117 |
+
setExpanded((prev) => ({
|
| 118 |
+
...prev,
|
| 119 |
+
[idea.id]: !prev[idea.id],
|
| 120 |
+
}))
|
| 121 |
+
}
|
| 122 |
+
>
|
| 123 |
+
<p className="text-xs uppercase tracking-[0.16em] text-zinc-500">Developers working</p>
|
| 124 |
+
<p className="mt-1 text-sm font-semibold">{idea.idea_working_count ?? workers.length}</p>
|
| 125 |
+
</button>
|
| 126 |
</div>
|
| 127 |
+
|
| 128 |
+
{isExpanded ? (
|
| 129 |
+
<div className="mt-3 rounded-lg border border-zinc-200 bg-white/85 p-3">
|
| 130 |
+
<p className="text-xs font-semibold uppercase tracking-[0.16em] text-zinc-500">Developer list</p>
|
| 131 |
+
{workers.length > 0 ? (
|
| 132 |
+
<ul className="mt-2 list-disc space-y-1 pl-5 text-sm">
|
| 133 |
+
{workers.map((name) => (
|
| 134 |
+
<li key={name}>{name}</li>
|
| 135 |
+
))}
|
| 136 |
+
</ul>
|
| 137 |
+
) : (
|
| 138 |
+
<p className="subtle mt-2 text-sm">No developers have marked this topic yet.</p>
|
| 139 |
+
)}
|
| 140 |
+
</div>
|
| 141 |
+
) : null}
|
| 142 |
+
</article>
|
| 143 |
+
);
|
| 144 |
+
})}
|
| 145 |
</div>
|
| 146 |
</div>
|
| 147 |
);
|