Skip to content

Commit

Permalink
useCommunityActions: update logic from MoreActions
Browse files Browse the repository at this point in the history
  • Loading branch information
sharunkumar committed Oct 13, 2023
1 parent 81f77f0 commit 5367daf
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/features/community/useCommunityActions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommunityView } from "lemmy-js-client";
import { useContext, useState } from "react";
import { useContext, useMemo, useState } from "react";
import { PageContext } from "../auth/PageContext";
import { useAppDispatch, useAppSelector } from "../../store";
import { checkIsMod, getHandle } from "../../helpers/lemmy";
Expand Down Expand Up @@ -41,7 +41,6 @@ export default function useCommunityActions(
const buildGeneralBrowseLink = useBuildGeneralBrowseLink();

const site = useAppSelector((state) => state.auth.site);
const isMod = site ? checkIsMod(communityHandle, site) : false;
const isAdmin = useAppSelector(isAdminSelector);

const { presentLoginIfNeeded } = useContext(PageContext);
Expand All @@ -52,14 +51,23 @@ export default function useCommunityActions(

const isNsfw = community.community.nsfw;

const canPost =
!community.community.posting_restricted_to_mods || isMod || isAdmin;
const canPost = useMemo(() => {
const isMod = site ? checkIsMod(communityHandle, site) : false;

const canPost =
!community.community.posting_restricted_to_mods || isMod || isAdmin;

return canPost;
}, [community, communityHandle, isAdmin, site]);

const favoriteCommunities = useAppSelector(
(state) => state.community.favorites,
);

const isFavorite = favoriteCommunities.includes(communityHandle);
const isFavorite = useMemo(
() => favoriteCommunities.includes(communityHandle),
[favoriteCommunities, communityHandle],
);

function post() {
if (presentLoginIfNeeded()) return;
Expand Down

0 comments on commit 5367daf

Please sign in to comment.