mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor: migrate 5chan to the community hooks API (#1073)
* refactor(community-api): migrate 5chan to community hooks * fix(review): address PR feedback * fix(review): preserve legacy board context fallbacks * fix(review): address latest bot feedback * fix(review): use communityAddress in edit menu privileges
This commit is contained in:
@@ -289,7 +289,7 @@ describe('AccountSettings', () => {
|
||||
name: 'Imported',
|
||||
author: { address: '0x999' },
|
||||
subscriptions: ['business.eth'],
|
||||
subplebbits: {
|
||||
communities: {
|
||||
'business.eth': { title: '/biz/' },
|
||||
'music-posting.bso': { title: '/mu/' },
|
||||
},
|
||||
|
||||
@@ -99,20 +99,20 @@ const AccountSettingsEditor = ({
|
||||
}
|
||||
|
||||
const accountData = safeParseJSON<{
|
||||
account?: { subplebbits?: Record<string, unknown>; subscriptions?: string[]; author?: { address?: string }; name?: string };
|
||||
account?: { communities?: Record<string, unknown>; subscriptions?: string[]; author?: { address?: string }; name?: string };
|
||||
}>(fileContent);
|
||||
if (!accountData) {
|
||||
alert('Invalid JSON in file.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (accountData.account?.subplebbits) {
|
||||
const subplebbitAddresses = Object.keys(accountData.account.subplebbits);
|
||||
if (accountData.account?.communities) {
|
||||
const communityAddresses = Object.keys(accountData.account.communities);
|
||||
if (!accountData.account.subscriptions) {
|
||||
accountData.account.subscriptions = [];
|
||||
}
|
||||
const uniqueSubscriptions = [...accountData.account.subscriptions];
|
||||
for (const address of subplebbitAddresses) {
|
||||
for (const address of communityAddresses) {
|
||||
if (!uniqueSubscriptions.includes(address)) {
|
||||
uniqueSubscriptions.push(address);
|
||||
}
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@ vi.mock('react-i18next', () => ({
|
||||
|
||||
vi.mock('@bitsocialnet/bitsocial-react-hooks', () => ({
|
||||
useAccount: () => accountState.value,
|
||||
useSubscribe: ({ subplebbitAddress }: { subplebbitAddress: string }) =>
|
||||
subscriptionMocks.byAddress.get(subplebbitAddress) ?? {
|
||||
useSubscribe: ({ communityAddress }: { communityAddress: string }) =>
|
||||
subscriptionMocks.byAddress.get(communityAddress) ?? {
|
||||
subscribed: false,
|
||||
subscribe: vi.fn(),
|
||||
unsubscribe: vi.fn(),
|
||||
|
||||
@@ -6,7 +6,7 @@ import { memo, useState } from 'react';
|
||||
|
||||
const SubscriptionButton = ({ address }: { address: string }) => {
|
||||
const { t } = useTranslation();
|
||||
const { subscribed, subscribe, unsubscribe } = useSubscribe({ subplebbitAddress: address });
|
||||
const { subscribed, subscribe, unsubscribe } = useSubscribe({ communityAddress: address });
|
||||
const [recentlyUnsubscribed, setRecentlyUnsubscribed] = useState(false);
|
||||
|
||||
const handleClick = () => {
|
||||
|
||||
Reference in New Issue
Block a user