Skip to content

Commit

Permalink
fixing issue with maps not showing on play page
Browse files Browse the repository at this point in the history
  • Loading branch information
webdevcody committed Oct 22, 2024
1 parent ffd806f commit aeb5762
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/admin/review/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { api } from "@/convex/_generated/api";

export default function AdminReviewPage() {
const isAdmin = useQuery(api.users.isAdmin);
const maps = useQuery(api.maps.getMaps, { isReviewed: false });
const maps = useQuery(api.maps.getUnreviewedMaps);
const adminApprovalMutation = useMutation(api.maps.approveMap);
const adminRejectMapMutation = useMutation(api.maps.rejectMap);

Expand Down
37 changes: 11 additions & 26 deletions convex/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,38 +191,23 @@ export const seedMaps = internalMutation({
},
});


export const getUnreviewedMaps = adminQueryBuilder({
handler: async (ctx) => {
return await ctx.db
.query("maps")
.withIndex("by_isReviewed_level", (q) => q.eq("isReviewed", false))
.collect();
},
});

export const getMaps = query({
args: {
isReviewed: v.optional(v.boolean()),
},
handler: async (ctx, args) => {
if (args.isReviewed !== undefined) {
// todo: take this out into a helper function
// if a manual query is made, check if the user is an admin

const userId = await getAuthUserId(ctx);
if (userId === null) {
return null;
}

const admin = await ctx.db
.query("admins")
.withIndex("by_userId", (q) => q.eq("userId", userId))
.first();

if (admin) {
return await ctx.db
.query("maps")
.filter((q) => q.eq(q.field("isReviewed"), args.isReviewed))
.collect();
} else {
return null;
}
}

return await ctx.db
.query("maps")
.filter((q) => q.eq(q.field("isReviewed"), true))
.withIndex("by_isReviewed_level", (q) => q.eq("isReviewed", true))
.collect();
},
});
Expand Down
3 changes: 2 additions & 1 deletion convex/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default defineSchema({
grid: v.array(v.array(v.string())),
submittedBy: v.optional(v.id("users")),
isReviewed: v.boolean(),
}).index("by_level", ["level"]),
}).index("by_level", ["level"])
.index("by_isReviewed_level", ["isReviewed", "level"]),
scores: defineTable({
modelId: v.string(),
promptId: v.optional(v.id("prompts")),
Expand Down

0 comments on commit aeb5762

Please sign in to comment.