From b6cdc00843473a61cf158acca278f299dfa7ce34 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Thu, 28 Sep 2023 21:05:03 +0200 Subject: [PATCH] refactor(state): rename isModerator to canModerate for precision --- src/components/views/All.jsx | 10 +++---- src/components/views/AllCatalog.jsx | 8 +++--- src/components/views/Board.jsx | 20 +++++++------- src/components/views/Catalog.jsx | 16 ++++++------ src/components/views/Description.jsx | 2 +- src/components/views/Rules.jsx | 2 +- src/components/views/Subscriptions.jsx | 10 +++---- src/components/views/SubscriptionsCatalog.jsx | 8 +++--- src/components/views/Thread.jsx | 14 +++++----- src/hooks/stores/useGeneralStore.js | 26 +++++++++---------- 10 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/components/views/All.jsx b/src/components/views/All.jsx index 1d137029..dcd03dda 100755 --- a/src/components/views/All.jsx +++ b/src/components/views/All.jsx @@ -717,7 +717,7 @@ const All = () => { const { displayedReplies, omittedCount } = filteredRepliesByThread[thread.cid] || {}; const commentMediaInfo = getCommentMediaInfo(thread); const fallbackImgUrl = 'assets/filedeleted-res.gif'; - const isModerator = moderatorPermissions[thread.subplebbitAddress]; + const canModerate = moderatorPermissions[thread.subplebbitAddress]; let displayWidth, displayHeight, displayWidthMobile, displayHeightMobile; if (thread.linkWidth && thread.linkHeight) { let scale = Math.min(1, 250 / Math.max(thread.linkWidth, thread.linkHeight)); @@ -1037,7 +1037,7 @@ const All = () => {
  • handleAuthorDeleteClick(thread)}>Delete post
  • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
  • {
  • handleAuthorDeleteClick(reply)}>Delete post
  • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
  • {
  • handleAuthorDeleteClick(thread)}>Delete post
  • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
  • {
  • handleAuthorDeleteClick(reply)}>Delete post
  • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
  • { const [isImageSearchOpen, setIsImageSearchOpen] = useState(false); const [isClientRedirectMenuOpen, setIsClientRedirectMenuOpen] = useState(false); const [commentCid, setCommentCid] = useState(null); - const [isModerator, setIsModerator] = useState(false); + const [canModerate, setCanModerate] = useState(false); const [, setNewErrorMessage] = useError(); const [, setNewSuccessMessage] = useSuccess(); @@ -161,9 +161,9 @@ const CatalogPost = ({ post }) => { const role = subplebbit.roles[account?.author.address]?.role; if (role === 'moderator' || role === 'admin' || role === 'owner') { - setIsModerator(true); + setCanModerate(true); } else { - setIsModerator(false); + setCanModerate(false); } } }, [account?.author.address, subplebbit.roles]); @@ -573,7 +573,7 @@ const CatalogPost = ({ post }) => {
  • handleAuthorDeleteClick(thread)}>Delete post
  • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
  • { const [deletePost, setDeletePost] = useState(false); const [isImageSearchOpen, setIsImageSearchOpen] = useState(false); const [isClientRedirectMenuOpen, setIsClientRedirectMenuOpen] = useState(false); - const [isModerator, setIsModerator] = useState(false); + const [canModerate, setCanModerate] = useState(false); const [commentCid, setCommentCid] = useState(null); const [menuPosition, setMenuPosition] = useState({ top: 0, left: 0 }); const [mobileMenuPosition, setMobileMenuPosition] = useState({ top: 0, left: 0 }); @@ -180,9 +180,9 @@ const Board = () => { const role = subplebbit?.roles[account?.author.address]?.role; if (role === 'moderator' || role === 'admin' || role === 'owner') { - setIsModerator(true); + setCanModerate(true); } else { - setIsModerator(false); + setCanModerate(false); } } }, [account?.author.address, subplebbit?.roles]); @@ -1039,7 +1039,7 @@ const Board = () => { >
      - {/* {isModerator ? ( + {/* {canModerate ? ( <> change rules @@ -1264,7 +1264,7 @@ const Board = () => { >
        - {/* {isModerator ? ( + {/* {canModerate ? ( <> change rules @@ -1509,7 +1509,7 @@ const Board = () => { style={{ display: openMenuCid === subplebbit.pubsubTopic ? 'block' : 'none' }} >
          - {/* {isModerator ? ( + {/* {canModerate ? ( <> change description @@ -2080,7 +2080,7 @@ const Board = () => {
        • handleAuthorDeleteClick(thread)}>Delete post
        • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
        • {
        • handleAuthorDeleteClick(reply)}>Delete post
        • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
        • {
        • handleAuthorDeleteClick(thread)}>Delete post
        • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
        • {
        • handleAuthorDeleteClick(reply)}>Delete post
        • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
        • { setIsAuthorEdit, setIsCaptchaOpen, setIsEditModalOpen, - isModerator, + canModerate, setModeratingCommentCid, setOriginalCommentContent, setPendingComment, @@ -443,7 +443,7 @@ const CatalogPost = ({ post }) => { >
            - {/* {isModerator ? ( + {/* {canModerate ? ( <> change rules @@ -647,7 +647,7 @@ const CatalogPost = ({ post }) => { >
              - {/* {isModerator ? ( + {/* {canModerate ? ( <> change description @@ -999,7 +999,7 @@ const CatalogPost = ({ post }) => {
            • handleAuthorDeleteClick(thread)}>Delete post
            • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
            • { setIsCaptchaOpen, isModerationOpen, setIsModerationOpen, - setIsModerator, + setCanModerate, isSettingsOpen, setIsSettingsOpen, originalCommentContent, @@ -1198,12 +1198,12 @@ const Catalog = () => { const role = subplebbit.roles[account?.author.address]?.role; if (role === 'moderator' || role === 'admin' || role === 'owner') { - setIsModerator(true); + setCanModerate(true); } else { - setIsModerator(false); + setCanModerate(false); } } - }, [account?.author.address, subplebbit.roles, setIsModerator]); + }, [account?.author.address, subplebbit.roles, setCanModerate]); useEffect(() => { setSelectedAddress(subplebbitAddress); diff --git a/src/components/views/Description.jsx b/src/components/views/Description.jsx index dd293846..130647a3 100644 --- a/src/components/views/Description.jsx +++ b/src/components/views/Description.jsx @@ -427,7 +427,7 @@ const Description = () => { style={{ display: openMenuCid === subplebbit.pubsubTopic ? 'block' : 'none' }} >
                - {/* {isModerator ? ( + {/* {canModerate ? ( <> change description diff --git a/src/components/views/Rules.jsx b/src/components/views/Rules.jsx index 71264fc6..da47c8c5 100644 --- a/src/components/views/Rules.jsx +++ b/src/components/views/Rules.jsx @@ -412,7 +412,7 @@ const Rules = () => { >
                  - {/* {isModerator ? ( + {/* {canModerate ? ( <> change rules diff --git a/src/components/views/Subscriptions.jsx b/src/components/views/Subscriptions.jsx index 560db54b..7b3320f3 100755 --- a/src/components/views/Subscriptions.jsx +++ b/src/components/views/Subscriptions.jsx @@ -721,7 +721,7 @@ const Subscriptions = () => { const { displayedReplies, omittedCount } = filteredRepliesByThread[thread.cid] || {}; const commentMediaInfo = getCommentMediaInfo(thread); const fallbackImgUrl = 'assets/filedeleted-res.gif'; - const isModerator = moderatorPermissions[thread.subplebbitAddress]; + const canModerate = moderatorPermissions[thread.subplebbitAddress]; let displayWidth, displayHeight, displayWidthMobile, displayHeightMobile; if (thread.linkWidth && thread.linkHeight) { let scale = Math.min(1, 250 / Math.max(thread.linkWidth, thread.linkHeight)); @@ -1047,7 +1047,7 @@ const Subscriptions = () => {
                • handleAuthorDeleteClick(thread)}>Delete post
                • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
                • {
                • handleAuthorDeleteClick(reply)}>Delete post
                • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
                • {
                • handleAuthorDeleteClick(thread)}>Delete post
                • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
                • {
                • handleAuthorDeleteClick(reply)}>Delete post
                • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
                • { const [isImageSearchOpen, setIsImageSearchOpen] = useState(false); const [isClientRedirectMenuOpen, setIsClientRedirectMenuOpen] = useState(false); const [commentCid, setCommentCid] = useState(null); - const [isModerator, setIsModerator] = useState(false); + const [canModerate, setCanModerate] = useState(false); const [, setNewErrorMessage] = useError(); const [, setNewSuccessMessage] = useSuccess(); @@ -161,9 +161,9 @@ const CatalogPost = ({ post }) => { const role = subplebbit.roles[account?.author.address]?.role; if (role === 'moderator' || role === 'admin' || role === 'owner') { - setIsModerator(true); + setCanModerate(true); } else { - setIsModerator(false); + setCanModerate(false); } } }, [account?.author.address, subplebbit.roles]); @@ -573,7 +573,7 @@ const CatalogPost = ({ post }) => {
                • handleAuthorDeleteClick(thread)}>Delete post
                • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
                • { const [visible, setVisible] = useState(true); const [isImageSearchOpen, setIsImageSearchOpen] = useState(false); const [isClientRedirectMenuOpen, setIsClientRedirectMenuOpen] = useState(false); - const [isModerator, setIsModerator] = useState(false); + const [canModerate, setCanModerate] = useState(false); const [commentCid, setCommentCid] = useState(null); const [menuPosition, setMenuPosition] = useState({ top: 0, left: 0 }); const [mobileMenuPosition, setMobileMenuPosition] = useState({ top: 0, left: 0 }); @@ -200,9 +200,9 @@ const Thread = () => { const role = subplebbit.roles[account?.author?.address]?.role; if (role === 'moderator' || role === 'admin' || role === 'owner') { - setIsModerator(true); + setCanModerate(true); } else { - setIsModerator(false); + setCanModerate(false); } } }, [account?.author.address, subplebbit.roles]); @@ -1205,7 +1205,7 @@ const Thread = () => {
                • handleAuthorDeleteClick(comment)}>Delete post
                • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
                • {
                • handleAuthorDeleteClick(reply)}>Delete post
                • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
                • {
                • handleAuthorDeleteClick(comment)}>Delete post
                • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
                • {
                • handleAuthorDeleteClick(reply)}>Delete post
                • ) : null} - {isModerator ? ( + {canModerate ? ( <> {authorAddress === account?.author.address || authorAddress === account?.signer.address ? null : (
                • ({ setEditedComments: (comments) => set({ editedComments: comments }), feedCacheStates: {}, - setFeedCacheState: (address, isCached) => set((prev) => ({ - feedCacheStates: { - ...prev.feedCacheStates, - [address]: isCached, - } - })), + setFeedCacheState: (address, isCached) => + set((prev) => ({ + feedCacheStates: { + ...prev.feedCacheStates, + [address]: isCached, + }, + })), isAuthorDelete: false, setIsAuthorDelete: (isAuthorDelete) => set({ isAuthorDelete }), @@ -49,8 +50,8 @@ const useGeneralStore = create((set) => ({ isEditModalOpen: false, setIsEditModalOpen: (isOpen) => set({ isEditModalOpen: isOpen }), - isModerator: false, - setIsModerator: (isModerator) => set({ isModerator }), + canModerate: false, + setCanModerate: (canModerate) => set({ canModerate }), isModerationOpen: false, setIsModerationOpen: (isOpen) => set({ isModerationOpen: isOpen }), @@ -81,7 +82,7 @@ const useGeneralStore = create((set) => ({ resolveCaptchaPromise: null, setResolveCaptchaPromise: (resolve) => set({ resolveCaptchaPromise: resolve }), - + selectedAddress: '', setSelectedAddress: (address) => set({ selectedAddress: address }), @@ -90,7 +91,7 @@ const useGeneralStore = create((set) => ({ selectedShortCid: '', setSelectedShortCid: (shortCid) => set({ selectedShortCid: shortCid }), - + selectedStyle: localStorage.getItem('selectedStyle') || 'Yotsuba', setSelectedStyle: (style) => { localStorage.setItem('selectedStyle', style); @@ -99,7 +100,7 @@ const useGeneralStore = create((set) => ({ selectedText: '', setSelectedText: (text) => set({ selectedText: text }), - + selectedThread: '', setSelectedThread: (thread) => set({ selectedThread: thread }), @@ -114,7 +115,6 @@ const useGeneralStore = create((set) => ({ triggerInsertion: 0, setTriggerInsertion: (trigger) => set({ triggerInsertion: trigger }), - })); -export default useGeneralStore; \ No newline at end of file +export default useGeneralStore;