Skip to content

Commit

Permalink
feat: add button to allow community owners to restore their deleted c…
Browse files Browse the repository at this point in the history
…ommunities
  • Loading branch information
sunaurus committed May 10, 2024
1 parent 5181d18 commit b46749c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/app/PageWithSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ButtonLink } from "@/app/(ui)/button/ButtonLink";
import { SubscribeButton } from "@/app/communities/SubscribeButton";
import classNames from "classnames";
import { StyledLink } from "@/app/(ui)/StyledLink";
import { UndeleteButton } from "@/app/communities/UndeleteButton";

type SidebarProps = {
readonly children: ReactNode | ReactNode[];
Expand Down Expand Up @@ -205,6 +206,12 @@ const CommunityDetailsSection = async (props: {
currentStatus={props.communityView.subscribed}
loggedInUser={loggedInUser}
/>

<UndeleteButton
communityId={props.communityView.community.id}
communityName={props.communityName}
loggedInUser={loggedInUser}
/>
</>
)}

Expand Down
4 changes: 1 addition & 3 deletions src/app/communities/SubscribeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
import {
subscribeAction,
unsubscribeAction,
} from "@/app/communities/subscribeActions";
} from "@/app/communities/communityActions";
import { MyUserInfo, SubscribedType } from "lemmy-js-client";
import { useFormStatus } from "react-dom";
import { Spinner } from "@/app/(ui)/Spinner";
import { SubmitButton } from "@/app/(ui)/button/SubmitButton";

export const SubscribeButton = (props: {
Expand Down
20 changes: 20 additions & 0 deletions src/app/communities/UndeleteButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use client";
import { undeleteAction } from "@/app/communities/communityActions";
import { MyUserInfo } from "lemmy-js-client";
import { SubmitButton } from "@/app/(ui)/button/SubmitButton";

export const UndeleteButton = (props: {
readonly loggedInUser: MyUserInfo | undefined;
readonly communityId: number;
readonly communityName: string;
}) => {
return (
<form
action={undeleteAction.bind(null, props.communityId, props.communityName)}
>
<SubmitButton className={"ml-auto w-full max-w-[267px]"} color={"danger"}>
{"Restore community"}
</SubmitButton>
</form>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,18 @@ export const unsubscribeAction = async (
await apiClient.followCommunity({ community_id: communityId, follow: false });
revalidatePath("/communities");
};

export const undeleteAction = async (
communityId: number,
communityName: string,
) => {
if (!(await isLoggedIn())) {
await loginPageWithRedirectAction(`/c/${communityName}`);
return;
}

await apiClient.deleteCommunity({
community_id: communityId,
deleted: false,
});
};

0 comments on commit b46749c

Please sign in to comment.