Skip to content

Commit

Permalink
Refactor post, comment, and vote deletion functions to include author…
Browse files Browse the repository at this point in the history
…Did; update createPost to accept createdAt parameter; add new dependency for common-web
  • Loading branch information
WillCorrigan committed Dec 2, 2024
1 parent 4db6a14 commit 54012f4
Show file tree
Hide file tree
Showing 20 changed files with 1,473 additions and 253 deletions.
8 changes: 4 additions & 4 deletions packages/frontpage/app/(app)/_components/post-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ export async function PostCard({
}}
unvoteAction={async () => {
"use server";
await ensureUser();
const user = await ensureUser();
const vote = await getVoteForPost(id);
if (!vote) {
// TODO: Show error notification
console.error("Vote not found for post", id);
return;
}
await deleteVote(vote.rkey);
await deleteVote({ authorDid: user.did, rkey: vote.rkey });
}}
initialState={
(await getUser())?.did === author
Expand Down Expand Up @@ -148,8 +148,8 @@ export async function PostCard({

export async function deletePostAction(rkey: string) {
"use server";
await ensureUser();
await deletePost(rkey);
const user = await ensureUser();
await deletePost({ authorDid: user.did, rkey });

revalidatePath("/");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function createCommentAction(

export async function deleteCommentAction(rkey: string) {
const user = await ensureUser();
await deleteComment({ rkey, repo: user.did });
await deleteComment({ rkey, authorDid: user.did });
revalidatePath("/post");
}

Expand Down Expand Up @@ -100,5 +100,5 @@ export async function commentUnvoteAction(commentId: number) {
return;
}

await deleteVote(vote.rkey);
await deleteVote({ authorDid: user.did, rkey: vote.rkey });
}
2 changes: 1 addition & 1 deletion packages/frontpage/app/(app)/post/new/_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function newPostAction(_prevState: unknown, formData: FormData) {
}

try {
const { rkey } = await createPost({ title, url });
const { rkey } = await createPost({ title, url, createdAt: new Date() });
const handle = await getVerifiedHandle(user.did);
redirect(`/post/${handle}/${rkey}`);
} catch (error) {
Expand Down
38 changes: 38 additions & 0 deletions packages/frontpage/drizzle/0005_slimy_unus.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
DROP INDEX IF EXISTS `comments_cid_unique`;--> statement-breakpoint
DROP INDEX IF EXISTS "admin_users_did_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "beta_users_did_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "comments_author_did_rkey_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "comment_aggregates_comment_id_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "comment_id_idx";--> statement-breakpoint
DROP INDEX IF EXISTS "comment_votes_author_did_rkey_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "comment_votes_author_did_comment_id_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "labelled_profiles_did_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "oauth_auth_requests_state_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "posts_author_did_rkey_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "post_id_idx";--> statement-breakpoint
DROP INDEX IF EXISTS "rank_idx";--> statement-breakpoint
DROP INDEX IF EXISTS "post_aggregates_post_id_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "post_votes_author_did_rkey_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "post_votes_author_did_post_id_unique";--> statement-breakpoint
ALTER TABLE `comments` ALTER COLUMN "cid" TO "cid" text NOT NULL DEFAULT '';--> statement-breakpoint
CREATE UNIQUE INDEX `admin_users_did_unique` ON `admin_users` (`did`);--> statement-breakpoint
CREATE UNIQUE INDEX `beta_users_did_unique` ON `beta_users` (`did`);--> statement-breakpoint
CREATE UNIQUE INDEX `comments_author_did_rkey_unique` ON `comments` (`author_did`,`rkey`);--> statement-breakpoint
CREATE UNIQUE INDEX `comment_aggregates_comment_id_unique` ON `comment_aggregates` (`comment_id`);--> statement-breakpoint
CREATE INDEX `comment_id_idx` ON `comment_aggregates` (`comment_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `comment_votes_author_did_rkey_unique` ON `comment_votes` (`author_did`,`rkey`);--> statement-breakpoint
CREATE UNIQUE INDEX `comment_votes_author_did_comment_id_unique` ON `comment_votes` (`author_did`,`comment_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `labelled_profiles_did_unique` ON `labelled_profiles` (`did`);--> statement-breakpoint
CREATE UNIQUE INDEX `oauth_auth_requests_state_unique` ON `oauth_auth_requests` (`state`);--> statement-breakpoint
CREATE UNIQUE INDEX `posts_author_did_rkey_unique` ON `posts` (`author_did`,`rkey`);--> statement-breakpoint
CREATE INDEX `post_id_idx` ON `post_aggregates` (`post_id`);--> statement-breakpoint
CREATE INDEX `rank_idx` ON `post_aggregates` (`rank`);--> statement-breakpoint
CREATE UNIQUE INDEX `post_aggregates_post_id_unique` ON `post_aggregates` (`post_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `post_votes_author_did_rkey_unique` ON `post_votes` (`author_did`,`rkey`);--> statement-breakpoint
CREATE UNIQUE INDEX `post_votes_author_did_post_id_unique` ON `post_votes` (`author_did`,`post_id`);--> statement-breakpoint
DROP INDEX IF EXISTS `comment_votes_cid_unique`;--> statement-breakpoint
ALTER TABLE `comment_votes` ALTER COLUMN "cid" TO "cid" text NOT NULL DEFAULT '';--> statement-breakpoint
DROP INDEX IF EXISTS `posts_cid_unique`;--> statement-breakpoint
ALTER TABLE `posts` ALTER COLUMN "cid" TO "cid" text NOT NULL DEFAULT '';--> statement-breakpoint
DROP INDEX IF EXISTS `post_votes_cid_unique`;--> statement-breakpoint
ALTER TABLE `post_votes` ALTER COLUMN "cid" TO "cid" text NOT NULL DEFAULT '';
Loading

0 comments on commit 54012f4

Please sign in to comment.