mirror of
https://github.com/fergalmoran/opengifame.git
synced 2025-12-22 09:38:44 +00:00
Basic vote mechanism implemented
This commit is contained in:
@@ -1,15 +1,14 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { TrendingPosts } from "@/components/trending-posts";
|
||||||
|
import { api, HydrateClient } from "@/trpc/server";
|
||||||
|
|
||||||
|
const LandingPage: React.FC = async () => {
|
||||||
|
void api.post.getTrending.prefetch();
|
||||||
|
|
||||||
const LandingPage: React.FC = () => {
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<HydrateClient>
|
||||||
<div className="m-6 h-full">
|
<TrendingPosts />
|
||||||
<h1 className="text-xl font-extrabold sm:text-[5rem]">
|
</HydrateClient>
|
||||||
Contains
|
|
||||||
<span className="text-[hsl(280,100%,70%)]"> Gifs</span>
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,16 +19,22 @@ const PostActions: React.FC<PostActionsProps> = ({ post }) => {
|
|||||||
await vote.mutateAsync({ slug: post.slug, up: true });
|
await vote.mutateAsync({ slug: post.slug, up: true });
|
||||||
voteCount.refetch();
|
voteCount.refetch();
|
||||||
}}
|
}}
|
||||||
icon={<Icons.up className="h-8 w-8" />}
|
icon={<Icons.up className="h-6 w-6" />}
|
||||||
/>
|
/>
|
||||||
<div>{voteCount.data ? voteCount.data.toString() : "Loading..."}</div>
|
<div>
|
||||||
|
{voteCount.data ? (
|
||||||
|
voteCount.data.toString()
|
||||||
|
) : (
|
||||||
|
<Icons.spinner className="animate-spin" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<ActionButton
|
<ActionButton
|
||||||
title="Downvote"
|
title="Downvote"
|
||||||
action={async () => {
|
action={async () => {
|
||||||
await vote.mutateAsync({ slug: post.slug, up: false });
|
await vote.mutateAsync({ slug: post.slug, up: false });
|
||||||
voteCount.refetch();
|
voteCount.refetch();
|
||||||
}}
|
}}
|
||||||
icon={<Icons.down className="h-8 w-8" />}
|
icon={<Icons.down className="h-6 w-6" />}
|
||||||
/>
|
/>
|
||||||
<ActionButton
|
<ActionButton
|
||||||
title="Favourite"
|
title="Favourite"
|
||||||
@@ -36,7 +42,7 @@ const PostActions: React.FC<PostActionsProps> = ({ post }) => {
|
|||||||
await vote.mutateAsync({ slug: post.slug, up: false });
|
await vote.mutateAsync({ slug: post.slug, up: false });
|
||||||
voteCount.refetch();
|
voteCount.refetch();
|
||||||
}}
|
}}
|
||||||
icon={<Icons.heart className="h-8 w-8" />}
|
icon={<Icons.heart className="h-6 w-6" />}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const postRouter = createTRPCRouter({
|
|||||||
.execute(sql`SELECT SUM(CASE WHEN up = TRUE THEN 1 ELSE -1 END)
|
.execute(sql`SELECT SUM(CASE WHEN up = TRUE THEN 1 ELSE -1 END)
|
||||||
FROM public.votes v
|
FROM public.votes v
|
||||||
WHERE v.post_id = (SELECT id FROM posts WHERE slug = ${input.slug})`);
|
WHERE v.post_id = (SELECT id FROM posts WHERE slug = ${input.slug})`);
|
||||||
return count[0]?.sum ?? 0;
|
return count[0]?.sum ?? '0';
|
||||||
}),
|
}),
|
||||||
getBySlug: publicProcedure
|
getBySlug: publicProcedure
|
||||||
.input(z.object({ slug: z.string() }))
|
.input(z.object({ slug: z.string() }))
|
||||||
|
|||||||
Reference in New Issue
Block a user