diff --git a/public/translations/en/default.json b/public/translations/en/default.json index 45894edb..10fd0dab 100644 --- a/public/translations/en/default.json +++ b/public/translations/en/default.json @@ -293,8 +293,8 @@ "more_posts_last_month": "{{count}} posts last {{currentTimeFilterName}}: <1>show more posts from last month", "profile_info": "Your account u/{{shortAddress}} was created. <1>Set display name, <2>export backup, <3>learn more.", "show_all_instead": "Showing posts since {{timeFilterName}}, <1>show all instead", - "subplebbit_offline_info": "The subplebbit might be offline and publishing might fail.", - "posts_last_synced_info": "Posts last synced {{time}}, the subplebbit might be offline and publishing might fail.", + "subplebbit_offline_info": "The community might be offline and publishing might fail.", + "posts_last_synced_info": "Posts last synced {{time}}, the community might be offline and publishing might fail.", "import_account_backup": "<1>import account backup", "export_account_backup": "<1>export account backup", "save_reset_changes": "<1>save or <2>reset changes", diff --git a/src/app.tsx b/src/app.tsx index 2ed126a1..1879e819 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -15,11 +15,11 @@ import PostPage from './views/post-page'; import Profile from './views/profile'; import Settings from './views/settings'; import AccountDataEditor from './views/settings/account-data-editor'; -import SubplebbitDataEditor from './views/subplebbit-settings/subplebbit-data-editor'; +import CommunityDataEditor from './views/community-settings/community-data-editor'; import SubmitPage from './views/submit-page'; -import Subplebbit from './views/subplebbit'; -import SubplebbitSettings from './views/subplebbit-settings'; -import Subplebbits from './views/subplebbits'; +import CommunityView from './views/community'; +import CommunitySettings from './views/community-settings'; +import Communities from './views/communities'; import AccountBar from './components/account-bar/'; import ChallengeModal from './components/challenge-modal'; import Header from './components/header'; @@ -90,15 +90,15 @@ const App = () => { } /> } /> - } /> - } /> + } /> + } /> - } /> - } /> + } /> + } /> } /> - } /> - } /> + } /> + } /> } /> } /> } /> @@ -112,15 +112,15 @@ const App = () => { } /> } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> } /> @@ -129,7 +129,7 @@ const App = () => { } /> - } /> + } /> } /> diff --git a/src/components/author-sidebar/author-sidebar.tsx b/src/components/author-sidebar/author-sidebar.tsx index 574255a8..d03f9d7a 100644 --- a/src/components/author-sidebar/author-sidebar.tsx +++ b/src/components/author-sidebar/author-sidebar.tsx @@ -3,26 +3,28 @@ import { Link, useLocation, useParams } from 'react-router-dom'; import { useAccount, useAccountComments, - useAccountSubplebbits, - AccountSubplebbit, + useAccountCommunities, + AccountCommunity, + Community, useAuthor, useAuthorAvatar, useAuthorComments, useBlock, useComment, - useSubplebbits, + useCommunities, } from '@bitsocial/bitsocial-react-hooks'; -import Plebbit from '@plebbit/plebbit-js'; import styles from './author-sidebar.module.css'; import { getFormattedTimeDuration } from '../../lib/utils/time-utils'; import { getOldestAccountHistoryTimestamp } from '../../lib/utils/account-history-utils'; import { isAuthorView, isProfileView } from '../../lib/utils/view-utils'; import { findAuthorSubplebbits, estimateAuthorKarma } from '../../lib/utils/user-utils'; +import getShortAddress from '../../lib/utils/address-utils'; +import { getCommunityIdentifiers } from '../../hooks/use-community-identifier'; import { useTranslation } from 'react-i18next'; import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits'; interface AuthorModeratingListProps { - accountSubplebbits: Record; + accountSubplebbits: Record>; authorSubplebbits: string[]; isAuthor?: boolean; } @@ -39,7 +41,7 @@ const AuthorModeratingList = ({ accountSubplebbits, authorSubplebbits, isAuthor
    {subplebbitAddresses.map((address, index) => (
  • - s/{Plebbit.getShortAddress({ address })} + s/{getShortAddress(address)}
  • ))}
@@ -65,7 +67,7 @@ const AuthorSidebar = () => { const userAccount = useAccount(); const { imageUrl: profilePageAvatar } = useAuthorAvatar({ author: userAccount?.author }); const { accountComments: oldestAccountComment } = useAccountComments({ page: 0, pageSize: 1, order: 'asc' }); - const { accountSubplebbits } = useAccountSubplebbits(); + const { accountCommunities: accountSubplebbits } = useAccountCommunities(); const profileOldestAccountTimestamp = getOldestAccountHistoryTimestamp(oldestAccountComment as { timestamp?: number }[]); const defaultSubplebbitAddresses = useDefaultSubplebbitAddresses(); @@ -73,10 +75,10 @@ const AuthorSidebar = () => { const subscriptionsAndDefaults = [...accountSubscriptions, ...defaultSubplebbitAddresses]; const subplebbits = - useSubplebbits({ - subplebbitAddresses: subscriptionsAndDefaults || [], + useCommunities({ + communities: getCommunityIdentifiers(subscriptionsAndDefaults || []), onlyIfCached: true, - }).subplebbits?.filter(Boolean) || []; + }).communities?.filter(Boolean) || []; const authorAccount = useAuthor({ authorAddress, commentCid }); const { authorComments } = useAuthorComments({ authorAddress, commentCid }); diff --git a/src/components/header/header.tsx b/src/components/header/header.tsx index 6ce9b035..52f9342e 100644 --- a/src/components/header/header.tsx +++ b/src/components/header/header.tsx @@ -1,7 +1,6 @@ import { Link, useLocation, useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { useAccount, useAccountComment, useSubplebbit } from '@bitsocial/bitsocial-react-hooks'; -import Plebbit from '@plebbit/plebbit-js'; +import { useAccount, useAccountComment, useCommunity } from '@bitsocial/bitsocial-react-hooks'; import { sortTypes } from '../../constants/sort-types'; import { sortLabels } from '../../constants/sort-labels'; import { @@ -11,7 +10,7 @@ import { isAuthorView, isAuthorCommentsView, isAuthorSubmittedView, - isCreateSubplebbitView, + isCreateCommunityView, isHomeAboutView, isHomeView, isInboxView, @@ -25,23 +24,24 @@ import { isProfileHiddenView, isSettingsView, isSubmitView, - isSubplebbitView, - isSubplebbitSettingsView, - isSubplebbitSubmitView, - isSubplebbitsView, - isSubplebbitsSubscriberView, - isSubplebbitsModeratorView, - isSubplebbitsAdminView, - isSubplebbitsVoteView, - isSubplebbitsOwnerView, + isCommunityView, + isCommunitySettingsView, + isCommunitySubmitView, + isCommunitiesView, + isCommunitiesSubscriberView, + isCommunitiesModeratorView, + isCommunitiesAdminView, + isCommunitiesVoteView, + isCommunitiesOwnerView, isProfileUpvotedView, isSettingsContentOptionsView, isSettingsPlebbitOptionsView, - isSubplebbitAboutView, + isCommunityAboutView, isDomainView, isPostPageAboutView, isSettingsAccountDataView, } from '../../lib/utils/view-utils'; +import getShortAddress from '../../lib/utils/address-utils'; import useContentOptionsStore from '../../stores/use-content-options-store'; import useNotFoundStore from '../../stores/use-not-found-store'; import { useIsBroadlyNsfwSubplebbit } from '../../hooks/use-is-broadly-nsfw-subplebbit'; @@ -56,10 +56,10 @@ const AboutButton = () => { const aboutLink = getAboutLink(location.pathname, params); const isInHomeAboutView = isHomeAboutView(location.pathname); const isInPostPageAboutView = isPostPageAboutView(location.pathname, params); - const isInSubplebbitAboutView = isSubplebbitAboutView(location.pathname, params); + const isInCommunityAboutView = isCommunityAboutView(location.pathname, params); return ( -
  • +
  • {t('about')}
  • ); @@ -76,7 +76,7 @@ const CommentsButton = () => { return (
  • - isInPendingPostView && e.preventDefault()}> + isInPendingPostView && e.preventDefault()}> {t('comments')}
  • @@ -89,18 +89,18 @@ const SortItems = () => { const location = useLocation(); const isInHomeAboutView = isHomeAboutView(location.pathname); const isInPostPageAboutView = isPostPageAboutView(location.pathname, params); - const isInSubplebbitAboutView = isSubplebbitAboutView(location.pathname, params); + const isInCommunityAboutView = isCommunityAboutView(location.pathname, params); const isInAllView = isAllView(location.pathname); const isInModView = isModView(location.pathname); const isInDomainView = isDomainView(location.pathname); - const isInSubplebbitView = isSubplebbitView(location.pathname, params); + const isInCommunityView = isCommunityView(location.pathname, params); // Derive selection directly from route instead of syncing via an effect - const selectedSortType = isInHomeAboutView || isInSubplebbitAboutView || isInPostPageAboutView ? '' : params.sortType || 'hot'; + const selectedSortType = isInHomeAboutView || isInCommunityAboutView || isInPostPageAboutView ? '' : params.sortType || 'hot'; const timeFilterName = params.timeFilterName; return sortTypes.map((sortType, index) => { - let sortLink = isInSubplebbitView - ? `/s/${params.subplebbitAddress}/${sortType}` + let sortLink = isInCommunityView + ? `/s/${params.communityAddress}/${sortType}` : isInAllView ? `/s/all/${sortType}` : isInModView @@ -196,27 +196,27 @@ const InboxHeaderTabs = () => { const SubplebbitsHeaderTabs = () => { const { t } = useTranslation(); const location = useLocation(); - const isInSubplebbitsSubscriberView = isSubplebbitsSubscriberView(location.pathname); - const isInSubplebbitsModeratorView = isSubplebbitsModeratorView(location.pathname); - const isInSubplebbitsAdminView = isSubplebbitsAdminView(location.pathname); - const isInSubplebbitsOwnerView = isSubplebbitsOwnerView(location.pathname); - const isInSubplebbitsVoteView = isSubplebbitsVoteView(location.pathname); - const isInSubplebbitsView = - isSubplebbitsView(location.pathname) && - !isInSubplebbitsSubscriberView && - !isInSubplebbitsModeratorView && - !isInSubplebbitsAdminView && - !isInSubplebbitsOwnerView && - !isInSubplebbitsVoteView; + const isInCommunitiesSubscriberView = isCommunitiesSubscriberView(location.pathname); + const isInCommunitiesModeratorView = isCommunitiesModeratorView(location.pathname); + const isInCommunitiesAdminView = isCommunitiesAdminView(location.pathname); + const isInCommunitiesOwnerView = isCommunitiesOwnerView(location.pathname); + const isInCommunitiesVoteView = isCommunitiesVoteView(location.pathname); + const isInCommunitiesView = + isCommunitiesView(location.pathname) && + !isInCommunitiesSubscriberView && + !isInCommunitiesModeratorView && + !isInCommunitiesAdminView && + !isInCommunitiesOwnerView && + !isInCommunitiesVoteView; return ( <> -
  • +
  • {t('vote')}
  • { const isInPendingPostView = isPendingPostView(location.pathname, params); const isInPostPageView = isPostPageView(location.pathname, params); const isInProfileView = isProfileView(location.pathname); - const isInSubplebbitView = isSubplebbitView(location.pathname, params); - const isInSubplebbitSettingsView = isSubplebbitSettingsView(location.pathname, params); - const isInSubplebbitSubmitView = isSubplebbitSubmitView(location.pathname, params); - const isInSubplebbitsView = isSubplebbitsView(location.pathname); - const isInCreateSubplebbitView = isCreateSubplebbitView(location.pathname); + const isInCommunityView = isCommunityView(location.pathname, params); + const isInCommunitySettingsView = isCommunitySettingsView(location.pathname, params); + const isInCommunitySubmitView = isCommunitySubmitView(location.pathname, params); + const isInCommunitiesView = isCommunitiesView(location.pathname); + const isInCreateCommunityView = isCreateCommunityView(location.pathname); const isInSettingsView = isSettingsView(location.pathname); const isInSettingsContentOptionsView = isSettingsContentOptionsView(location.pathname); const isInSettingsPlebbitOptionsView = isSettingsPlebbitOptionsView(location.pathname); @@ -278,7 +278,7 @@ const HeaderTabs = () => { isInHomeView || isInHomeAboutView || isInPostPageAboutView || - (isInSubplebbitView && !isInSubplebbitSubmitView && !isInSubplebbitSettingsView) || + (isInCommunityView && !isInCommunitySubmitView && !isInCommunitySettingsView) || isInAllView || isInModView || isInDomainView @@ -288,7 +288,7 @@ const HeaderTabs = () => { return ; } else if (isInInboxView) { return ; - } else if (isInSubplebbitsView && !isInCreateSubplebbitView) { + } else if (isInCommunitiesView && !isInCreateCommunityView) { return ; } else if (isInSettingsView || isInSettingsPlebbitOptionsView || isInSettingsContentOptionsView) { return ; @@ -313,14 +313,14 @@ const HeaderTitle = ({ title, pendingPostSubplebbitAddress }: { title: string; p const isInSettingsContentOptionsView = isSettingsContentOptionsView(location.pathname); const isInSettingsPlebbitOptionsView = isSettingsPlebbitOptionsView(location.pathname); const isInSubmitView = isSubmitView(location.pathname); - const isInSubplebbitView = isSubplebbitView(location.pathname, params); - const isInSubplebbitSubmitView = isSubplebbitSubmitView(location.pathname, params); - const isInSubplebbitSettingsView = isSubplebbitSettingsView(location.pathname, params); - const isInSubplebbitsView = isSubplebbitsView(location.pathname); - const isInCreateSubplebbitView = isCreateSubplebbitView(location.pathname); + const isInCommunityView = isCommunityView(location.pathname, params); + const isInCommunitySubmitView = isCommunitySubmitView(location.pathname, params); + const isInCommunitySettingsView = isCommunitySettingsView(location.pathname, params); + const isInCommunitiesView = isCommunitiesView(location.pathname); + const isInCreateCommunityView = isCreateCommunityView(location.pathname); const isInNotFoundView = useNotFoundStore((state) => state.isNotFound); - const subplebbitAddress = params.subplebbitAddress; + const subplebbitAddress = params.communityAddress; const { hideAdultCommunities, hideGoreCommunities, hideAntiCommunities, hideVulgarCommunities } = useContentOptionsStore(); const hasUnhiddenAnyNsfwCommunity = !hideAdultCommunities || !hideGoreCommunities || !hideAntiCommunities || !hideVulgarCommunities; @@ -328,27 +328,23 @@ const HeaderTitle = ({ title, pendingPostSubplebbitAddress }: { title: string; p const subplebbitTitle = ( - {title || - (subplebbitAddress && Plebbit.getShortAddress({ address: subplebbitAddress })) || - (pendingPostSubplebbitAddress && Plebbit.getShortAddress({ address: pendingPostSubplebbitAddress }))} + {title || (subplebbitAddress && getShortAddress(subplebbitAddress)) || (pendingPostSubplebbitAddress && getShortAddress(pendingPostSubplebbitAddress))} ); const domainTitle = {params.domain}; const submitTitle = {t('submit')}; const profileTitle = {account?.author?.shortAddress}; - const authorTitle = ( - {params.authorAddress && Plebbit.getShortAddress({ address: params.authorAddress })} - ); + const authorTitle = {params.authorAddress && getShortAddress(params.authorAddress)}; if (isBroadlyNsfwSubplebbit && !hasUnhiddenAnyNsfwCommunity) { return {t('over_18')}; - } else if (isInSubplebbitSubmitView) { + } else if (isInCommunitySubmitView) { return ( <> {subplebbitTitle}: {submitTitle} ); - } else if (isInSubplebbitSettingsView) { + } else if (isInCommunitySettingsView) { return ( <> {subplebbitTitle}: {t('community_settings')} @@ -360,15 +356,15 @@ const HeaderTitle = ({ title, pendingPostSubplebbitAddress }: { title: string; p return t('preferences'); } else if (isInProfileView && !isInPendingPostView) { return profileTitle; - } else if (isInPostPageView || isInPendingPostView || (isInSubplebbitView && !isInSubplebbitSettingsView)) { + } else if (isInPostPageView || isInPendingPostView || (isInCommunityView && !isInCommunitySettingsView)) { return subplebbitTitle; } else if (isInAuthorView) { return authorTitle; } else if (isInInboxView) { return t('messages'); - } else if (isInCreateSubplebbitView) { + } else if (isInCreateCommunityView) { return {t('create_community')}; - } else if (isInSubplebbitsView) { + } else if (isInCommunitiesView) { return t('communities'); } else if (isInNotFoundView) { return {t('page_not_found')}; @@ -387,7 +383,7 @@ const Header = () => { const [theme] = useTheme(); const location = useLocation(); const params = useParams(); - const subplebbit = useSubplebbit({ subplebbitAddress: params?.subplebbitAddress, onlyIfCached: true }); + const subplebbit = useCommunity(params?.communityAddress ? { community: { name: params?.communityAddress }, onlyIfCached: true } : undefined); const { suggested, title } = subplebbit || {}; const commentIndex = params?.accountCommentIndex ? parseInt(params?.accountCommentIndex) : undefined; @@ -407,24 +403,23 @@ const Header = () => { const isInPendingPostView = isPendingPostView(location.pathname, params); const isInProfileView = isProfileView(location.pathname); const isInSettingsView = isSettingsView(location.pathname); - const isInSubplebbitView = isSubplebbitView(location.pathname, params); - const isInSubplebbitAboutView = isSubplebbitAboutView(location.pathname, params); + const isInCommunityView = isCommunityView(location.pathname, params); + const isInCommunityAboutView = isCommunityAboutView(location.pathname, params); const isInSubmitView = isSubmitView(location.pathname); - const isInSubplebbitSubmitView = isSubplebbitSubmitView(location.pathname, params); - const isInSubplebbitSettingsView = isSubplebbitSettingsView(location.pathname, params); + const isInCommunitySubmitView = isCommunitySubmitView(location.pathname, params); + const isInCommunitySettingsView = isCommunitySettingsView(location.pathname, params); const isInNotFoundView = useNotFoundStore((state) => state.isNotFound); - const hasFewTabs = - isInPostPageView || isInSubmitView || isInSubplebbitSubmitView || isInSubplebbitSettingsView || isInSettingsView || isInInboxView || isInSettingsView; + const hasFewTabs = isInPostPageView || isInSubmitView || isInCommunitySubmitView || isInCommunitySettingsView || isInSettingsView || isInInboxView || isInSettingsView; const hasStickyHeader = isInHomeView || isInNotFoundView || - (isInSubplebbitView && - !isInSubplebbitSubmitView && - !isInSubplebbitSettingsView && + (isInCommunityView && + !isInCommunitySubmitView && + !isInCommunitySettingsView && !isInPostPageView && !isInHomeAboutView && - !isInSubplebbitAboutView && + !isInCommunityAboutView && !isInPostPageAboutView) || (isInProfileView && !isInHomeAboutView) || (isInAllView && !isInAllAboutView) || @@ -432,7 +427,7 @@ const Header = () => { (isInDomainView && !isInHomeAboutView) || (isInAuthorView && !isInHomeAboutView); - const subplebbitAddress = params.subplebbitAddress; + const subplebbitAddress = params.communityAddress; const contentOptionsStore = useContentOptionsStore(); const hasUnhiddenAnyNsfwCommunity = @@ -442,7 +437,7 @@ const Header = () => { !contentOptionsStore.hideVulgarCommunities; const isBroadlyNsfwSubplebbit = useIsBroadlyNsfwSubplebbit(subplebbitAddress || ''); - const logoIsAvatar = isInSubplebbitView && suggested?.avatarUrl && !(isBroadlyNsfwSubplebbit && !hasUnhiddenAnyNsfwCommunity); + const logoIsAvatar = isInCommunityView && suggested?.avatarUrl && !(isBroadlyNsfwSubplebbit && !hasUnhiddenAnyNsfwCommunity); const logoSrc = logoIsAvatar ? suggested?.avatarUrl : 'assets/sprout/sprout.png'; const logoLink = '/'; @@ -459,15 +454,15 @@ const Header = () => {
    - {(logoIsAvatar || (!isInSubplebbitView && !isInProfileView && !isInAuthorView) || !logoIsAvatar) && ( + {(logoIsAvatar || (!isInCommunityView && !isInProfileView && !isInAuthorView) || !logoIsAvatar) && ( )} - {((!isInSubplebbitView && !isInProfileView && !isInAuthorView) || !logoIsAvatar) && ( + {((!isInCommunityView && !isInProfileView && !isInAuthorView) || !logoIsAvatar) && ( )} @@ -489,10 +484,10 @@ const Header = () => { )}
    - {isMobile && !isInSubplebbitSubmitView && !(isBroadlyNsfwSubplebbit && !hasUnhiddenAnyNsfwCommunity) && ( + {isMobile && !isInCommunitySubmitView && !(isBroadlyNsfwSubplebbit && !hasUnhiddenAnyNsfwCommunity) && (
      - {(isInHomeView || isInHomeAboutView || isInSubplebbitView || isInHomeAboutView || isInPostPageView) && } + {(isInHomeView || isInHomeAboutView || isInCommunityView || isInHomeAboutView || isInPostPageView) && } {!isInSubmitView && !isInSettingsView && (
    • diff --git a/src/components/post/comment-tools/comment-tools.tsx b/src/components/post/comment-tools/comment-tools.tsx index 4de4ab24..f619fe86 100644 --- a/src/components/post/comment-tools/comment-tools.tsx +++ b/src/components/post/comment-tools/comment-tools.tsx @@ -1,7 +1,7 @@ import { useCallback, useState } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { Author, useAccount, useComment, useSubplebbit } from '@bitsocial/bitsocial-react-hooks'; +import { Author, useAccount, useComment, useCommunity } from '@bitsocial/bitsocial-react-hooks'; import useScheduledReset from '../../../hooks/use-scheduled-reset'; import styles from './comment-tools.module.css'; import EditMenu from './edit-menu'; @@ -296,7 +296,7 @@ const CommentTools = ({ }: CommentToolsProps) => { const account = useAccount(); const isAuthor = account?.author?.address === author?.address; - const subplebbit = useSubplebbit({ subplebbitAddress, onlyIfCached: true }); + const subplebbit = useCommunity(subplebbitAddress ? { community: { name: subplebbitAddress }, onlyIfCached: true } : undefined); const accountAuthorRole = subplebbit?.roles?.[account?.author?.address]?.role; const commentAuthorRole = subplebbit?.roles?.[author?.address]?.role; const isAccountMod = accountAuthorRole === 'admin' || accountAuthorRole === 'owner' || accountAuthorRole === 'moderator'; diff --git a/src/components/post/comment-tools/hide-menu/hide-menu.tsx b/src/components/post/comment-tools/hide-menu/hide-menu.tsx index a6254d39..52964a58 100644 --- a/src/components/post/comment-tools/hide-menu/hide-menu.tsx +++ b/src/components/post/comment-tools/hide-menu/hide-menu.tsx @@ -2,9 +2,9 @@ import { useState } from 'react'; import { useLocation } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Author, useBlock } from '@bitsocial/bitsocial-react-hooks'; -import Plebbit from '@plebbit/plebbit-js'; import { autoUpdate, flip, FloatingFocusManager, offset, shift, useClick, useDismiss, useFloating, useId, useInteractions, useRole } from '@floating-ui/react'; import { isProfileHiddenView } from '../../../../lib/utils/view-utils'; +import getShortAddress from '../../../../lib/utils/address-utils'; import styles from './hide-menu.module.css'; type HideMenuProps = { @@ -38,7 +38,7 @@ const BlockSubplebbitButton = ({ subplebbitAddress }: HideMenuProps) => { return (
      - {blocked ? `${t('unblock')}` : `${t('block')}`} s/{subplebbitAddress && Plebbit.getShortAddress({ address: subplebbitAddress })} + {blocked ? `${t('unblock')}` : `${t('block')}`} s/{subplebbitAddress && getShortAddress(subplebbitAddress)}
      ); }; diff --git a/src/components/post/expando/expando.tsx b/src/components/post/expando/expando.tsx index c52e876e..5bc02f5d 100644 --- a/src/components/post/expando/expando.tsx +++ b/src/components/post/expando/expando.tsx @@ -79,7 +79,7 @@ const Expando = ({ mediaComponent = ; } - const pageSubplebbitAddress = useParams().subplebbitAddress; + const pageSubplebbitAddress = useParams().communityAddress; const isNsfwSubplebbit = useIsNsfwSubplebbit(pageSubplebbitAddress || ''); return ( diff --git a/src/components/post/post.tsx b/src/components/post/post.tsx index 26bc671c..a643a1f2 100644 --- a/src/components/post/post.tsx +++ b/src/components/post/post.tsx @@ -1,13 +1,13 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Link, useLocation, useParams, useSearchParams } from 'react-router-dom'; -import { Comment, useAuthorAddress, useBlock, useComment, useEditedComment, useSubplebbit, useSubscribe } from '@bitsocial/bitsocial-react-hooks'; -import Plebbit from '@plebbit/plebbit-js'; +import { Comment, useAuthorAddress, useBlock, useComment, useEditedComment, useCommunity, useSubscribe } from '@bitsocial/bitsocial-react-hooks'; import { getHasThumbnail } from '../../lib/utils/media-utils'; +import getShortAddress from '../../lib/utils/address-utils'; import { getPostScore, formatScore } from '../../lib/utils/post-utils'; import { getFormattedTimeAgo, formatLocalizedUTCTimestamp } from '../../lib/utils/time-utils'; import { getHostname } from '../../lib/utils/url-utils'; -import { isAllView, isAuthorView, isPendingPostView, isPostPageView, isProfileHiddenView, isProfileView, isSubplebbitView } from '../../lib/utils/view-utils'; +import { isAllView, isAuthorView, isPendingPostView, isPostPageView, isProfileHiddenView, isProfileView, isCommunityView } from '../../lib/utils/view-utils'; import { highlightMatchedText } from '../../lib/utils/pattern-utils'; import { usePinnedPostsStore } from '../../stores/use-pinned-posts-store'; import { useCommentMediaInfo } from '../../hooks/use-comment-media-info'; @@ -133,7 +133,7 @@ const Post = ({ index, post = {} }: PostProps) => { const postDate = formatLocalizedUTCTimestamp(timestamp, language); const params = useParams(); const location = useLocation(); - const subplebbit = useSubplebbit({ subplebbitAddress, onlyIfCached: true }); + const subplebbit = useCommunity(subplebbitAddress ? { community: { name: subplebbitAddress }, onlyIfCached: true } : undefined); const authorRole = subplebbit?.roles?.[post.author?.address]?.role; @@ -143,7 +143,7 @@ const Post = ({ index, post = {} }: PostProps) => { const isInProfileView = isProfileView(location.pathname); const isInAuthorView = isAuthorView(location.pathname); const isInProfileHiddenView = isProfileHiddenView(location.pathname); - const isInSubplebbitView = isSubplebbitView(location.pathname, params); + const isInCommunityView = isCommunityView(location.pathname, params); const commentMediaInfo = useCommentMediaInfo(post); @@ -176,7 +176,7 @@ const Post = ({ index, post = {} }: PostProps) => { const { blocked, unblock } = useBlock({ cid }); const [hasClickedSubscribe, setHasClickedSubscribe] = useState(false); - const { subscribe, subscribed } = useSubscribe({ subplebbitAddress }); + const { subscribe, subscribed } = useSubscribe({ communityAddress: subplebbitAddress }); // show gray dotted border around last clicked post const isLastClicked = sessionStorage.getItem('lastClickedPost') === cid && !isInPostPageView; @@ -194,7 +194,7 @@ const Post = ({ index, post = {} }: PostProps) => { const windowWidth = useWindowWidth(); const pinnedPostsCount = usePinnedPostsStore((state) => state.pinnedPostsCount); let rank = (index ?? 0) + 1; - if (isInSubplebbitView) { + if (isInCommunityView) { rank = rank - pinnedPostsCount; } @@ -260,9 +260,7 @@ const Post = ({ index, post = {} }: PostProps) => { {hostname ? ( {hostname.length > 25 ? hostname.slice(0, 25) + '...' : hostname} ) : ( - - self.{subplebbit?.shortAddress || (subplebbitAddress && Plebbit.getShortAddress({ address: subplebbitAddress }))} - + self.{subplebbit?.shortAddress || (subplebbitAddress && getShortAddress(subplebbitAddress))} )} ) @@ -293,7 +291,7 @@ const Post = ({ index, post = {} }: PostProps) => { shortAuthorAddress={shortAuthorAddress} authorAddressChanged={authorAddressChanged} /> - {!isInSubplebbitView && ( + {!isInCommunityView && ( <>  {t('post_to')} @@ -309,7 +307,7 @@ const Post = ({ index, post = {} }: PostProps) => { )} - s/{subplebbit?.shortAddress || (subplebbitAddress && Plebbit.getShortAddress({ address: subplebbitAddress }))} + s/{subplebbit?.shortAddress || (subplebbitAddress && getShortAddress(subplebbitAddress))} diff --git a/src/components/post/thumbnail/thumbnail.tsx b/src/components/post/thumbnail/thumbnail.tsx index a14fb7de..bb22b454 100644 --- a/src/components/post/thumbnail/thumbnail.tsx +++ b/src/components/post/thumbnail/thumbnail.tsx @@ -45,7 +45,7 @@ const Thumbnail = ({ const thumbnailClass = expanded ? styles.thumbnailHidden : styles.thumbnailVisible; const { blurNsfwThumbnails } = useContentOptionsStore(); - const pageSubplebbitAddress = useParams().subplebbitAddress; + const pageSubplebbitAddress = useParams().communityAddress; const isNsfwSubplebbit = useIsNsfwSubplebbit(pageSubplebbitAddress || ''); if (linkWidth && linkHeight) { diff --git a/src/components/reply-form/reply-form.tsx b/src/components/reply-form/reply-form.tsx index a74b282b..f4187e7d 100644 --- a/src/components/reply-form/reply-form.tsx +++ b/src/components/reply-form/reply-form.tsx @@ -1,8 +1,8 @@ import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useSubplebbit } from '@bitsocial/bitsocial-react-hooks'; +import { useCommunity } from '@bitsocial/bitsocial-react-hooks'; import { isValidURL } from '../../lib/utils/url-utils'; -import useIsSubplebbitOffline from '../../hooks/use-is-subplebbit-offline'; +import useIsCommunityOffline from '../../hooks/use-is-community-offline'; import usePublishReply from '../../hooks/use-publish-reply'; import Markdown from '../markdown'; import styles from './reply-form.module.css'; @@ -122,8 +122,8 @@ const ReplyForm = ({ cid, isReplyingToReply, hideReplyForm, subplebbitAddress, p const spoilerClass = showOptions ? styles.spoilerVisible : styles.spoilerHidden; const nsfwClass = showOptions ? styles.spoilerVisible : styles.spoilerHidden; - const subplebbit = useSubplebbit({ subplebbitAddress, onlyIfCached: true }); - const { isOffline, offlineTitle } = useIsSubplebbitOffline(subplebbit); + const subplebbit = useCommunity(subplebbitAddress ? { community: { name: subplebbitAddress }, onlyIfCached: true } : undefined); + const { isOffline, offlineTitle } = useIsCommunityOffline(subplebbit); // focus on the textarea when replying to a reply const textRef = useRef(null); diff --git a/src/components/reply/reply.tsx b/src/components/reply/reply.tsx index e7bc5864..29230d84 100644 --- a/src/components/reply/reply.tsx +++ b/src/components/reply/reply.tsx @@ -1,9 +1,9 @@ import { Fragment, useEffect, useMemo, useState, useRef } from 'react'; import { Link, useLocation, useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import Plebbit from '@plebbit/plebbit-js'; -import { Comment, useAccountComment, useAuthorAddress, useAuthorAvatar, useBlock, useComment, useEditedComment, useSubplebbit } from '@bitsocial/bitsocial-react-hooks'; +import { Comment, useAccountComment, useAuthorAddress, useAuthorAvatar, useBlock, useComment, useEditedComment, useCommunity } from '@bitsocial/bitsocial-react-hooks'; import { isInboxView, isPostContextView, isPostPageView } from '../../lib/utils/view-utils'; +import getShortAddress from '../../lib/utils/address-utils'; import { getHostname } from '../../lib/utils/url-utils'; import { formatScore, getReplyScore } from '../../lib/utils/post-utils'; import { flattenCommentsPages } from '@bitsocial/bitsocial-react-hooks/dist/lib/utils'; @@ -282,7 +282,7 @@ const InboxShowParentButton = ({ parentCid }: { parentCid: string | undefined }) const InboxParentInfo = ({ address, cid, markedAsRead, parentCid, postCid, shortAddress, subplebbitAddress, timestamp }: ParentLinkProps) => { const { t } = useTranslation(); - const shortSubplebbitAddress = subplebbitAddress ? (subplebbitAddress.includes('.') ? subplebbitAddress : Plebbit.getShortAddress({ address: subplebbitAddress })) : ''; + const shortSubplebbitAddress = subplebbitAddress ? (subplebbitAddress.includes('.') ? subplebbitAddress : getShortAddress(subplebbitAddress)) : ''; return ( <> @@ -342,7 +342,7 @@ const Reply = ({ cidOfReplyWithContext, depth = 0, isSingleComment, isSingleRepl timestamp, upvoteCount, } = reply || {}; - const subplebbit = useSubplebbit({ subplebbitAddress, onlyIfCached: true }); + const subplebbit = useCommunity(subplebbitAddress ? { community: { name: subplebbitAddress }, onlyIfCached: true } : undefined); const pendingReply = useAccountComment({ commentIndex: reply?.index }); const parentOfPendingReply = useComment({ commentCid: pendingReply?.parentCid, onlyIfCached: true }); diff --git a/src/components/search-bar/search-bar.tsx b/src/components/search-bar/search-bar.tsx index 2c381155..02e85886 100644 --- a/src/components/search-bar/search-bar.tsx +++ b/src/components/search-bar/search-bar.tsx @@ -3,17 +3,17 @@ import { useLocation, useNavigate, useParams, useSearchParams } from 'react-rout import { useTranslation } from 'react-i18next'; import { useFloating, autoUpdate, offset, shift, FloatingPortal } from '@floating-ui/react'; import { useAccount } from '@bitsocial/bitsocial-react-hooks'; -import Plebbit from '@plebbit/plebbit-js'; import { isHomeView, isHomeAboutView, isPostPageView, isPostPageAboutView, - isSubplebbitView, + isCommunityView, isAllView, isModView, - isSubplebbitAboutView, + isCommunityAboutView, } from '../../lib/utils/view-utils'; +import getShortAddress from '../../lib/utils/address-utils'; import useFeedFiltersStore from '../../stores/use-feed-filters-store'; import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits'; import styles from './search-bar.module.css'; @@ -33,14 +33,14 @@ const SearchBar = ({ isFocused = false, onExpandoChange }: SearchBarProps) => { const isInHomeAboutView = isHomeAboutView(location.pathname); const isInPostPageAboutView = isPostPageAboutView(location.pathname, params); - const isInSubplebbitView = isSubplebbitView(location.pathname, params); - const isInSubplebbitAboutView = isSubplebbitAboutView(location.pathname, params); + const isInCommunityView = isCommunityView(location.pathname, params); + const isInCommunityAboutView = isCommunityAboutView(location.pathname, params); const isInHomeView = isHomeView(location.pathname); const isInPostPageView = isPostPageView(location.pathname, params); const isInAllView = isAllView(location.pathname); const isInModView = isModView(location.pathname); - const isInFeedView = (isInSubplebbitView || isInHomeView || isInAllView || isInModView) && !isInPostPageView; + const isInFeedView = (isInCommunityView || isInHomeView || isInAllView || isInModView) && !isInPostPageView; const currentQuery = searchParams.get('q') || ''; const [isInCommunitySearch, setIsInCommunitySearch] = useState(() => { @@ -141,7 +141,7 @@ const SearchBar = ({ isFocused = false, onExpandoChange }: SearchBarProps) => { } const searchInput = searchInputRef.current?.value; if (searchInput) { - if (searchInput.toLowerCase() === params.subplebbitAddress?.toLowerCase()) { + if (searchInput.toLowerCase() === params.communityAddress?.toLowerCase()) { alert(t('already_in_community')); return; } @@ -183,7 +183,7 @@ const SearchBar = ({ isFocused = false, onExpandoChange }: SearchBarProps) => { const handleCommunitySelect = useCallback( (address: string) => { - if (address.toLowerCase() === params.subplebbitAddress?.toLowerCase()) { + if (address.toLowerCase() === params.communityAddress?.toLowerCase()) { alert(t('already_in_community')); return; } @@ -194,7 +194,7 @@ const SearchBar = ({ isFocused = false, onExpandoChange }: SearchBarProps) => { searchInputRef.current?.blur(); navigate(`/s/${address}`); }, - [navigate, setInputValue, setIsInputFocused, setActiveDropdownIndex, params.subplebbitAddress, t], + [navigate, setInputValue, setIsInputFocused, setActiveDropdownIndex, params.communityAddress, t], ); const handleKeyDown = useCallback( @@ -228,7 +228,7 @@ const SearchBar = ({ isFocused = false, onExpandoChange }: SearchBarProps) => { ); return ( -
      +
      { onTouchEnd={() => handleCommunitySelect(address)} onMouseEnter={() => setActiveDropdownIndex(index)} > - {Plebbit.getShortAddress({ address })} + {getShortAddress(address)}
    • ))}
    diff --git a/src/components/sidebar/sidebar.tsx b/src/components/sidebar/sidebar.tsx index 02f05a5c..47d42220 100644 --- a/src/components/sidebar/sidebar.tsx +++ b/src/components/sidebar/sidebar.tsx @@ -1,11 +1,11 @@ import { useState, useEffect } from 'react'; import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { Comment, useAccount, useBlock, Role, Subplebbit, useSubplebbitStats, useAccountComment, usePlebbitRpcSettings } from '@bitsocial/bitsocial-react-hooks'; -import Plebbit from '@plebbit/plebbit-js'; +import { Comment, useAccount, useBlock, Role, Community, useCommunityStats, useAccountComment, usePkcRpcSettings } from '@bitsocial/bitsocial-react-hooks'; import { getPostScore } from '../../lib/utils/post-utils'; import { getFormattedDate, getFormattedTimeDuration, getFormattedTimeAgo } from '../../lib/utils/time-utils'; import { findSubplebbitCreator } from '../../lib/utils/user-utils'; +import getShortAddress from '../../lib/utils/address-utils'; import { isAllView, isDomainView, @@ -15,14 +15,14 @@ import { isPendingPostView, isPostPageAboutView, isPostPageView, - isSubplebbitAboutView, - isSubplebbitSettingsView, - isSubplebbitsView, - isSubplebbitView, + isCommunityAboutView, + isCommunitySettingsView, + isCommunitiesView, + isCommunityView, } from '../../lib/utils/view-utils'; import useCommunitySubtitles from '../../hooks/use-community-subtitles'; import useIsMobile from '../../hooks/use-is-mobile'; -import useIsSubplebbitOffline from '../../hooks/use-is-subplebbit-offline'; +import useIsCommunityOffline from '../../hooks/use-is-community-offline'; import { FAQ } from '../../views/about/about'; import LoadingEllipsis from '../loading-ellipsis'; import Markdown from '../markdown'; @@ -55,7 +55,7 @@ const ModeratorsList = ({ roles }: { roles: Record }) => {