Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove default add btn in advanced settings, add block btn on u… #4075

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions packages/shared/src/components/contentPreference/BlockButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { ReactElement } from 'react';
import React from 'react';
import type { ContentPreferenceType } from '../../graphql/contentPreference';
import { ContentPreferenceStatus } from '../../graphql/contentPreference';
import { Button } from '../buttons/Button';
import { ButtonVariant, ButtonSize } from '../buttons/common';
import { useContentPreference } from '../../hooks/contentPreference/useContentPreference';

type BlockButtonProps = {
feedId: string;
entityId: string;
entityName: string;
status?: ContentPreferenceStatus;
entityType: ContentPreferenceType;
variant?: ButtonVariant;
size?: ButtonSize;
};

const BlockButton = ({
variant = ButtonVariant.Secondary,
size = ButtonSize.Small,
feedId,
entityId,
entityName,
entityType,
status,
}: BlockButtonProps): ReactElement => {
const { block, unblock } = useContentPreference();

return (
<Button
onClick={(e) => {
e.preventDefault();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to prevent default? If this button is submitting some form we can add type="button" and prevent it :)

Copy link
Contributor Author

@AmarTrebinjac AmarTrebinjac Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's wrapped inside a link in another component. Unfortunately not much to be done about other than this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's a major mistake have a button inside a link, so I've opened a PR fixing this issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the wrapping concern. Normally, React automatically detecs those kind of nesting and prompts a warning in the console.

if (status === ContentPreferenceStatus.Blocked) {
unblock({
id: entityId,
entity: entityType,
entityName,
feedId,
});
} else {
block({
id: entityId,
entity: entityType,
entityName,
feedId,
});
}
}}
variant={variant}
size={size}
>
{status === ContentPreferenceStatus.Blocked ? 'Unblock' : 'Block'}
</Button>
);
};

export default BlockButton;
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export const BlockedSourceList = ({
canFetchMore: checkFetchMore(queryResult),
fetchNextPage,
}}
showBlock
showFollow={false}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export const BlockedTagList = ({
canFetchMore: checkFetchMore(queryResult),
fetchNextPage,
}}
showBlock
showFollow={false}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Origin } from '../../../../lib/log';
import { CopyType } from '../../../sources/SourceActions/SourceActionsFollow';
import { useBlockedQuery } from '../../../../hooks/contentPreference/useBlockedQuery';
import { anchorDefaultRel } from '../../../../lib/strings';
import BlockButton from '../../../contentPreference/BlockButton';

type BlockedUserListProps = {
searchQuery?: string;
Expand Down Expand Up @@ -52,9 +53,18 @@ export const BlockedUserList = ({
canFetchMore: checkFetchMore(queryResult),
fetchNextPage,
}}
additionalContent={(user) => (
<BlockButton
feedId={feed.id}
entityId={user.id}
entityName={user.name}
entityType={ContentPreferenceType.User}
status={user.contentPreference.status}
/>
)}
userInfoProps={{
origin: Origin.BlockedFilter,
showFollow: true,
showFollow: false,
showSubscribe: false,
copyType: CopyType.Custom,
feedId: feed.id,
Expand Down
34 changes: 25 additions & 9 deletions packages/shared/src/components/profile/SourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ import { SourceListPlaceholder } from './SourceListPlaceholder';
import { webappUrl } from '../../lib/constants';
import Link from '../utilities/Link';
import { anchorDefaultRel } from '../../lib/strings';
import BlockButton from '../contentPreference/BlockButton';

export interface SourceListProps {
scrollingProps: Omit<InfiniteScrollingProps, 'children'>;
sources: Source[];
placeholderAmount?: number;
isLoading?: boolean;
emptyPlaceholder?: JSX.Element;
showFollow?: boolean;
showBlock?: boolean;
}

export const SourceList = ({
Expand All @@ -35,6 +38,8 @@ export const SourceList = ({
sources,
isLoading,
emptyPlaceholder,
showFollow = true,
showBlock,
}: SourceListProps): ReactElement => {
const feedSettingsEditContext = useFeedSettingsEditContext();
const feed = feedSettingsEditContext?.feed;
Expand Down Expand Up @@ -107,15 +112,26 @@ export const SourceList = ({
{source.description}
</Typography>
</div>
<FollowButton
feedId={feed?.id}
entityId={source.id}
type={ContentPreferenceType.Source}
status={source.contentPreference.status}
entityName={`@${source.handle}`}
showSubscribe={false}
copyType={CopyType.Custom}
/>
{showBlock && (
<BlockButton
feedId={feed?.id}
entityId={source.id}
entityName={`@${source.handle}`}
entityType={ContentPreferenceType.Source}
status={source.contentPreference.status}
/>
)}
{showFollow && (
<FollowButton
feedId={feed?.id}
entityId={source.id}
type={ContentPreferenceType.Source}
status={source.contentPreference.status}
entityName={`@${source.handle}`}
showSubscribe={false}
copyType={CopyType.Custom}
/>
)}
</a>
</Link>
))}
Expand Down
34 changes: 25 additions & 9 deletions packages/shared/src/components/profile/TagList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import { FollowButton } from '../contentPreference/FollowButton';
import { useFeedSettingsEditContext } from '../feeds/FeedSettings/FeedSettingsEditContext';
import { CopyType } from '../sources/SourceActions/SourceActionsFollow';
import { TagListPlaceholder } from './TagListPlaceholder';
import BlockButton from '../contentPreference/BlockButton';

export interface TagListProps {
scrollingProps: Omit<InfiniteScrollingProps, 'children'>;
tags: ContentPreference[];
placeholderAmount?: number;
isLoading?: boolean;
emptyPlaceholder?: JSX.Element;
showBlock?: boolean;
showFollow?: boolean;
}

export const TagList = ({
Expand All @@ -28,6 +31,8 @@ export const TagList = ({
tags,
isLoading,
emptyPlaceholder,
showBlock = false,
showFollow = true,
AmarTrebinjac marked this conversation as resolved.
Show resolved Hide resolved
}: TagListProps): ReactElement => {
const feedSettingsEditContext = useFeedSettingsEditContext();
const feed = feedSettingsEditContext?.feed;
Expand All @@ -51,15 +56,26 @@ export const TagList = ({
>
#{tag.referenceId}
</Typography>
<FollowButton
feedId={feed?.id}
entityId={tag.referenceId}
type={ContentPreferenceType.Keyword}
status={tag.status}
entityName={`@${tag.referenceId}`}
showSubscribe={false}
copyType={CopyType.Custom}
/>
{showBlock && (
<BlockButton
feedId={feed?.id}
entityId={tag.referenceId}
entityName={`@${tag.referenceId}`}
entityType={ContentPreferenceType.Keyword}
status={tag.status}
/>
)}
{showFollow && (
<FollowButton
feedId={feed?.id}
entityId={tag.referenceId}
type={ContentPreferenceType.Keyword}
status={tag.status}
entityName={`@${tag.referenceId}`}
showSubscribe={false}
copyType={CopyType.Custom}
/>
)}
</div>
))}
</InfiniteScrolling>
Expand Down
Loading