From b52a38af4d172eaec34b0bd1d0c0e25be3b196f7 Mon Sep 17 00:00:00 2001 From: johnruina Date: Sat, 1 Aug 2026 08:16:39 -0400 Subject: [PATCH] removed tag binding overhead --- client/src/pages/AdminPage.tsx | 27 ++++++--------------------- client/src/pages/RatingsPage.tsx | 1 - server/prisma/schema.prisma | 11 ++++------- server/src/index.ts | 17 +++++------------ 4 files changed, 15 insertions(+), 41 deletions(-) diff --git a/client/src/pages/AdminPage.tsx b/client/src/pages/AdminPage.tsx index 9b14898..43f5c43 100644 --- a/client/src/pages/AdminPage.tsx +++ b/client/src/pages/AdminPage.tsx @@ -10,7 +10,6 @@ type Tag = { id: number; name: string; color: string; - ratingTypeId: number; }; type Rating = { @@ -119,11 +118,9 @@ function AdminPage({ user }: Props) { const [newTagName, setNewTagName] = useState(""); const [newTagColor, setNewTagColor] = useState("#424e88"); - const [newTagTypeId, setNewTagTypeId] = useState(""); const [editingTagId, setEditingTagId] = useState(null); const [editTagName, setEditTagName] = useState(""); const [editTagColor, setEditTagColor] = useState("#424e88"); - const [editTagTypeId, setEditTagTypeId] = useState(""); const [addingTagToRating, setAddingTagToRating] = useState(null); const [selectedTagForRating, setSelectedTagForRating] = useState(""); const [ratingTypeFilter, setRatingTypeFilter] = useState(""); @@ -300,11 +297,11 @@ function AdminPage({ user }: Props) { } async function createTag() { - if (!newTagName || !newTagTypeId) return; + if (!newTagName) return; await fetch(ua("/api/admin/tags"), { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ name: newTagName, color: newTagColor, ratingTypeId: newTagTypeId }), + body: JSON.stringify({ name: newTagName, color: newTagColor }), }); setNewTagName(""); setNewTagColor("#424e88"); @@ -319,11 +316,11 @@ function AdminPage({ user }: Props) { } async function updateTag(id: number) { - if (!editTagName || !editTagTypeId) return; + if (!editTagName) return; await fetch(ua(`/api/admin/tags/${id}`), { method: "PUT", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ name: editTagName, color: editTagColor, ratingTypeId: editTagTypeId }), + body: JSON.stringify({ name: editTagName, color: editTagColor }), }); setEditingTagId(null); loadTags(); @@ -591,28 +588,16 @@ function AdminPage({ user }: Props) {

Manage Tags

- setNewTagName(e.target.value)} style={{ flex: 1, padding: "8px 12px", fontSize: 14, border: `1px solid ${borderClr}`, background: inputBg, color: textClr }} /> setNewTagColor(e.target.value)} style={{ width: 40, height: 36, border: `1px solid ${borderClr}`, background: inputBg, cursor: "pointer" }} />
-
Tags for selected type:
- {tags.filter((t) => !newTagTypeId || t.ratingTypeId === Number(newTagTypeId)).map((t) => ( + {tags.map((t) => (
{editingTagId === t.id ? ( <> - setEditTagName(e.target.value)} style={{ width: 100, padding: "4px 6px", fontSize: 12, border: `1px solid ${borderClr}`, background: inputBg, color: textClr }} /> setEditTagColor(e.target.value)} style={{ width: 30, height: 24, border: `1px solid ${borderClr}`, background: inputBg, cursor: "pointer", padding: 0 }} /> @@ -621,7 +606,7 @@ function AdminPage({ user }: Props) { ) : ( <> {t.name} - + )} diff --git a/client/src/pages/RatingsPage.tsx b/client/src/pages/RatingsPage.tsx index 97b5c39..d88c7fc 100644 --- a/client/src/pages/RatingsPage.tsx +++ b/client/src/pages/RatingsPage.tsx @@ -24,7 +24,6 @@ type Tag = { id: number; name: string; color: string; - ratingTypeId: number; }; type Review = { diff --git a/server/prisma/schema.prisma b/server/prisma/schema.prisma index 4254048..194f303 100644 --- a/server/prisma/schema.prisma +++ b/server/prisma/schema.prisma @@ -22,12 +22,10 @@ model User { } model Tag { - id Int @id @default(autoincrement()) - name String - color String - ratingTypeId Int - ratings RatingTag[] - ratingType RatingType @relation(fields: [ratingTypeId], references: [id]) + id Int @id @default(autoincrement()) + name String + color String + ratings RatingTag[] } model RatingTag { @@ -60,7 +58,6 @@ model RatingType { Header Header[] ratings Rating[] categories RatingCategory[] - tags Tag[] } model Rating { diff --git a/server/src/index.ts b/server/src/index.ts index 91c50bf..65d2118 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -24,7 +24,7 @@ const cache = { userStars: new Map>>(), catRanks: new Map>(), totalInType: new Map(), - tags: [] as { id: number; name: string; color: string; ratingTypeId: number }[], + tags: [] as { id: number; name: string; color: string }[], polls: [] as { id: number; name: string; description: string; image: string; completed: boolean; resultEntryId: number | null; categoryId: number | null; entries: { id: number; pollId: number; option: string; amount: number; supporters: number }[]; tags: { pollId: number; tagId: number; tag: { id: number; name: string; color: string; image: string } }[] }[], pollCategories: [] as { id: number; name: string }[], pollTags: [] as { id: number; name: string; color: string; image: string }[], @@ -1061,9 +1061,8 @@ app.get("/api/tags", (_req, res) => { app.post("/api/admin/tags", async (req, res) => { if (!(await requireAdmin(req, res))) return; const { name, color } = req.body; - const ratingTypeId = Number(req.body.ratingTypeId); - if (!name || !color || !ratingTypeId) { res.status(400).json({ error: "name, color, and ratingTypeId are required" }); return; } - const tag = await prisma.tag.create({ data: { name, color, ratingTypeId } }); + if (!name || !color) { res.status(400).json({ error: "name and color are required" }); return; } + const tag = await prisma.tag.create({ data: { name, color } }); await rebuildCache(); res.json(tag); }); @@ -1072,9 +1071,8 @@ app.put("/api/admin/tags/:id", async (req, res) => { if (!(await requireAdmin(req, res))) return; const id = Number(req.params.id); const { name, color } = req.body; - const ratingTypeId = Number(req.body.ratingTypeId); - if (!name || !color || !ratingTypeId) { res.status(400).json({ error: "name, color, and ratingTypeId are required" }); return; } - const tag = await prisma.tag.update({ where: { id }, data: { name, color, ratingTypeId } }); + if (!name || !color) { res.status(400).json({ error: "name and color are required" }); return; } + const tag = await prisma.tag.update({ where: { id }, data: { name, color } }); await rebuildCache(); res.json(tag); }); @@ -1088,11 +1086,6 @@ app.delete("/api/admin/tags/:id", async (req, res) => { res.json({ success: true }); }); -app.get("/api/tags-by-type/:ratingTypeId", (req, res) => { - const ratingTypeId = Number(req.params.ratingTypeId); - res.json(cache.tags.filter(t => t.ratingTypeId === ratingTypeId)); -}); - app.post("/api/admin/ratings/:id/tags", async (req, res) => { if (!(await requireAdmin(req, res))) return; const id = Number(req.params.id);