Skip to content

Commit

Permalink
fix: fix unresponsive hide_network toggle in profile + hide followers…
Browse files Browse the repository at this point in the history
… and counters accordingly (#296)
  • Loading branch information
Cl0v1s authored Apr 21, 2024
1 parent fea765e commit 8feeb4b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/soapbox/features/edit_profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ const EditProfile: React.FC = () => {
hint={<FormattedMessage id='edit_profile.hints.hide_network' defaultMessage='Who you follow and who follows you will not be shown on your profile' />}
>
<Toggle
checked={account ? hidesNetwork(account) : false}
checked={data.hide_followers && data.hide_followers_count && data.hide_follows && data.hide_follows_count}
onChange={handleHideNetworkChange}
/>
</ListItem>
Expand Down
5 changes: 3 additions & 2 deletions app/soapbox/features/followers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ const mapStateToProps = (state, { params, withReplies = false }) => {
const features = getFeatures(state.get('instance'));

let accountId = -1;
let account = null;
if (accountFetchError) {
accountId = null;
} else {
const account = findAccountByUsername(state, username);
account = findAccountByUsername(state, username);
accountId = account ? account.getIn(['id'], null) : -1;
}

const diffCount = getFollowDifference(state, accountId, 'followers');
const isBlocked = state.getIn(['relationships', accountId, 'blocked_by'], false);
const unavailable = (me === accountId) ? false : (isBlocked && !features.blockersVisible);
const unavailable = (me === accountId) ? false : ((isBlocked && !features.blockersVisible) || account?.pleroma?.get('hide_followers'));

return {
accountId,
Expand Down
5 changes: 3 additions & 2 deletions app/soapbox/features/following/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ const mapStateToProps = (state, { params, withReplies = false }) => {
const features = getFeatures(state.get('instance'));

let accountId = -1;
let account = null;
if (accountFetchError) {
accountId = null;
} else {
const account = findAccountByUsername(state, username);
account = findAccountByUsername(state, username);
accountId = account ? account.getIn(['id'], null) : -1;
}

const diffCount = getFollowDifference(state, accountId, 'following');
const isBlocked = state.getIn(['relationships', accountId, 'blocked_by'], false);
const unavailable = (me === accountId) ? false : (isBlocked && !features.blockersVisible);
const unavailable = (me === accountId) ? false : ((isBlocked && !features.blockersVisible) || account?.pleroma?.get('hide_followers'));

return {
accountId,
Expand Down
25 changes: 19 additions & 6 deletions app/soapbox/features/ui/components/profile_stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,46 @@ interface IProfileStats {
const ProfileStats: React.FC<IProfileStats> = ({ account, onClickHandler }) => {
const intl = useIntl();

const FollowersWrapper = React.useMemo(() =>
({ children }) => account.pleroma?.get('hide_followers') ? <>{ children }</> : <NavLink to={`/@${account.acct}/followers`} onClick={onClickHandler} title={account.pleroma?.get('hide_followers_count') ? null : intl.formatNumber(account.followers_count)} className='hover:underline'>{ children }</NavLink>
, [account, onClickHandler, intl]);

const FollowingWrapper = React.useMemo(() =>
({ children }) => account.pleroma?.get('hide_follows') ? <>{ children }</> : <NavLink to={`/@${account.acct}/following`} onClick={onClickHandler} title={account.pleroma?.get('hide_follows_count') ? null : intl.formatNumber(account.following_count)} className='hover:underline'>{ children }</NavLink>
, [account, onClickHandler, intl]);


if (!account) {
return null;
}

return (
<HStack alignItems='center' space={3}>
<NavLink to={`/@${account.acct}/followers`} onClick={onClickHandler} title={intl.formatNumber(account.followers_count)} className='hover:underline'>
<FollowersWrapper>
<HStack alignItems='center' space={1}>
<Text theme='primary' weight='bold' size='sm'>
{shortNumberFormat(account.followers_count)}
{
account.pleroma?.get('hide_followers_count') ? '-' : shortNumberFormat(account.followers_count)
}
</Text>
<Text weight='bold' size='sm'>
{intl.formatMessage(messages.followers)}
</Text>
</HStack>
</NavLink>
</FollowersWrapper>

<NavLink to={`/@${account.acct}/following`} onClick={onClickHandler} title={intl.formatNumber(account.following_count)} className='hover:underline'>
<FollowingWrapper>
<HStack alignItems='center' space={1}>
<Text theme='primary' weight='bold' size='sm'>
{shortNumberFormat(account.following_count)}
{
account.pleroma?.get('hide_follows_count') ? '-' : shortNumberFormat(account.following_count)
}
</Text>
<Text weight='bold' size='sm'>
{intl.formatMessage(messages.follows)}
</Text>
</HStack>
</NavLink>
</FollowingWrapper>
</HStack>
);
};
Expand Down
2 changes: 1 addition & 1 deletion app/soapbox/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@
"tabs_bar.chats": "Chats",
"tabs_bar.dashboard": "Dashboard",
"tabs_bar.fediverse": "Explorer",
"tabs_bar.bubble": "Voisins",
"tabs_bar.bubble": "Voisinage",
"tabs_bar.home": "Accueil",
"tabs_bar.more": "Plus",
"tabs_bar.notifications": "Notifications",
Expand Down

0 comments on commit 8feeb4b

Please sign in to comment.